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 ClassesModifier and TypeClassDescriptionstatic class
Represents a custom implementation of theToolComponent.ToolRule
interface.Nested classes/interfaces inherited from interface org.bukkit.inventory.meta.components.ToolComponent
org.bukkit.inventory.meta.components.ToolComponent.ToolRule
-
Constructor Summary
ConstructorsConstructorDescriptionCustomToolComponent
(float defaultMiningSpeed, int damagePerBlock) Constructs a new CustomToolComponent with the given default mining speed and block damage. -
Method Summary
Modifier and TypeMethodDescription@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> getRules()
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.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
Sets the list of custom tool rules.
-
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 tooldamagePerBlock
- 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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.bukkit.inventory.meta.components.ToolComponent
- Parameters:
block
- the material of the blockspeed
- the custom mining speed, or null to use the defaultcorrectForDrops
- 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 interfaceorg.bukkit.inventory.meta.components.ToolComponent
- Parameters:
blocks
- a collection of block materialsspeed
- the custom mining speed, or null to use the defaultcorrectForDrops
- 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 interfaceorg.bukkit.inventory.meta.components.ToolComponent
- Parameters:
tag
- the tag representing multiple block typesspeed
- the custom mining speed, or null to use the defaultcorrectForDrops
- 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 interfaceorg.bukkit.inventory.meta.components.ToolComponent
- Parameters:
rule
- the rule to remove- Returns:
- true if the rule was removed, false otherwise
-
serialize
Serializes this tool component into a map for data storage.- Specified by:
serialize
in interfaceorg.bukkit.configuration.serialization.ConfigurationSerializable
- Returns:
- a map containing the tool properties and rules
-