com.aranai.dungeonator.dungeonchunk
Class DungeonChunkManager

java.lang.Object
  extended by com.aranai.dungeonator.dungeonchunk.DungeonChunkManager

public class DungeonChunkManager
extends java.lang.Object

Handles storage and access for DungeonChunks via a local cache. The DungeonChunkManager interfaces with the DungeonDataManager for data store abstraction, and the DungeonChunkGenerator for new chunk generation.


Field Summary
private  java.util.concurrent.ConcurrentHashMap<java.lang.String,DungeonChunk> chunkCache
          Local cache of dungeon chunk information.
private  DungeonChunkGenerator chunkGenerator
          DungeonChunkGenerator instance
private  DungeonDataManager dataManager
          DungeonDataManager instance
 
Constructor Summary
DungeonChunkManager(DungeonDataManager dataManager)
          Instantiates the dungeon chunk manager.
 
Method Summary
 void generateChunk(java.lang.String world, int x, int z, org.bukkit.Chunk chunk)
          Generate a DungeonChunk for the specified Chunk.
private  DungeonChunk getCachedChunk(java.lang.String hash)
          Gets a cached DungeonChunk based on its hash code
private  DungeonChunk getCachedChunk(java.lang.String world, int x, int z)
          Gets a cached DungeonChunk based on world, x and z coordinates Convenience alias for getCachedChunk(String).
 DungeonChunk getChunk(java.lang.String hash)
          Gets the DungeonChunk for the specified coordinates
 DungeonChunk getChunk(java.lang.String world, int x, int z)
          Gets a DungeonChunk matching the specified coordinates.
 java.lang.String getChunkHash(java.lang.String world, int x, int z)
          Gets a chunk hash based on world name, x and z coordinates.
 boolean isChunkCached(java.lang.String hash)
          Checks if the chunk is cached.
 boolean isChunkCached(java.lang.String world, int x, int z)
          Checks if the chunk is cached.
 boolean isChunkGenerated(java.lang.String world, int x, int z)
          Checks if a DungeonChunk has been generated for the specified Chunk.
 void loadChunk(java.lang.String hash, org.bukkit.Chunk chunkData)
          Load a DungeonChunk from the local cache or the data store.
 void loadChunk(java.lang.String world, int x, int z, org.bukkit.Chunk chunkData)
          Load a DungeonChunk from the local cache or the data store.
 void storeChunk(DungeonChunk chunk)
          Stores and caches the Dungeonator-specific chunk data.
 void updateCachedChunk(DungeonChunk chunk)
          Save a DungeonChunk to the local cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chunkCache

private java.util.concurrent.ConcurrentHashMap<java.lang.String,DungeonChunk> chunkCache
Local cache of dungeon chunk information.


dataManager

private DungeonDataManager dataManager
DungeonDataManager instance


chunkGenerator

private DungeonChunkGenerator chunkGenerator
DungeonChunkGenerator instance

Constructor Detail

DungeonChunkManager

public DungeonChunkManager(DungeonDataManager dataManager)
Instantiates the dungeon chunk manager.

Method Detail

storeChunk

public void storeChunk(DungeonChunk chunk)
Stores and caches the Dungeonator-specific chunk data.

Parameters:
chunk - the DungeonChunk to store
See Also:
DungeonChunk

updateCachedChunk

public void updateCachedChunk(DungeonChunk chunk)
Save a DungeonChunk to the local cache.

Parameters:
chunk - the DungeonChunk to save

loadChunk

public void loadChunk(java.lang.String world,
                      int x,
                      int z,
                      org.bukkit.Chunk chunkData)
Load a DungeonChunk from the local cache or the data store. Convenience alias for #loadChunk(String)

Parameters:
world - the world in which the chunk is located
x - the x coordinate for the chunk
z - the z coordinate for the chunk
chunk - the chunk data

loadChunk

public void loadChunk(java.lang.String hash,
                      org.bukkit.Chunk chunkData)
Load a DungeonChunk from the local cache or the data store.

Parameters:
hash - the hash for the DungeonChunk

getChunk

public DungeonChunk getChunk(java.lang.String world,
                             int x,
                             int z)
Gets a DungeonChunk matching the specified coordinates. Convenience alias for getChunk(String)

Parameters:
world - the world for the chunk
x - the x coordinate for the chunk
z - the z coordinate for the chunk
Returns:
the chunk

getChunk

public DungeonChunk getChunk(java.lang.String hash)
Gets the DungeonChunk for the specified coordinates

Parameters:
hash - the hash for the chunk
Returns:
the DungeonChunk
See Also:
getChunkHash(String, int, int)

getCachedChunk

private DungeonChunk getCachedChunk(java.lang.String world,
                                    int x,
                                    int z)
Gets a cached DungeonChunk based on world, x and z coordinates Convenience alias for getCachedChunk(String).

Parameters:
world - the world
x - the x coordinate
z - the z coordinate
Returns:
the cached chunk

getCachedChunk

private DungeonChunk getCachedChunk(java.lang.String hash)
Gets a cached DungeonChunk based on its hash code

Parameters:
hash - the hash for the DungeonChunk
Returns:
the cached DungeonChunk
See Also:
getChunkHash(String, int, int)

getChunkHash

public java.lang.String getChunkHash(java.lang.String world,
                                     int x,
                                     int z)
Gets a chunk hash based on world name, x and z coordinates.

Parameters:
world - the world name
x - the x coordinate
z - the z coordinate
Returns:
the chunk hash

isChunkCached

public boolean isChunkCached(java.lang.String world,
                             int x,
                             int z)
Checks if the chunk is cached. Convenience alias for isChunkCached(String)

Parameters:
world - the world name
x - the x coordinate for the chunk
z - the z coordinate for the chunk
Returns:
true, if the chunk is cached

isChunkCached

public boolean isChunkCached(java.lang.String hash)
Checks if the chunk is cached.

Parameters:
hash - the hash for the chunk
Returns:
true, if the chunk is cached

isChunkGenerated

public boolean isChunkGenerated(java.lang.String world,
                                int x,
                                int z)
Checks if a DungeonChunk has been generated for the specified Chunk.

Parameters:
world - the world
x - the x coordinate for the chunk
z - the z coordinate for the chunk
Returns:
true, if a DungeonChunk has already been generated

generateChunk

public void generateChunk(java.lang.String world,
                          int x,
                          int z,
                          org.bukkit.Chunk chunk)
Generate a DungeonChunk for the specified Chunk.

Parameters:
world - the world name
x - the x coordinate for the chunk
z - the z coordinate for the chunk
chunk - the handle for the chunk