keeping a chunk loaded?

Discussion in 'Plugin Development' started by CaiusTSM, Jul 22, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    CaiusTSM

    How do I keep a certain chunk loaded when no body is on the server?
     
  2. Offline

    bergerkiller

    Not 100% sure about this, but maybe using this:
    Code:
                    World w = event.getPlayer().getWorld();
                    Chunk toload = w.getChunkAt(x, z);
                    boolean loaded = false;
                    for (Chunk c : w.getLoadedChunks()) if (c == toload) {
                        loaded = true;
                        break;
                    }
                    if (loaded == false) {
                        w.loadChunk(toload);
                    }
    In a timer operation.

    EDIT

    You also need to handle the Event.Type.CHUNK_UNLOAD event to cancel chunks that are supposed to stay loaded.
     
  3. Offline

    Simanova

  4. Offline

    bergerkiller

    I was right. :)
    Code:
    public class ChuckLoadWListener extends WorldListener {
    ChunkLoad plugin;
    public ChuckLoadWListener(ChunkLoad i){
    this.plugin = i;
    
    }
    public void onChunkUnload(ChunkUnloadEvent event){
    Chunk chunk = event.getChunk();
    int x = chunk.getX();
    int z = chunk.getZ();
    if(!this.plugin.allowunload(x, z)){
    event.setCancelled(true);
    plugin.getLogger().info("Chunk @ " + x + ":" + z + "Stoped from unloading");
    
    }
    else{
    event.setCancelled(false);
    }
    }
    
    }
    
    
     
  5. Offline

    CaiusTSM

    Thanks for the help guys!:)
     
Thread Status:
Not open for further replies.

Share This Page