Class CustomDurability
java.lang.Object
me.deecaad.weaponmechanics.weapon.shoot.CustomDurability
- All Implemented Interfaces:
me.deecaad.core.file.Serializer<CustomDurability>
public class CustomDurability
extends Object
implements me.deecaad.core.file.Serializer<CustomDurability>
Handles breaking the weapon over a certain number of shots, so weapons do
not last forever.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for serializerCustomDurability(int maxDurability, int minMaxDurability, int loseMaxDurabilityPerRepair, int durabilityPerShot, double chance, org.bukkit.inventory.ItemStack replaceItem, me.deecaad.core.mechanics.Mechanics durabilityMechanics, me.deecaad.core.mechanics.Mechanics breakMechanics, Map<org.bukkit.inventory.ItemStack, Integer> repairItems, int repairPerExp, me.deecaad.core.mechanics.Mechanics repairMechanics, me.deecaad.core.mechanics.Mechanics denyRepairMechanics, boolean repairOnlyBroken) -
Method Summary
Modifier and TypeMethodDescriptionme.deecaad.core.mechanics.Mechanicsdoubleme.deecaad.core.mechanics.Mechanicsme.deecaad.core.mechanics.MechanicsintintintintgetMaxDurability(org.bukkit.inventory.ItemStack item) Returns the maximum possible durability that this item can be repaired up to.intme.deecaad.core.mechanics.Mechanicsintorg.bukkit.inventory.ItemStackstatic booleanisLoseDurability(int level, boolean armor) Factory method to determine whether an item should lose durability based on the given level of theEnchantment.DURABILITY.booleanintmodifyMaxDurability(org.bukkit.inventory.ItemStack item) Shorthand to use the default 'loseMaxDurabilityPerRepair' withmodifyMaxDurability(ItemStack, int).intmodifyMaxDurability(org.bukkit.inventory.ItemStack item, int change) Subtracts from the given weapon's max durability.booleanrepair(org.bukkit.inventory.ItemStack weapon, boolean repairMaxDurability) Fully repairs the given weapon.@NotNull CustomDurabilityserialize(@NotNull me.deecaad.core.file.SerializeData data) voidsetBreakMechanics(me.deecaad.core.mechanics.Mechanics breakMechanics) voidsetChance(double chance) voidsetDenyRepairMechanics(me.deecaad.core.mechanics.Mechanics denyRepairMechanics) voidsetDurabilityMechanics(me.deecaad.core.mechanics.Mechanics durabilityMechanics) voidsetDurabilityPerShot(int durabilityPerShot) voidsetLoseMaxDurabilityPerRepair(int loseMaxDurabilityPerRepair) voidsetMaxDurability(int maxDurability) voidsetMinMaxDurability(int minMaxDurability) voidsetRepairItems(Map<org.bukkit.inventory.ItemStack, Integer> repairItems) voidsetRepairMechanics(me.deecaad.core.mechanics.Mechanics repairMechanics) voidsetRepairOnlyBroken(boolean repairOnlyBroken) voidsetRepairPerExp(int repairPerExp) voidsetReplaceItem(org.bukkit.inventory.ItemStack replaceItem) booleanApplies the durability effects to the given item, as if the item has just been used.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.deecaad.core.file.Serializer
canUsePathTo, getKeyword, getName, getParentKeywords, getWikiLink, letPassThrough, shouldSerialize, tryPathTo, useLater
-
Constructor Details
-
CustomDurability
public CustomDurability()Default constructor for serializer -
CustomDurability
public CustomDurability(int maxDurability, int minMaxDurability, int loseMaxDurabilityPerRepair, int durabilityPerShot, double chance, org.bukkit.inventory.ItemStack replaceItem, me.deecaad.core.mechanics.Mechanics durabilityMechanics, me.deecaad.core.mechanics.Mechanics breakMechanics, Map<org.bukkit.inventory.ItemStack, Integer> repairItems, int repairPerExp, me.deecaad.core.mechanics.Mechanics repairMechanics, me.deecaad.core.mechanics.Mechanics denyRepairMechanics, boolean repairOnlyBroken)
-
-
Method Details
-
getMaxDurability
public int getMaxDurability() -
setMaxDurability
public void setMaxDurability(int maxDurability) -
getMinMaxDurability
public int getMinMaxDurability() -
setMinMaxDurability
public void setMinMaxDurability(int minMaxDurability) -
getLoseMaxDurabilityPerRepair
public int getLoseMaxDurabilityPerRepair() -
setLoseMaxDurabilityPerRepair
public void setLoseMaxDurabilityPerRepair(int loseMaxDurabilityPerRepair) -
getDurabilityPerShot
public int getDurabilityPerShot() -
setDurabilityPerShot
public void setDurabilityPerShot(int durabilityPerShot) -
getChance
public double getChance() -
setChance
public void setChance(double chance) -
getReplaceItem
public org.bukkit.inventory.ItemStack getReplaceItem() -
setReplaceItem
public void setReplaceItem(org.bukkit.inventory.ItemStack replaceItem) -
getDurabilityMechanics
public me.deecaad.core.mechanics.Mechanics getDurabilityMechanics() -
setDurabilityMechanics
public void setDurabilityMechanics(me.deecaad.core.mechanics.Mechanics durabilityMechanics) -
getBreakMechanics
public me.deecaad.core.mechanics.Mechanics getBreakMechanics() -
setBreakMechanics
public void setBreakMechanics(me.deecaad.core.mechanics.Mechanics breakMechanics) -
getRepairItems
-
setRepairItems
-
getRepairPerExp
public int getRepairPerExp() -
setRepairPerExp
public void setRepairPerExp(int repairPerExp) -
getRepairMechanics
public me.deecaad.core.mechanics.Mechanics getRepairMechanics() -
setRepairMechanics
public void setRepairMechanics(me.deecaad.core.mechanics.Mechanics repairMechanics) -
getDenyRepairMechanics
public me.deecaad.core.mechanics.Mechanics getDenyRepairMechanics() -
setDenyRepairMechanics
public void setDenyRepairMechanics(me.deecaad.core.mechanics.Mechanics denyRepairMechanics) -
isRepairOnlyBroken
public boolean isRepairOnlyBroken() -
setRepairOnlyBroken
public void setRepairOnlyBroken(boolean repairOnlyBroken) -
getMaxDurability
public int getMaxDurability(org.bukkit.inventory.ItemStack item) Returns the maximum possible durability that this item can be repaired up to. The more often you repair an item, the less max-durability it has. This prevents users from re-using the same item forever.It is assumed that the given item is a weapon that uses THIS instance of custom durability.
- Parameters:
item- The non-null weapon to check.- Returns:
- The maximum repair durability.
-
modifyMaxDurability
public int modifyMaxDurability(org.bukkit.inventory.ItemStack item) Shorthand to use the default 'loseMaxDurabilityPerRepair' withmodifyMaxDurability(ItemStack, int).- Parameters:
item- The item to modify.- Returns:
- The new max durability (might be negative).
-
modifyMaxDurability
public int modifyMaxDurability(org.bukkit.inventory.ItemStack item, int change) Subtracts from the given weapon's max durability. This method should be called whenever the item is repaired. The item's current durability WILL exceed the max durability, since this subtraction occurs AFTER the item is repaired.- Parameters:
item- The item to modify.change- The amount to subtract from max-durability.- Returns:
- The new max durability (might be negative)
-
use
public boolean use(org.bukkit.entity.LivingEntity entity, org.bukkit.inventory.ItemStack item, String weaponTitle) Applies the durability effects to the given item, as if the item has just been used. It is assumed that the given item is a weapon. If the weapon was broken by this usage, this method will returntrue.- Parameters:
entity- The non-null entity used forMechanics.item- The non-null weapon to lose durability.- Returns:
- true if the item was broken.
-
repair
public boolean repair(org.bukkit.inventory.ItemStack weapon, boolean repairMaxDurability) Fully repairs the given weapon. This method assumes that the given weapon uses this custom durability. You should always manually check if the weapon actually does use custom durability.- Parameters:
weapon- The non-null weapon to repair.repairMaxDurability- true to also repair max-durability.- Returns:
- true if changes were made to the weapon.
- Throws:
IllegalArgumentException- If the weapon has no meta or is null.
-
serialize
@NotNull public @NotNull CustomDurability serialize(@NotNull @NotNull me.deecaad.core.file.SerializeData data) throws me.deecaad.core.file.SerializerException - Specified by:
serializein interfaceme.deecaad.core.file.Serializer<CustomDurability>- Throws:
me.deecaad.core.file.SerializerException
-
isLoseDurability
public static boolean isLoseDurability(int level, boolean armor) Factory method to determine whether an item should lose durability based on the given level of theEnchantment.DURABILITY. For tools/weapons, the chance to lose durability is LOWER then for armor.- Parameters:
level- The unbreaking enchantment level.armor- true if the item is armor.- Returns:
- true if the item should lose durability.
-