Class CustomToolComponent

java.lang.Object
io.github.lucfr1746.llibrary.itemstack.component.CustomToolComponent
All Implemented Interfaces:
org.bukkit.configuration.serialization.ConfigurationSerializable, org.bukkit.inventory.meta.components.ToolComponent

public class CustomToolComponent extends Object implements org.bukkit.inventory.meta.components.ToolComponent
Represents a custom implementation of the ToolComponent interface. This class allows configuring custom tool properties like mining speed, block damage, and specific rules for block interactions.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a custom implementation of the ToolComponent.ToolRule interface.

    Nested classes/interfaces inherited from interface org.bukkit.inventory.meta.components.ToolComponent

    org.bukkit.inventory.meta.components.ToolComponent.ToolRule
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomToolComponent(float defaultMiningSpeed, int damagePerBlock)
    Constructs a new CustomToolComponent with the given default mining speed and block damage.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule
    addRule(@NotNull Collection<org.bukkit.Material> blocks, @Nullable Float speed, @Nullable Boolean correctForDrops)
    Adds a custom rule for multiple blocks.
    @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule
    addRule(@NotNull org.bukkit.Material block, @Nullable Float speed, @Nullable Boolean correctForDrops)
    Adds a custom rule for a specific block.
    @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule
    addRule(@NotNull org.bukkit.Tag<org.bukkit.Material> tag, @Nullable Float speed, @Nullable Boolean correctForDrops)
    Adds a custom rule for a tag of blocks.
    int
    Gets the amount of damage the tool takes per block broken.
    float
    Gets the default mining speed of the tool.
    @NotNull List<org.bukkit.inventory.meta.components.ToolComponent.ToolRule>
    Gets all custom rules for block interactions.
    boolean
    removeRule(@NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule rule)
    Removes a specific rule from the tool.
    @NotNull Map<String,Object>
    Serializes this tool component into a map for data storage.
    void
    setDamagePerBlock(int damage)
    Sets the amount of damage the tool takes per block broken.
    void
    setDefaultMiningSpeed(float speed)
    Sets the default mining speed of the tool.
    void
    setRules(@NotNull List<org.bukkit.inventory.meta.components.ToolComponent.ToolRule> rules)
    Sets the list of custom tool rules.

    Methods inherited from class java.lang.Object

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

    • CustomToolComponent

      public CustomToolComponent(float defaultMiningSpeed, int damagePerBlock)
      Constructs a new CustomToolComponent with the given default mining speed and block damage.
      Parameters:
      defaultMiningSpeed - the default mining speed of the tool
      damagePerBlock - the amount of damage the tool takes per block broken
  • Method Details

    • getDefaultMiningSpeed

      public float getDefaultMiningSpeed()
      Gets the default mining speed of the tool.
      Specified by:
      getDefaultMiningSpeed in interface org.bukkit.inventory.meta.components.ToolComponent
      Returns:
      the default mining speed
    • setDefaultMiningSpeed

      public void setDefaultMiningSpeed(float speed)
      Sets the default mining speed of the tool.
      Specified by:
      setDefaultMiningSpeed in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      speed - the new mining speed
    • getDamagePerBlock

      public int getDamagePerBlock()
      Gets the amount of damage the tool takes per block broken.
      Specified by:
      getDamagePerBlock in interface org.bukkit.inventory.meta.components.ToolComponent
      Returns:
      the damage per block
    • setDamagePerBlock

      public void setDamagePerBlock(int damage)
      Sets the amount of damage the tool takes per block broken.
      Specified by:
      setDamagePerBlock in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      damage - the new damage per block
    • getRules

      @NotNull public @NotNull List<org.bukkit.inventory.meta.components.ToolComponent.ToolRule> getRules()
      Gets all custom rules for block interactions.
      Specified by:
      getRules in interface org.bukkit.inventory.meta.components.ToolComponent
      Returns:
      a list of tool rules
    • setRules

      public void setRules(@NotNull @NotNull List<org.bukkit.inventory.meta.components.ToolComponent.ToolRule> rules)
      Sets the list of custom tool rules.
      Specified by:
      setRules in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      rules - the list of tool rules
    • addRule

      @NotNull public @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule addRule(@NotNull @NotNull org.bukkit.Material block, @Nullable @Nullable Float speed, @Nullable @Nullable Boolean correctForDrops)
      Adds a custom rule for a specific block.
      Specified by:
      addRule in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      block - the material of the block
      speed - the custom mining speed, or null to use the default
      correctForDrops - whether the rule affects drops or null for default behavior
      Returns:
      the created ToolRule
    • addRule

      @NotNull public @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule addRule(@NotNull @NotNull Collection<org.bukkit.Material> blocks, @Nullable @Nullable Float speed, @Nullable @Nullable Boolean correctForDrops)
      Adds a custom rule for multiple blocks.
      Specified by:
      addRule in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      blocks - a collection of block materials
      speed - the custom mining speed, or null to use the default
      correctForDrops - whether the rule affects drops or null for default behavior
      Returns:
      the created ToolRule
    • addRule

      @NotNull public @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule addRule(@NotNull @NotNull org.bukkit.Tag<org.bukkit.Material> tag, @Nullable @Nullable Float speed, @Nullable @Nullable Boolean correctForDrops)
      Adds a custom rule for a tag of blocks.
      Specified by:
      addRule in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      tag - the tag representing multiple block types
      speed - the custom mining speed, or null to use the default
      correctForDrops - whether the rule affects drops or null for default behavior
      Returns:
      the created ToolRule
    • removeRule

      public boolean removeRule(@NotNull @NotNull org.bukkit.inventory.meta.components.ToolComponent.ToolRule rule)
      Removes a specific rule from the tool.
      Specified by:
      removeRule in interface org.bukkit.inventory.meta.components.ToolComponent
      Parameters:
      rule - the rule to remove
      Returns:
      true if the rule was removed, false otherwise
    • serialize

      @NotNull public @NotNull Map<String,Object> serialize()
      Serializes this tool component into a map for data storage.
      Specified by:
      serialize in interface org.bukkit.configuration.serialization.ConfigurationSerializable
      Returns:
      a map containing the tool properties and rules