From 2513b4ca231f1ab517d6569490038c770ef057fd Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Thu, 10 Jan 2013 12:33:30 -0800 Subject: [PATCH] Alleviating hangtime on world save. --- .../blockmeta/chunkmeta/HashChunkManager.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java index 4795cfa17..8ac1ca98d 100755 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java @@ -32,7 +32,9 @@ public class HashChunkManager implements ChunkManager { private List spawnedMobs = new ArrayList(); private List spawnedPets = new ArrayList(); private List mobsToRemove = new ArrayList(); + private List savedChunks = new ArrayList(); private boolean safeToRemoveMobs = true; + private boolean savingWorld = false; @Override public synchronized void closeAll() { @@ -219,6 +221,9 @@ public class HashChunkManager implements ChunkManager { if (world == null) return; + if(savingWorld && savedChunks.contains(world.getName() + "," + cx + "," + cz)) + return; + boolean unloaded = false; if (!store.containsKey(world.getName() + "," + cx + "," + cz)) { List tempSpawnedMobs = new ArrayList(spawnedMobs); @@ -240,7 +245,7 @@ public class HashChunkManager implements ChunkManager { loadChunk(cx, cz, world); unloaded = true; break; - } + } } } @@ -273,6 +278,9 @@ public class HashChunkManager implements ChunkManager { writeChunkStore(world, cx, cz, out); } + + if(savingWorld) + savedChunks.add(world.getName() + "," + cx + "," + cz); } private boolean isEntityInChunk(Entity entity, int cx, int cz, World world) { @@ -317,6 +325,7 @@ public class HashChunkManager implements ChunkManager { closeAll(); String worldName = world.getName(); + savingWorld = true; List keys = new ArrayList(store.keySet()); for (String key : keys) { @@ -361,6 +370,9 @@ public class HashChunkManager implements ChunkManager { saveChunk(cx, cz, world); } + + savingWorld = false; + savedChunks.clear(); } @Override @@ -370,6 +382,7 @@ public class HashChunkManager implements ChunkManager { closeAll(); String worldName = world.getName(); + savingWorld = true; List keys = new ArrayList(store.keySet()); for (String key : keys) { @@ -404,7 +417,7 @@ public class HashChunkManager implements ChunkManager { unloadChunk(cx, cz, world); } - List tempSpawnedPets = new ArrayList(spawnedPets); + List tempSpawnedPets = new ArrayList(spawnedPets); for (Entity entity : tempSpawnedPets) { World entityWorld = entity.getWorld(); @@ -422,6 +435,8 @@ public class HashChunkManager implements ChunkManager { spawnedMobs.remove(mobsToRemove); spawnedPets.remove(mobsToRemove); mobsToRemove.clear(); + savingWorld = false; + savedChunks.clear(); } @Override