Class ChunkManager

java.lang.Object
net.glowstone.chunk.ChunkManager

public final class ChunkManager extends Object
A class which manages the GlowChunks currently loaded in memory.
  • Constructor Details

    • ChunkManager

      public ChunkManager(GlowWorld world, ChunkIoService service, org.bukkit.generator.ChunkGenerator generator)
      Creates a new chunk manager with the specified I/O service and world generator.
      Parameters:
      world - The chunk manager's world.
      service - The I/O service.
      generator - The world generator.
  • Method Details

    • getChunk

      public GlowChunk getChunk(int x, int z)
      Gets a chunk object representing the specified coordinates, which might not yet be loaded.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
      Returns:
      The chunk.
    • getChunk

      public GlowChunk getChunk(GlowChunk.Key key)
      Gets a chunk object from its key, which might not yet be loaded.
      Parameters:
      key - The x, y key of the chunk.
      Returns:
      The chunk.
    • isChunkLoaded

      public boolean isChunkLoaded(int x, int z)
      Checks if the Chunk at the specified coordinates is loaded.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
      Returns:
      true if the chunk is loaded, otherwise false.
    • isChunkInUse

      public boolean isChunkInUse(int x, int z)
      Check whether a chunk has locks on it preventing it from being unloaded.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
      Returns:
      Whether the chunk is in use.
    • loadChunk

      public boolean loadChunk(int x, int z, boolean generate)
      Call the ChunkIoService to load a chunk, optionally generating the chunk.
      Parameters:
      x - The X coordinate of the chunk to load.
      z - The Y coordinate of the chunk to load.
      generate - Whether to generate the chunk if needed.
      Returns:
      True on success, false on failure.
    • loadChunk

      public boolean loadChunk(GlowChunk chunk, boolean generate)
      Attempts to load a chunk; handles exceptions.
      Parameters:
      chunk - the chunk address
      generate - if true, generate the chunk if it's new or the saved copy is corrupted
      Returns:
      true if the chunk was loaded or generated successfully, false otherwise
    • unloadOldChunks

      public void unloadOldChunks()
      Unload chunks with no locks on them.
    • forcePopulation

      public void forcePopulation(int x, int z)
      Force a chunk to be populated by loading the chunks in an area around it. Used when streaming chunks to players so that they do not have to watch chunks being populated.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
    • forceRegeneration

      public boolean forceRegeneration(int x, int z)
      Forces generation of the given chunk.
      Parameters:
      x - The X coordinate.
      z - The Z coordinate.
      Returns:
      Whether the chunk was successfully regenerated.
    • getLoadedChunks

      public GlowChunk[] getLoadedChunks()
      Gets a list of loaded chunks.
      Returns:
      The currently loaded chunks.
    • performSave

      public boolean performSave(GlowChunk chunk)
      Performs the save for the given chunk using the storage provider.
      Parameters:
      chunk - The chunk to save.
      Returns:
      True if the save was successful.
    • getBiomeGridAtLowerRes

      public int[] getBiomeGridAtLowerRes(int x, int z, int sizeX, int sizeZ)
    • getBiomeGrid

      public int[] getBiomeGrid(int x, int z, int sizeX, int sizeZ)
    • broadcastBlockChange

      public void broadcastBlockChange(GlowChunk.Key key, BlockChangeMessage message)
      Queues block change notification to all players in this chunk
      Parameters:
      key - The chunk's key
      message - The block change message to broadcast
    • broadcastBlockChanges

      public void broadcastBlockChanges(GlowChunk.Key key, Iterable<BlockChangeMessage> messages)
      Queues block change notification to all players in this chunk
      Parameters:
      key - The chunk's key
      messages - The block change messages to broadcast
    • getBlockChanges

      public List<BlockChangeMessage> getBlockChanges(GlowChunk.Key key)
    • clearChunkBlockChanges

      public void clearChunkBlockChanges()
    • getGenerator

      public org.bukkit.generator.ChunkGenerator getGenerator()
      The chunk generator used to generate new chunks.
      Returns:
      the chunk generator