Class ViewerHandler<V,T extends PacketBlockViewer<V>>

java.lang.Object
net.bitbylogic.packetblocks.viewer.ViewerHandler<V,T>

public class ViewerHandler<V,T extends PacketBlockViewer<V>> extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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.
    protected 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.
    protected void
    addViewCondition(@NonNull Predicate<org.bukkit.entity.Player> condition)
    Adds a viewing condition to the list of conditions if it is not already present.
    protected T
    addViewer(@NonNull org.bukkit.entity.Player player)
    Adds the specified player as a viewer to this Packet Block.
    protected 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.
    protected boolean
    canView(@NonNull org.bukkit.entity.Player player)
    Checks if the specified player meets all the conditions required to view this Packet Block.
    protected Object
    getMetadata(@NonNull org.bukkit.entity.Player player, @NonNull String key)
    Retrieves the metadata associated with a specific player and a given key.
    protected 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.
    protected 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.
    protected Map<UUID,T>
     
    protected 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.
    protected boolean
    isViewer(@NonNull org.bukkit.entity.Player player)
    Checks whether the specified player is a viewer of this Packet Block.
    protected 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.
    protected void
    removeViewer(@NonNull org.bukkit.entity.Player player)
    Removes the specified player from the list of viewers if they are present.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ViewerHandler

      public ViewerHandler()
  • Method Details

    • getViewers

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

      protected 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

      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 associated ViewerHandler instance is returned. If the player is already a viewer, their existing ViewerHandler 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 ViewerHandler associated with the player if they meet the conditions and are added as a viewer, or an empty optional otherwise.
    • addViewer

      protected 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

      protected 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
    • 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

      protected 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.
    • 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'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

      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 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