Class ViewerHandler<V,T extends PacketBlockViewer<V>>
java.lang.Object
net.bitbylogic.packetblocks.viewer.ViewerHandler<V,T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TaddAndUpdateViewer(@NonNull org.bukkit.entity.Player player) Adds the specified player as a viewer to this Packet Block if they are not already added and updates their block state to reflect the current state of the Packet Block.protected voidaddMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key, @NonNull Object object) Adds a metadata key-value pair to the specific player'sPacketBlockPlayerData, if the player is a viewer.protected voidaddViewCondition(@NonNull Predicate<org.bukkit.entity.Player> condition) Adds a viewing condition to the list of conditions if it is not already present.protected TaddViewer(@NonNull org.bukkit.entity.Player player) Adds the specified player as a viewer to this Packet Block.attemptAddViewer(@NonNull org.bukkit.entity.Player player, boolean sendUpdate) Attempts to add the specified player as a viewer to this Packet Block if they meet the viewing conditions.protected booleancanView(@NonNull org.bukkit.entity.Player player) Checks if the specified player meets all the conditions required to view this Packet Block.protected ObjectgetMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key) Retrieves the metadata associated with a specific player and a given key.protected ObjectgetMetadataAs(@NonNull org.bukkit.entity.Player player, @NonNull String key, @Nullable Object fallback) Retrieves metadata associated with a given key for a specified player.getViewer(@NonNull org.bukkit.entity.Player player) Retrieves thePacketBlockPlayerDataassociated with the given player if they are a viewer of this Packet Block.protected booleanhasMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key) Checks if the specified player has metadata associated with the given key within this Packet Block.protected booleanisViewer(@NonNull org.bukkit.entity.Player player) Checks whether the specified player is a viewer of this Packet Block.protected voidremoveMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key) Removes the metadata associated with a specific key for the given player, if the player is a viewer of this PacketBlock.protected voidremoveViewer(@NonNull org.bukkit.entity.Player player) Removes the specified player from the list of viewers if they are present.
-
Constructor Details
-
ViewerHandler
public ViewerHandler()
-
-
Method Details
-
getViewers
-
canView
protected boolean canView(@NonNull @NonNull org.bukkit.entity.Player player) Checks if the specified player meets all the conditions required to view this Packet Block. The conditions are evaluated using the stream of view requirements associated with this block.- Parameters:
player- The player whose eligibility to view the block is being checked. Must not be null.- Returns:
- True if the player satisfies all the view conditions, otherwise false.
-
isViewer
protected boolean isViewer(@NonNull @NonNull org.bukkit.entity.Player player) Checks whether the specified player is a viewer of this Packet Block.- Parameters:
player- The player to check. Must not be null.- Returns:
- True if the player is a viewer of this Packet Block, false otherwise.
-
getViewer
Retrieves thePacketBlockPlayerDataassociated with the given player if they are a viewer of this Packet Block.- Parameters:
player- The player whose viewer data is to be retrieved. Must not be null.- Returns:
- An
Optionalcontaining thePacketBlockPlayerDataassociated with the player if they are a viewer, or an empty optional if they are not a viewer.
-
attemptAddViewer
protected Optional<T> attemptAddViewer(@NonNull @NonNull org.bukkit.entity.Player player, boolean sendUpdate) Attempts to add the specified player as a viewer to this Packet Block if they meet the viewing conditions. If the player is successfully added, an optional containing the associatedViewerHandlerinstance is returned. If the player is already a viewer, their existingViewerHandleris returned. No viewer is added if the player does not meet the viewing conditions.- Parameters:
player- The player to attempt to add as a viewer.sendUpdate- Whether to send a block update to the player upon successfully adding them as a viewer.- Returns:
- An
Optionalcontaining theViewerHandlerassociated with the player if they meet the conditions and are added as a viewer, or an empty optional otherwise.
-
addViewer
Adds the specified player as a viewer to this Packet Block. This method bypasses any view requirements that are set.- Parameters:
player- The player to add as a viewer.- Returns:
- The
PacketBlockPlayerDatainstance associated with the added player.
-
addAndUpdateViewer
Adds the specified player as a viewer to this Packet Block if they are not already added and updates their block state to reflect the current state of the Packet Block. This method bypasses any view requirements that are set.- Parameters:
player- The player to add as a viewer and send block updates to- Returns:
- The
PacketBlockPlayerDatainstance associated with the added player
-
removeViewer
protected void removeViewer(@NonNull @NonNull org.bukkit.entity.Player player) Removes the specified player from the list of viewers if they are present. If the player is successfully removed, it sends a block change notification to the player for a specific location.- Parameters:
player- the player to be removed from the viewers list; must not be null
-
addViewCondition
Adds a viewing condition to the list of conditions if it is not already present.- Parameters:
condition- the condition to be added, represented as aPredicate<Player>. This condition evaluates to determine whether a player meets the viewing criteria.
-
addMetadata
protected void addMetadata(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String key, @NonNull @NonNull Object object) Adds a metadata key-value pair to the specific player'sPacketBlockPlayerData, if the player is a viewer.- Parameters:
player- The player whose metadata is being updated. Must not be null.key- The key for the metadata entry. Must not be null.object- The value associated with the specified key. Must not be null.
-
removeMetadata
protected void removeMetadata(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String key) Removes the metadata associated with a specific key for the given player, if the player is a viewer of this PacketBlock. This allows targeted removal of metadata entries tied to individual players.- Parameters:
player- The player whose associated metadata is to be removed. Must not be null.key- The key of the metadata to be removed. Must not be null.
-
hasMetadata
protected boolean hasMetadata(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String key) Checks if the specified player has metadata associated with the given key within this Packet Block.- Parameters:
player- The player whose metadata association is to be checked. Must not be null.key- The key of the metadata to check. Must not be null.- Returns:
- True if the specified player has metadata associated with the given key, otherwise false.
-
getMetadata
protected Object getMetadata(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String key) Retrieves the metadata associated with a specific player and a given key.- Parameters:
player- The player for whom metadata is being retrieved. Must not be null.key- The key identifying the metadata to be retrieved. Must not be null.- Returns:
- The metadata object associated with the specified player and key, or null if no metadata exists for the key.
-
getMetadataAs
protected Object getMetadataAs(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull @NonNull String key, @Nullable @Nullable Object fallback) Retrieves metadata associated with a given key for a specified player. If no metadata is found, a fallback value will be returned.- Parameters:
player- the player whose metadata is to be retrieved; must not be nullkey- the key associated with the metadata to retrieve; must not be nullfallback- the value to return if no associated metadata is found; can be null- Returns:
- the metadata value associated with the specified key, or the fallback value if no metadata is found
-