Package net.paulem.arcana.regions
Class Tracker<S extends Tracked<K>,K extends WorldKey>
java.lang.Object
net.paulem.arcana.regions.Tracker<S,K>
- Type Parameters:
S- the type of the object to track
A class to extend that tracks all the specified S type in the server.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetHolderAt(K key) Retrieves the tracked object registered at the given key, if any.abstract voidhandleChunkLoad(org.bukkit.Chunk chunk) Called when a chunk is loaded, allowing implementations to populate the tracker with the tracked objects contained in that chunk.voidhandleChunkUnload(org.bukkit.Chunk chunk) Called when a chunk is unloaded.voidregisterHolder(S tracked) Registers a tracked object in the global container, using its own key.voidremoveHolder(S tracked) Removes a tracked object from the global container, using its own key.voidsaveChunk(org.bukkit.Chunk chunk) Saves all tracked objects held within the given chunk by invokingTracked.onUnload()on each of them.voidInvokes the given callback for every holder tracked within the given chunk.
-
Constructor Details
-
Tracker
public Tracker()Creates a new tracker with an emptyGlobalBlockContainer.
-
-
Method Details
-
getHolderAt
Retrieves the tracked object registered at the given key, if any.- Parameters:
key- the key to look up- Returns:
- the tracked object at the key, or
nullif none is registered
-
registerHolder
Registers a tracked object in the global container, using its own key.- Parameters:
tracked- the object to register
-
removeHolder
Removes a tracked object from the global container, using its own key.- Parameters:
tracked- the object to remove
-
handleChunkLoad
public abstract void handleChunkLoad(org.bukkit.Chunk chunk) Called when a chunk is loaded, allowing implementations to populate the tracker with the tracked objects contained in that chunk.- Parameters:
chunk- the chunk that was loaded
-
handleChunkUnload
public void handleChunkUnload(org.bukkit.Chunk chunk) Called when a chunk is unloaded. Saves all tracked objects held in the chunk and removes the chunk's container from its world container.- Parameters:
chunk- the chunk that was unloaded
-
saveChunk
public void saveChunk(org.bukkit.Chunk chunk) Saves all tracked objects held within the given chunk by invokingTracked.onUnload()on each of them.- Parameters:
chunk- the chunk whose tracked objects should be saved
-
saveChunk
Invokes the given callback for every holder tracked within the given chunk. Does nothing if the chunk's world or chunk container isn't tracked.- Parameters:
chunk- the chunk whose holders should be visitedcallback- the action to perform for each holder in the chunk
-