Class PacketBlockManager

java.lang.Object
net.bitbylogic.packetblocks.block.PacketBlockManager

public class PacketBlockManager extends Object
  • Constructor Details

    • PacketBlockManager

      public PacketBlockManager()
  • Method Details

    • createBlock

      public PacketBlock createBlock(@NonNull @NonNull org.bukkit.Location location, @NonNull @NonNull org.bukkit.block.data.BlockData blockData)
      Creates a new PacketBlock instance at the specified location with the given block data. The created block is registered within the internally managed collection, ensuring it is appropriately tracked for further operations. If the block already exists in the specified chunk, no duplicate will be created, and the existing instance will be returned.
      Parameters:
      location - the location of the block to be created; must not be null
      blockData - the data of the block to be created; must not be null
      Returns:
      the newly created PacketBlock instance, or the existing instance if one already exists at the location; returns null if the location's world is null
    • removeBlock

      public void removeBlock(@NonNull @NonNull PacketBlock packetBlock)
      Removes the specified PacketBlock from the blockLocations map and updates its visual state for all associated viewers. If the PacketBlock exists in any chunk's block list, it is removed from that list, and its associated viewers are sent a block update to reset the affected block's state.
      Parameters:
      packetBlock - the PacketBlock to be removed; must not be null
    • removeIf

      public void removeIf(Predicate<PacketBlock> removePredicate)
      Removes PacketBlock instances from the managed collection if they satisfy a specified condition. The condition is defined by the provided Predicate. Additionally, it schedules a visual update for players viewing the affected blocks.
      Parameters:
      removePredicate - the condition used to determine which PacketBlock instances should be removed; must not be null.
    • getBlock

      public Optional<PacketBlock> getBlock(@NonNull @NonNull org.bukkit.Location location)
      Retrieves an Optional of PacketBlock located at the specified Location. If the provided location's world is null or no matching block exists, an empty Optional is returned.
      Parameters:
      location - the Location at which to find the PacketBlock; must not be null
      Returns:
      an Optional containing the matching PacketBlock, or an empty Optional if none is found
    • getBlocks

      public List<PacketBlock> getBlocks(@NonNull @NonNull org.bukkit.World world)
      Retrieves a list of PacketBlock instances associated with the specified world. Only blocks that belong to the given world will be included in the returned list.
      Parameters:
      world - the world for which the packet blocks are being queried; must not be null
      Returns:
      a list of PacketBlock instances that exist in the specified world
    • getBlocks

      public List<PacketBlock> getBlocks(@NonNull @NonNull org.bukkit.World world, int chunkX, int chunkZ)
      Retrieves a list of PacketBlock instances located within the specified chunk in the given world. The chunk is identified by its X and Z coordinates.
      Parameters:
      world - the world in which the blocks are being queried; must not be null
      chunkX - the X-coordinate of the chunk
      chunkZ - the Z-coordinate of the chunk
      Returns:
      a list of PacketBlock instances within the specified chunk, or an empty list if no blocks are found
    • getBlocksByViewer

      public List<PacketBlock> getBlocksByViewer(@NonNull @NonNull org.bukkit.entity.Player player)
      Retrieves a list of PacketBlock instances that are visible to the specified player. These blocks are determined based on the player's unique identifier and their visibility status.
      Parameters:
      player - the player for whom the visible blocks are being queried; must not be null
      Returns:
      a list of PacketBlock instances that the specified player can view
    • getBlocksByViewerWithMeta

      public List<PacketBlock> getBlocksByViewerWithMeta(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String metaKey)
      Retrieves a list of PacketBlock instances that are visible to the specified player and contain the specified metadata key.
      Parameters:
      player - the player whose visible blocks are being queried; must not be null.
      metaKey - the metadata key that the blocks must have to be included in the results; must not be null.
      Returns:
      a list of PacketBlock instances that are both visible to the specified player and contain the specified metadata key.
    • getBlocksByMetadata

      public List<PacketBlock> getBlocksByMetadata(@NonNull @NonNull String key)
      Retrieves a list of PacketBlock instances that contain the specified metadata key.
      Parameters:
      key - the metadata key to filter blocks by; must not be null.
      Returns:
      a list of PacketBlock instances that contain the specified metadata key.
    • getHitBlocks

      public List<PacketBlock> getHitBlocks(@NonNull @NonNull org.bukkit.World world, @NonNull @NonNull org.bukkit.util.BoundingBox boundingBox)
      Retrieves a list of PacketBlock instances that intersect with the specified bounding box within a given world.
      Parameters:
      world - the world in which the blocks are being queried; must not be null
      boundingBox - the bounding box used to filter the blocks; must not be null
      Returns:
      a list of PacketBlock instances that overlap with the specified bounding box
    • getChunksInBoundingBox

      public Set<org.bukkit.Chunk> getChunksInBoundingBox(org.bukkit.World world, org.bukkit.util.BoundingBox box)
      Retrieves all chunks that intersect with the provided bounding box in the given world.
      Parameters:
      world - the world in which to search for chunks, must not be null
      box - the bounding box to define the search area, must not be null
      Returns:
      a set of chunks that intersect with the specified bounding box
    • getHitBlocksByViewer

      public List<PacketBlock> getHitBlocksByViewer(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull org.bukkit.util.BoundingBox boundingBox)
      Retrieves a list of PacketBlock instances that are visible to the specified player and overlap with the given bounding box.
      Parameters:
      player - the player whose visible blocks are being queried, must not be null
      boundingBox - the bounding box used to filter the blocks, must not be null
      Returns:
      a list of PacketBlock instances that are both visible to the player and intersect with the specified bounding box
    • getHitBlocksByViewerWithMeta

      public List<PacketBlock> getHitBlocksByViewerWithMeta(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull org.bukkit.util.BoundingBox boundingBox, @NonNull @NonNull String metaKey)
      Retrieves a list of PacketBlock instances that are within a specified bounding box, are visible to the specified player, and contain the given metadata key.
      Parameters:
      player - the player for whom the blocks' visibility is checked; must not be null.
      boundingBox - the bounding box defining the area to search for blocks; must not be null.
      metaKey - the metadata key that the blocks must have to be included in the results; must not be null.
      Returns:
      a list of PacketBlock instances satisfying the conditions of being visible to the player, located within the bounding box, and containing the specified metadata key.
    • updateBlocks

      public void updateBlocks(@NonNull @NonNull org.bukkit.entity.Player player)
      Updates all visually modified blocks for the specified player in their visible region. This method uses the player's current view to determine which blocks to update.
      Parameters:
      player - the player for whom the block updates should be performed; must not be null
    • updateBlocksWithMeta

      public void updateBlocksWithMeta(@NonNull @NonNull org.bukkit.entity.Player player, @Nullable @Nullable String metaKey)
      Updates the visual state of blocks for a specific player, optionally filtering by metadata. If a metadata key is provided, only blocks associated with that metadata will be updated. If the metadata key is null, all relevant blocks for the player will be updated.
      Parameters:
      player - the player for whom the blocks' visual states are being updated
      metaKey - an optional metadata key used to filter the blocks being updated; if null, all relevant blocks are updated