Class PacketBlockManager
java.lang.Object
net.bitbylogic.packetblocks.block.PacketBlockManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateBlock
(@NonNull org.bukkit.Location location, @NonNull org.bukkit.block.data.BlockData blockData) Creates a newPacketBlock
instance at the specified location with the given block data.getBlock
(@NonNull org.bukkit.Location location) getBlocks
(@NonNull org.bukkit.World world) Retrieves a list ofPacketBlock
instances associated with the specified world.getBlocks
(@NonNull org.bukkit.World world, int chunkX, int chunkZ) Retrieves a list ofPacketBlock
instances located within the specified chunk in the given world.getBlocksByMetadata
(@NonNull String key) Retrieves a list ofPacketBlock
instances that contain the specified metadata key.getBlocksByViewer
(@NonNull org.bukkit.entity.Player player) Retrieves a list ofPacketBlock
instances that are visible to the specified player.getBlocksByViewerWithMeta
(@NonNull org.bukkit.entity.Player player, @NonNull String metaKey) Retrieves a list ofPacketBlock
instances that are visible to the specified player and contain the specified metadata key.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.getHitBlocks
(@NonNull org.bukkit.World world, @NonNull org.bukkit.util.BoundingBox boundingBox) Retrieves a list ofPacketBlock
instances that intersect with the specified bounding box within a given world.getHitBlocksByViewer
(@NonNull org.bukkit.entity.Player player, @NonNull org.bukkit.util.BoundingBox boundingBox) Retrieves a list ofPacketBlock
instances that are visible to the specified player and overlap with the given bounding box.getHitBlocksByViewerWithMeta
(@NonNull org.bukkit.entity.Player player, @NonNull org.bukkit.util.BoundingBox boundingBox, @NonNull String metaKey) Retrieves a list ofPacketBlock
instances that are within a specified bounding box, are visible to the specified player, and contain the given metadata key.void
removeBlock
(@NonNull PacketBlock packetBlock) Removes the specifiedPacketBlock
from the blockLocations map and updates its visual state for all associated viewers.void
removeIf
(Predicate<PacketBlock> removePredicate) RemovesPacketBlock
instances from the managed collection if they satisfy a specified condition.void
updateBlocks
(@NonNull org.bukkit.entity.Player player) Updates all visually modified blocks for the specified player in their visible region.void
updateBlocksWithMeta
(@NonNull org.bukkit.entity.Player player, @Nullable String metaKey) Updates the visual state of blocks for a specific player, optionally filtering by metadata.
-
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 newPacketBlock
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 nullblockData
- 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
Removes the specifiedPacketBlock
from the blockLocations map and updates its visual state for all associated viewers. If thePacketBlock
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
- thePacketBlock
to be removed; must not be null
-
removeIf
RemovesPacketBlock
instances from the managed collection if they satisfy a specified condition. The condition is defined by the providedPredicate
. Additionally, it schedules a visual update for players viewing the affected blocks.- Parameters:
removePredicate
- the condition used to determine whichPacketBlock
instances should be removed; must not be null.
-
getBlock
Retrieves anOptional
ofPacketBlock
located at the specifiedLocation
. If the provided location's world is null or no matching block exists, an emptyOptional
is returned.- Parameters:
location
- theLocation
at which to find thePacketBlock
; must not be null- Returns:
- an
Optional
containing the matchingPacketBlock
, or an emptyOptional
if none is found
-
getBlocks
Retrieves a list ofPacketBlock
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 ofPacketBlock
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 nullchunkX
- the X-coordinate of the chunkchunkZ
- 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
Retrieves a list ofPacketBlock
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 ofPacketBlock
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
Retrieves a list ofPacketBlock
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 ofPacketBlock
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 nullboundingBox
- 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 nullbox
- 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 ofPacketBlock
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 nullboundingBox
- 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 ofPacketBlock
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 updatedmetaKey
- an optional metadata key used to filter the blocks being updated; if null, all relevant blocks are updated
-