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

java.lang.Object
net.bitbylogic.packetblocks.data.DataHandler<T,V>

public class DataHandler<T,V extends PacketBlockViewer<T>> extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataHandler(ViewerHolder<T,V> viewerHandler, Consumer<org.bukkit.entity.Player> updateConsumer, Function<T,List<org.bukkit.util.BoundingBox>> boundingBoxProvider, T data, int breakSpeed)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected List<org.bukkit.util.BoundingBox>
     
    protected int
     
    protected int
    getBreakSpeed(@NonNull org.bukkit.entity.Player player)
    Calculates and retrieves the break speed for the given player.
    protected T
     
    protected T
    getData(@Nullable org.bukkit.entity.Player player)
     
    protected boolean
     
    protected boolean
     
    protected void
    Sends block updates to all the viewers currently tracking the block at the specified location.
    protected void
    setAddViewerOnJoin(boolean addViewerOnJoin)
     
    protected void
    setBlockDataAndUpdate(@NonNull org.bukkit.entity.Player player, T data)
    Sets the block data for the specified player and sends an update.
    protected void
    setBreakSpeed(int breakSpeed)
     
    protected void
    setData(@NonNull org.bukkit.entity.Player player, T data)
    Sets the data for a specific player.
    protected void
    setData(T data)
     
    protected void
    Sets the data for all viewers and updates them accordingly.
    protected void
    setDataSupplier(@NonNull org.bukkit.entity.Player player, T data)
    Sets the data supplier for a specific player, allowing for dynamic control over block data.
    protected void
    Sets the block data supplier for all viewers and updates the block data for each viewer based on the provided BlockData.
    protected void
    setGlobalBreakAnimation(boolean globalBreakAnimation)
     

    Methods inherited from class java.lang.Object

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

    • data

      public T data
  • Constructor Details

    • DataHandler

      public DataHandler(ViewerHolder<T,V> viewerHandler, Consumer<org.bukkit.entity.Player> updateConsumer, Function<T,List<org.bukkit.util.BoundingBox>> boundingBoxProvider, T data, int breakSpeed)
  • Method Details

    • setDataForAll

      protected void setDataForAll(@NonNull T data)
      Sets the data for all viewers and updates them accordingly.
      Parameters:
      data - the block data to be set for all viewers
    • setDataSupplierForAll

      protected void setDataSupplierForAll(@NonNull T data)
      Sets the block data supplier for all viewers and updates the block data for each viewer based on the provided BlockData.
      Parameters:
      data - the BlockData object to be supplied to all viewers
    • setData

      protected void setData(@NonNull @NonNull org.bukkit.entity.Player player, @Nullable T data)
      Sets the data for a specific player.
      Parameters:
      player - the player for whom the block data is being set; must not be null
      data - the data to associate with the player; can be null to reset or remove the block data
    • setDataSupplier

      protected void setDataSupplier(@NonNull @NonNull org.bukkit.entity.Player player, @NonNull T data)
      Sets the data supplier for a specific player, allowing for dynamic control over block data.
      Parameters:
      player - the player for whom the BlockData supplier is being set, must not be null
      data - the data object to be supplied, must not be null
    • setBlockDataAndUpdate

      protected void setBlockDataAndUpdate(@NonNull @NonNull org.bukkit.entity.Player player, @Nullable T data)
      Sets the block data for the specified player and sends an update.
      Parameters:
      player - the player for whom the block data is being set, must not be null
      data - the block data to be set, can be null
    • getBreakSpeed

      protected int getBreakSpeed(@NonNull @NonNull org.bukkit.entity.Player player)
      Calculates and retrieves the break speed for the given player.
      Parameters:
      player - the player whose break speed is being requested, must not be null
      Returns:
      the calculated break speed for the player; returns a default value if not available
    • sendUpdates

      protected void sendUpdates()
      Sends block updates to all the viewers currently tracking the block at the specified location.

      This method iterates through all viewers stored in the `viewers` map and attempts to send a block update to each. If a viewer no longer exists or is offline, they are removed from the `viewers` map.

      The block state sent to each viewer is dependent on the `getBlockState(Player)` implementation, which determines the block's appearance based on the specific viewer.

    • getBoundingBoxes

      protected List<org.bukkit.util.BoundingBox> getBoundingBoxes()
    • getData

      protected T getData()
    • getData

      protected T getData(@Nullable @Nullable org.bukkit.entity.Player player)
    • getBreakSpeed

      protected int getBreakSpeed()
    • isAddViewerOnJoin

      protected boolean isAddViewerOnJoin()
    • isGlobalBreakAnimation

      protected boolean isGlobalBreakAnimation()
    • setBreakSpeed

      protected void setBreakSpeed(int breakSpeed)
    • setAddViewerOnJoin

      protected void setAddViewerOnJoin(boolean addViewerOnJoin)
    • setGlobalBreakAnimation

      protected void setGlobalBreakAnimation(boolean globalBreakAnimation)
    • setData

      protected void setData(T data)