mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Change ChunkletManager to a notify/demand system
Allowing NullChunkletManager to bypass the ChunkletUnloader as it is not needed.
This commit is contained in:
parent
646bb32965
commit
f7a5678814
@ -33,6 +33,6 @@ public class WorldListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
ChunkletUnloader.addToList(event.getChunk());
|
||||
mcMMO.placeStore.chunkUnloaded(event.getChunk().getX(), event.getChunk().getZ(), event.getWorld());
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
|
||||
@ -26,6 +27,10 @@ public class ChunkletUnloader implements Runnable {
|
||||
unloadedChunks.put(chunk, 0);
|
||||
}
|
||||
|
||||
public static void addToList(int cx, int cz, World world) {
|
||||
addToList(world.getChunkAt(cx, cz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Iterator<Entry<Chunk, Integer>> it = unloadedChunks.entrySet().iterator() ; it.hasNext() ; ) {
|
||||
@ -37,7 +42,7 @@ public class ChunkletUnloader implements Runnable {
|
||||
|
||||
//Chunklets are unloaded only if their chunk has been unloaded for minimumInactiveTime
|
||||
if (inactiveTime >= minimumInactiveTime) {
|
||||
mcMMO.placeStore.chunkUnloaded(chunk.getX(), chunk.getZ(), chunk.getWorld());
|
||||
mcMMO.placeStore.unloadChunk(chunk.getX(), chunk.getZ(), chunk.getWorld());
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
@ -15,7 +15,35 @@ public interface ChunkletManager {
|
||||
public void loadChunklet(int cx, int cy, int cz, World world);
|
||||
|
||||
/**
|
||||
* Informs the ChunkletManager a chunk is loaded, it should load appropriate data
|
||||
* Unload a specific chunklet
|
||||
*
|
||||
* @param cx Chunklet X coordinate that needs to be unloaded
|
||||
* @param cy Chunklet Y coordinate that needs to be unloaded
|
||||
* @param cz Chunklet Z coordinate that needs to be unloaded
|
||||
* @param world World that the chunklet needs to be unloaded from
|
||||
*/
|
||||
public void unloadChunklet(int cx, int cy, int cz, World world);
|
||||
|
||||
/**
|
||||
* Load a given Chunk's Chunklet data
|
||||
*
|
||||
* @param cx Chunk X coordinate that is to be loaded
|
||||
* @param cz Chunk Z coordinate that is to be loaded
|
||||
* @param world World that the Chunk is in
|
||||
*/
|
||||
public void loadChunk(int cx, int cz, World world);
|
||||
|
||||
/**
|
||||
* Unload a given Chunk's Chunklet data
|
||||
*
|
||||
* @param cx Chunk X coordinate that is to be unloaded
|
||||
* @param cz Chunk Z coordinate that is to be unloaded
|
||||
* @param world World that the Chunk is in
|
||||
*/
|
||||
public void unloadChunk(int cx, int cz, World world);
|
||||
|
||||
/**
|
||||
* Informs the ChunkletManager a chunk is loaded
|
||||
*
|
||||
* @param cx Chunk X coordinate that is loaded
|
||||
* @param cz Chunk Z coordinate that is loaded
|
||||
@ -24,7 +52,7 @@ public interface ChunkletManager {
|
||||
public void chunkLoaded(int cx, int cz, World world);
|
||||
|
||||
/**
|
||||
* Informs the ChunkletManager a chunk is unloaded, it should unload and save appropriate data
|
||||
* Informs the ChunkletManager a chunk is unloaded
|
||||
*
|
||||
* @param cx Chunk X coordinate that is unloaded
|
||||
* @param cz Chunk Z coordinate that is unloaded
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.runnables.ChunkletUnloader;
|
||||
|
||||
public class HashChunkletManager implements ChunkletManager {
|
||||
private HashMap<String, ChunkletStore> store = new HashMap<String, ChunkletStore>();
|
||||
@ -37,28 +38,44 @@ public class HashChunkletManager implements ChunkletManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkLoaded(int cx, int cz, World world) {
|
||||
//File dataDir = new File(world.getWorldFolder(), "mcmmo_data");
|
||||
//File cxDir = new File(dataDir, "" + cx);
|
||||
//if(!cxDir.exists()) return;
|
||||
//File czDir = new File(cxDir, "" + cz);
|
||||
//if(!czDir.exists()) return;
|
||||
public void unloadChunklet(int cx, int cy, int cz, World world) {
|
||||
File dataDir = new File(world.getWorldFolder(), "mcmmo_data");
|
||||
if(store.containsKey(world.getName() + "," + cx + "," + cz + "," + cy)) {
|
||||
File cxDir = new File(dataDir, "" + cx);
|
||||
if(!cxDir.exists()) cxDir.mkdir();
|
||||
File czDir = new File(cxDir, "" + cz);
|
||||
if(!czDir.exists()) czDir.mkdir();
|
||||
File yFile = new File(czDir, "" + cy);
|
||||
|
||||
//for(int y = 0; y < 4; y++) {
|
||||
// File yFile = new File(czDir, "" + y);
|
||||
// if(!yFile.exists()) {
|
||||
// continue;
|
||||
// } else {
|
||||
// ChunkletStore in = deserializeChunkletStore(yFile);
|
||||
// if(in != null) {
|
||||
// store.put(world.getName() + "," + cx + "," + cz + "," + y, in);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
ChunkletStore out = store.get(world.getName() + "," + cx + "," + cz + "," + cy);
|
||||
serializeChunkletStore(out, yFile);
|
||||
store.remove(world.getName() + "," + cx + "," + cz + "," + cy);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkUnloaded(int cx, int cz, World world) {
|
||||
public void loadChunk(int cx, int cz, World world) {
|
||||
File dataDir = new File(world.getWorldFolder(), "mcmmo_data");
|
||||
File cxDir = new File(dataDir, "" + cx);
|
||||
if(!cxDir.exists()) return;
|
||||
File czDir = new File(cxDir, "" + cz);
|
||||
if(!czDir.exists()) return;
|
||||
|
||||
for(int y = 0; y < 4; y++) {
|
||||
File yFile = new File(czDir, "" + y);
|
||||
if(!yFile.exists()) {
|
||||
continue;
|
||||
} else {
|
||||
ChunkletStore in = deserializeChunkletStore(yFile);
|
||||
if(in != null) {
|
||||
store.put(world.getName() + "," + cx + "," + cz + "," + y, in);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(int cx, int cz, World world) {
|
||||
File dataDir = new File(world.getWorldFolder(), "mcmmo_data");
|
||||
|
||||
for(int y = 0; y < 4; y++) {
|
||||
@ -76,6 +93,16 @@ public class HashChunkletManager implements ChunkletManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkLoaded(int cx, int cz, World world) {
|
||||
//loadChunk(cx, cz, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkUnloaded(int cx, int cz, World world) {
|
||||
ChunkletUnloader.addToList(cx, cx, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWorld(World world) {
|
||||
String worldName = world.getName();
|
||||
|
@ -14,6 +14,21 @@ public class NullChunkletManager implements ChunkletManager {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunklet(int cx, int cy, int cz, World world) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadChunk(int cx, int cz, World world) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadChunk(int cx, int cz, World world) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chunkLoaded(int cx, int cz, World world) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user