Class VeinMinerPlayer

java.lang.Object
wtf.choco.veinminer.VeinMinerPlayer
All Implemented Interfaces:
MessageReceiver, PluginMessageListener, ServerboundPluginMessageListener

public final class VeinMinerPlayer extends Object implements MessageReceiver, ServerboundPluginMessageListener
A player wrapper containing player-related data for VeinMiner, as well as a network handler for vein miner protocol messages.
  • Constructor Details

    • VeinMinerPlayer

      @Internal public VeinMinerPlayer(@NotNull @NotNull PlatformPlayer player, @NotNull @NotNull ClientConfig clientConfig)
      Construct a new VeinMinerPlayer.

      This is an internal method. To get an instance of VeinMinerPlayer, the VeinMinerPlayerManager should be used instead. Constructing a new instance of this class may have unintended side-effects and will not have accurate information tracked by VeinMiner.

      Parameters:
      player - the player
      clientConfig - the client configuration
      See Also:
  • Method Details

    • getPlayer

      @NotNull public @NotNull PlatformPlayer getPlayer()
      Get the PlatformPlayer wrapped by this vein miner player.
      Returns:
      the platform player
    • getPlayerUUID

      @NotNull public @NotNull UUID getPlayerUUID()
      Get the UUID of this player.
      Returns:
      the player UUID
    • setVeinMinerEnabled

      public boolean setVeinMinerEnabled(@NotNull @NotNull VeinMinerToolCategory category, boolean enabled)
      Set whether or not the given VeinMinerToolCategory is enabled.
      Parameters:
      category - the category to change
      enabled - whether or not the category is enabled
      Returns:
      true if the category state was changed, false if the category remains unchanged
    • setVeinMinerEnabled

      public boolean setVeinMinerEnabled(boolean enabled)
      Set whether or not vein miner is enabled entirely.

      If true and one or more categories are disabled, it will enable all disabled categories. If {code false} not all categories have been disabled, it will disable all remaining categories.

      Parameters:
      enabled - whether or not to enable vein miner
      Returns:
      true if at least one category was changed as a result of the enable toggle
    • isVeinMinerEnabled

      public boolean isVeinMinerEnabled(@NotNull @NotNull VeinMinerToolCategory category)
      Check whether or not the given VeinMinerToolCategory is enabled.
      Parameters:
      category - the category to check
      Returns:
      true if enabled, false otherwise
    • isVeinMinerEnabled

      public boolean isVeinMinerEnabled()
      Check whether or not vein miner is completely enabled.

      If at least one category is disabled (according to isVeinMinerEnabled(VeinMinerToolCategory)), this method will return false.

      Returns:
      true if fully enabled, false if at least one category is disabled
    • isVeinMinerDisabled

      public boolean isVeinMinerDisabled()
      Check whether or not vein miner is completely disabled.

      If at least one category is enabled (according to isVeinMinerEnabled(VeinMinerToolCategory)), this method will return false.

      Returns:
      true if fully disabled, false if at least one category is enabled
    • isVeinMinerPartiallyDisabled

      public boolean isVeinMinerPartiallyDisabled()
      Check whether or not vein miner has been partially disabled but still has at least one category still enabled.
      Returns:
      true if partially disabled, false if all categories are enabled or all categories are disabled
    • getDisabledCategories

      @NotNull public @NotNull @UnmodifiableView Set<VeinMinerToolCategory> getDisabledCategories()
      Get this player's disabled VeinMinerToolCategories.
      Returns:
      the disabled tool categories
    • setActivationStrategy

      public void setActivationStrategy(@NotNull @NotNull ActivationStrategy activationStrategy)
      Set the ActivationStrategy to use for this player.
      Parameters:
      activationStrategy - the activation strategy
    • getActivationStrategy

      @NotNull public @NotNull ActivationStrategy getActivationStrategy()
      Get the ActivationStrategy to use for this player.
      Returns:
      the activation strategy
    • setVeinMiningPattern

      public void setVeinMiningPattern(@NotNull @NotNull VeinMiningPattern veinMiningPattern, boolean updateClient)
      Set the VeinMiningPattern to use for this player.
      Parameters:
      veinMiningPattern - the pattern
      updateClient - whether or not the client should be informed of this update
    • setVeinMiningPattern

      public void setVeinMiningPattern(@NotNull @NotNull VeinMiningPattern veinMiningPattern)
      Set the VeinMiningPattern to use for this player and update the client.
      Parameters:
      veinMiningPattern - the pattern
    • getVeinMiningPattern

      @NotNull public @NotNull VeinMiningPattern getVeinMiningPattern()
      Get the VeinMiningPattern to use for this player.
      Returns:
      the pattern
    • executeWhenClientIsReady

      public boolean executeWhenClientIsReady(@NotNull @NotNull Runnable runnable)
      Execute the given Runnable when the client is ready.
      Parameters:
      runnable - the runnable to execute
      Returns:
      true if the client is not yet ready and the task was queued, false if the task was executed immediately
      See Also:
    • executeWhenClientIsReady

      public boolean executeWhenClientIsReady(@NotNull @NotNull Consumer<VeinMinerPlayer> consumer)
      Execute the given Consumer when the client is ready.
      Parameters:
      consumer - the consumer to execute
      Returns:
      true if the client is not yet ready and the task was queued, false if the task was executed immediately
      See Also:
    • isClientReady

      public boolean isClientReady()
      Check whether or not the client is ready to receive messages.

      This method will only be true if isUsingClientMod() is true, and if the client has successfully shaken hands with the server, is capable of being sent a client message, and has been synchronized with the server as per the protocol specification.

      Returns:
      true if the client is ready, false otherwise
      See Also:
    • isUsingClientMod

      public boolean isUsingClientMod()
      Check whether or not this player is using the client mod.
      Returns:
      true if using client mod, false otherwise
    • isClientKeyPressed

      public boolean isClientKeyPressed()
      Check whether or not vein miner is active as a result of this user's client mod.
      Returns:
      true if active, false otherwise
    • setClientConfig

      public void setClientConfig(@NotNull @NotNull ClientConfig clientConfig)
      Set the ClientConfig for this player.
      Parameters:
      clientConfig - the client config to set
    • getClientConfig

      @NotNull public @NotNull ClientConfig getClientConfig()
      Get the ClientConfig for this player.

      Note that this configuration only really applies if isUsingClientMod() is true.

      Returns:
      the client config
    • isVeinMinerActive

      public boolean isVeinMinerActive()
      Check whether or not vein miner is currently active and ready to be used.

      NOTE: Do not confuse this with isVeinMinerEnabled(). This method verifies whether or not the player has activated vein miner according to their current activation strategy (getActivationStrategy()), NOT whether they have it enabled via commands.

      Returns:
      true if active, false otherwise
    • setVeinMining

      @Internal public void setVeinMining(boolean veinMining)
      Set whether or not the player is actively vein mining.

      Not part of the public API. This method is intended for internal use only.

      Parameters:
      veinMining - the new vein mining state
    • isVeinMining

      public boolean isVeinMining()
      Check whether or not the player is actively vein mining.
      Returns:
      true if using vein miner, false otherwise
    • setDirty

      public void setDirty(boolean dirty)
      Set whether or not this player data should be written.
      Parameters:
      dirty - true if dirty, false otherwise
    • isDirty

      public boolean isDirty()
      Check whether or not this player data has been modified since last write.
      Returns:
      true if modified, false otherwise
    • sendMessage

      @Internal public void sendMessage(@NotNull @NotNull NamespacedKey channel, byte[] message)
      Description copied from interface: MessageReceiver
      Send a message represented by the given bytes on the specified channel.
      Specified by:
      sendMessage in interface MessageReceiver
      Parameters:
      channel - the channel on which the message should be sent
      message - the message bytes to be sent
    • handleHandshake

      @Internal public void handleHandshake(@NotNull @NotNull PluginMessageServerboundHandshake message)
      Description copied from interface: ServerboundPluginMessageListener
      Specified by:
      handleHandshake in interface ServerboundPluginMessageListener
      Parameters:
      message - the message
    • handleToggleVeinMiner

      @Internal public void handleToggleVeinMiner(@NotNull @NotNull PluginMessageServerboundToggleVeinMiner message)
      Description copied from interface: ServerboundPluginMessageListener
      Specified by:
      handleToggleVeinMiner in interface ServerboundPluginMessageListener
      Parameters:
      message - the message
    • handleRequestVeinMine

      @Internal public void handleRequestVeinMine(@NotNull @NotNull PluginMessageServerboundRequestVeinMine message)
      Description copied from interface: ServerboundPluginMessageListener
      Specified by:
      handleRequestVeinMine in interface ServerboundPluginMessageListener
      Parameters:
      message - the message
    • handleSelectPattern

      @Internal public void handleSelectPattern(@NotNull @NotNull PluginMessageServerboundSelectPattern message)
      Description copied from interface: ServerboundPluginMessageListener
      Specified by:
      handleSelectPattern in interface ServerboundPluginMessageListener
      Parameters:
      message - the message