Package net.glowstone.chunk
Class ChunkManager
java.lang.Object
net.glowstone.chunk.ChunkManager
A class which manages the
GlowChunk
s currently loaded in memory.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A group of locks on chunks to prevent them from being unloaded while in use. -
Constructor Summary
ConstructorDescriptionChunkManager
(GlowWorld world, ChunkIoService service, org.bukkit.generator.ChunkGenerator generator) Creates a new chunk manager with the specified I/O service and world generator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
broadcastBlockChange
(GlowChunk.Key key, BlockChangeMessage message) Queues block change notification to all players in this chunkvoid
broadcastBlockChanges
(GlowChunk.Key key, Iterable<BlockChangeMessage> messages) Queues block change notification to all players in this chunkvoid
void
forcePopulation
(int x, int z) Force a chunk to be populated by loading the chunks in an area around it.boolean
forceRegeneration
(int x, int z) Forces generation of the given chunk.int[]
getBiomeGrid
(int x, int z, int sizeX, int sizeZ) int[]
getBiomeGridAtLowerRes
(int x, int z, int sizeX, int sizeZ) getChunk
(int x, int z) Gets a chunk object representing the specified coordinates, which might not yet be loaded.getChunk
(GlowChunk.Key key) Gets a chunk object from its key, which might not yet be loaded.org.bukkit.generator.ChunkGenerator
The chunk generator used to generate new chunks.Gets a list of loaded chunks.boolean
isChunkInUse
(int x, int z) Check whether a chunk has locks on it preventing it from being unloaded.boolean
isChunkLoaded
(int x, int z) Checks if the Chunk at the specified coordinates is loaded.boolean
loadChunk
(int x, int z, boolean generate) Call the ChunkIoService to load a chunk, optionally generating the chunk.boolean
Attempts to load a chunk; handles exceptions.boolean
performSave
(GlowChunk chunk) Performs the save for the given chunk using the storage provider.void
Unload chunks with no locks on them.
-
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
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
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
Attempts to load a chunk; handles exceptions.- Parameters:
chunk
- the chunk addressgenerate
- 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
Gets a list of loaded chunks.- Returns:
- The currently loaded chunks.
-
performSave
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
Queues block change notification to all players in this chunk- Parameters:
key
- The chunk's keymessage
- The block change message to broadcast
-
broadcastBlockChanges
Queues block change notification to all players in this chunk- Parameters:
key
- The chunk's keymessages
- The block change messages to broadcast
-
getBlockChanges
-
clearChunkBlockChanges
public void clearChunkBlockChanges() -
getGenerator
public org.bukkit.generator.ChunkGenerator getGenerator()The chunk generator used to generate new chunks.- Returns:
- the chunk generator
-