Class GlobalBlockContainer<S extends Tracked<K>,K extends WorldKey>

java.lang.Object
net.paulem.arcana.regions.container.GlobalBlockContainer<S,K>
Type Parameters:
S - the type of the object to track
K - the key used to identify the object

public class GlobalBlockContainer<S extends Tracked<K>,K extends WorldKey> extends Object
A container that holds all the block containers for all worlds. This increases performance when dealing with many worlds, chunks and sections and avoid iterating over every single object.
  • Method Details

    • of

      public static <S extends Tracked<K>, K extends WorldKey> GlobalBlockContainer<S,K> of()
      Creates a new, empty GlobalBlockContainer.
      Type Parameters:
      S - the type of the object to track
      K - the key used to identify the object
      Returns:
      a new GlobalBlockContainer instance
    • getWorldContainer

      @Nullable public @Nullable WorldBlockContainer<S,K> getWorldContainer(UUID worldId)
      Retrieves the container for the given world, without creating it.
      Parameters:
      worldId - the UUID of the world
      Returns:
      the world's container, or null if it doesn't exist yet
    • getOrCreateWorldContainer

      public WorldBlockContainer<S,K> getOrCreateWorldContainer(UUID worldId)
      Retrieves the container for the given world, creating it first if it doesn't exist yet.
      Parameters:
      worldId - the UUID of the world
      Returns:
      the world's container, never null
    • removeWorldContainer

      public void removeWorldContainer(UUID worldId)
      Removes the container for the given world, if present.
      Parameters:
      worldId - the UUID of the world to remove
    • getWorldContainer

      @Nullable public @Nullable WorldBlockContainer<S,K> getWorldContainer(org.bukkit.World world)
      Retrieves the container for the given world, without creating it.
      Parameters:
      world - the world
      Returns:
      the world's container, or null if it doesn't exist yet
    • getOrCreateWorldContainer

      public WorldBlockContainer<S,K> getOrCreateWorldContainer(org.bukkit.World world)
      Retrieves the container for the given world, creating it first if it doesn't exist yet.
      Parameters:
      world - the world
      Returns:
      the world's container, never null
    • getHolder

      @Nullable public S getHolder(K key)
      Retrieves the tracked object located at the given key, across all worlds.
      Parameters:
      key - the key identifying the world and coordinates to look up
      Returns:
      the tracked object at the key, or null if none is registered or its world has no container
    • setHolder

      public void setHolder(K key, S tracked)
      Stores a tracked object at the given key, creating the containers for its world/chunk/section as needed.
      Parameters:
      key - the key identifying the world and coordinates to store the object at
      tracked - the object to store
    • removeHolder

      public void removeHolder(K key)
      Removes the tracked object located at the given key, if any.
      Parameters:
      key - the key identifying the world and coordinates to remove
    • getAllHolders

      public List<Holder<S,K>> getAllHolders()
      Returns:
      a collection of all holders stored across every world container
    • getAllHolders

      public <T extends Holder<S, K>> List<T> getAllHolders(Class<T> type)
      Retrieves the data of every holder across all world containers whose data is an instance of the given type.
      Type Parameters:
      T - the expected type of the holder's data
      Parameters:
      type - the class used to filter and cast each holder's data
      Returns:
      a list of the data objects matching the given type