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 classRepresents a custom implementation of theToolComponent.ToolRuleinterface.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.ToolRuleaddRule(@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.ToolRuleaddRule(@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.ToolRuleaddRule(@NotNull org.bukkit.Tag<org.bukkit.Material> tag, @Nullable Float speed, @Nullable Boolean correctForDrops) Adds a custom rule for a tag of blocks.intGets the amount of damage the tool takes per block broken.floatGets the default mining speed of the tool.@NotNull List<org.bukkit.inventory.meta.components.ToolComponent.ToolRule> getRules()Gets all custom rules for block interactions.booleanremoveRule(@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.voidsetDamagePerBlock(int damage) Sets the amount of damage the tool takes per block broken.voidsetDefaultMiningSpeed(float speed) Sets the default mining speed of the tool.voidSets 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:
getDefaultMiningSpeedin 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:
setDefaultMiningSpeedin 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:
getDamagePerBlockin 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:
setDamagePerBlockin 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:
getRulesin 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:
setRulesin 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:
addRulein 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:
addRulein 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:
addRulein 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:
removeRulein 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:
serializein interfaceorg.bukkit.configuration.serialization.ConfigurationSerializable- Returns:
- a map containing the tool properties and rules
-