Interface ViewerHolder<V,T extends PacketBlockViewer<V>>
- All Known Subinterfaces:
PacketBlockHolder<T,V>
- All Known Implementing Classes:
PacketBlock,PacketBlockGroup
public interface ViewerHolder<V,T extends PacketBlockViewer<V>>
-
Method Summary
Modifier and TypeMethodDescriptiondefault 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.default 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.default voidaddViewCondition(@NonNull Predicate<org.bukkit.entity.Player> condition) Adds a viewing condition to the list of conditions if it is not already present.default 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.default booleancanView(@NonNull org.bukkit.entity.Player player) Checks if the specified player meets all the conditions required to view this Packet Block.default ObjectgetMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key) Retrieves the metadata associated with a specific player and a given key.default 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.default 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.default booleanisViewer(@NonNull org.bukkit.entity.Player player) Checks whether the specified player is a viewer of this Packet Block.default 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.default voidremoveViewer(@NonNull org.bukkit.entity.Player player) Removes the specified player from the list of viewers if they are present.
-
Method Details
-
getViewerHandler
ViewerHandler<V,T> getViewerHandler() -
getViewers
-
canView
default 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
default 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
default 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 associatedViewerHolderinstance is returned. If the player is already a viewer, their existingViewerHolderis 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 theViewerHolderassociated 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
-
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.
-
removeViewer
default 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
-
addMetadata
default 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
default 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
default 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
default 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
default 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
-