Hallo,
als erstes die Java Code Ausschnitte:
Hier die Fehlermeldung:
Hier noch die gesamte Klasse:
[Java] WorldPopulator - Pastebin.com
Nun meine Frage: Die Fehlermeldung tritt in unregelmäßigen Abständen auf, während ich durch die HashMaps iteriere verändere ich die Menge nicht, wie kommt es dann zu dieser Fehlermeldung?
Ich hoffe mir kann jemand helfen :/
Gruß Zelnehlun
als erstes die Java Code Ausschnitte:
Java:
static HashMap<String, WWorld> worlds = new HashMap<String, WWorld>();
public static void onServerTick(ServerTickEvent e){
if(ticks % 100 == 0){
synchronize();
}
if(ticks % 400 == 0){
spawnMonsters();
spawnAnimals();
}
if(ticks % 600 == 0){
checkSpawner();
}
ticks++;
}
// methods
public static void checkSpawner(){
for(WWorld world:worlds.values()){
for(CChunk chunk:world.getChunks()){
chunk.checkSpawner();
}
}
}
public void checkSpawner(){
if(!isProtected(chunk)){
BlockState[] states = chunk.getTileEntities();
for(BlockState state:states){
if(state instanceof CreatureSpawner){
CreatureSpawner spawner = (CreatureSpawner)state;
Block block = spawner.getBlock();
for(int i = 0; i < 2; i++){
if(!isSpawnerCapReached()){
int modX = Rand.nextInt(3) + 1;
int modZ = Rand.nextInt(3) + 1;
block = block.getRelative(modX, -1, modZ);
if(isOpaque(block)){
block = block.getRelative(BlockFace.UP);
if(isTransparent(block)){
block = block.getRelative(BlockFace.UP);
if(isTransparent(block)){
block = block.getRelative(BlockFace.DOWN);
World world = chunk.getWorld();
Location loc = block.getLocation();
EntityType type = spawner.getSpawnedType();
Entity ent = world.spawnCreature(loc, type);
int id = ent.getEntityId();
spawnerEntities.put(id, ent);
SFX.playEffect(spawner.getBlock(), Effect.MOBSPAWNER_FLAMES);
SFX.playEffect(ent, Effect.MOBSPAWNER_FLAMES);
}
}
}
}else{
break;
}
}
}
}
}
}
}
public static class WWorld {
String name;
HashMap<String, CChunk> chunks = new HashMap<String, CChunk>();
public WWorld(World world){
this.name = world.getName();
Chunk[] chunks = world.getLoadedChunks();
for(Chunk chunk:chunks){
registerChunk(chunk);
}
}
public Collection<CChunk> getChunks(){
return chunks.values();
}
public void registerChunk(Chunk chunk){
CChunk cChunk = new CChunk(chunk);
String name = cChunk.name;
chunks.put(name, cChunk);
}
public CChunk getChunk(Chunk chunk){
String name = chunk.getX() + " " + chunk.getZ();
return chunks.get(name);
}
}
public static class CChunk {
Chunk chunk;
String name;
HashMap<Integer, Entity> entities = new HashMap<Integer, Entity>();
HashMap<Integer, Entity> spawnerEntities = new HashMap<Integer, Entity>();
public CChunk(Chunk chunk){
this.chunk = chunk;
name = chunk.getX() + " " + chunk.getZ();
Entity[] ents = chunk.getEntities();
for(Entity ent:ents){
if(isLivingEntity(ent)){
addEntity(ent);
}
}
}
[...]
Hier die Fehlermeldung:
Java:
[SEVERE] Could not pass event ServerTickEvent to Alonian
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
at java.util.HashMap$ValueIterator.next(HashMap.java:835)
at zelnehlun.alonian.WorldPopulator.checkSpawner(WorldPopulator.java:114)
at zelnehlun.alonian.WorldPopulator.onServerTick(WorldPopulator.java:104)
at zelnehlun.listeners.WorldListener.onServerTick(WorldListener.java:32)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301)
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:461)
at org.getspout.spout.ServerTickTask.run(ServerTickTask.java:49)
at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:126)
at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:588)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:506)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
Hier noch die gesamte Klasse:
[Java] WorldPopulator - Pastebin.com
Nun meine Frage: Die Fehlermeldung tritt in unregelmäßigen Abständen auf, während ich durch die HashMaps iteriere verändere ich die Menge nicht, wie kommt es dann zu dieser Fehlermeldung?
Ich hoffe mir kann jemand helfen :/
Gruß Zelnehlun