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 Type
    Method
    Description
    default T
    addAndUpdateViewer(@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 void
    addMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key, @NonNull Object object)
    Adds a metadata key-value pair to the specific player's PacketBlockPlayerData, if the player is a viewer.
    default void
    addViewCondition(@NonNull Predicate<org.bukkit.entity.Player> condition)
    Adds a viewing condition to the list of conditions if it is not already present.
    default T
    addViewer(@NonNull org.bukkit.entity.Player player)
    Adds the specified player as a viewer to this Packet Block.
    default Optional<T>
    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 boolean
    canView(@NonNull org.bukkit.entity.Player player)
    Checks if the specified player meets all the conditions required to view this Packet Block.
    default Object
    getMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key)
    Retrieves the metadata associated with a specific player and a given key.
    default Object
    getMetadataAs(@NonNull org.bukkit.entity.Player player, @NonNull String key, @Nullable Object fallback)
    Retrieves metadata associated with a given key for a specified player.
    default Optional<T>
    getViewer(@NonNull org.bukkit.entity.Player player)
    Retrieves the PacketBlockPlayerData associated with the given player if they are a viewer of this Packet Block.
     
    default Map<UUID,T>
     
    default boolean
    hasMetadata(@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 boolean
    isViewer(@NonNull org.bukkit.entity.Player player)
    Checks whether the specified player is a viewer of this Packet Block.
    default void
    removeMetadata(@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 void
    removeViewer(@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

      default Map<UUID,T> 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

      default Optional<T> getViewer(@NonNull @NonNull org.bukkit.entity.Player player)
      Retrieves the PacketBlockPlayerData associated 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 Optional containing the PacketBlockPlayerData associated 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 associated ViewerHolder instance is returned. If the player is already a viewer, their existing ViewerHolder is 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 Optional containing the ViewerHolder associated with the player if they meet the conditions and are added as a viewer, or an empty optional otherwise.
    • addViewer

      default T addViewer(@NonNull @NonNull org.bukkit.entity.Player player)
      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 PacketBlockPlayerData instance associated with the added player.
    • addAndUpdateViewer

      default T addAndUpdateViewer(@NonNull @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. 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 PacketBlockPlayerData instance associated with the added player
    • addViewCondition

      default void addViewCondition(@NonNull @NonNull Predicate<org.bukkit.entity.Player> condition)
      Adds a viewing condition to the list of conditions if it is not already present.
      Parameters:
      condition - the condition to be added, represented as a Predicate<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's PacketBlockPlayerData, 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 null
      key - the key associated with the metadata to retrieve; must not be null
      fallback - 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