Adds a new check for items with full durability (#4)

This commit is contained in:
2022-10-03 13:03:21 +02:00
parent 5897f68b42
commit 505d6bfb2b
7 changed files with 72 additions and 39 deletions

View File

@ -6,6 +6,7 @@ import net.citizensnpcs.api.util.DataKey;
import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.config.NPCSettings;
import net.knarcraft.blacksmith.manager.EconomyManager;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget;
@ -173,6 +174,11 @@ public class BlacksmithTrait extends Trait {
return;
}
if (ItemHelper.getDamage(hand) == 0) {
sendNPCMessage(this.npc, player, config.getNotDamagedMessage());
return;
}
//Start a new reforge session for the player
_sessionStart = System.currentTimeMillis();
session = new ReforgeSession(this, player, npc, config);

View File

@ -4,6 +4,7 @@ import net.citizensnpcs.api.npc.NPC;
import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.config.NPCSettings;
import net.knarcraft.blacksmith.manager.EconomyManager;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
@ -163,7 +164,7 @@ public class ReforgeSession implements Runnable {
}
// Damage the item
short currentItemDurability = EconomyManager.getDurability(itemToReforge);
short currentItemDurability = ItemHelper.getDurability(itemToReforge);
short newDurability = (short) (currentItemDurability + (currentItemDurability * random.nextInt(8)));
short maxDurability = itemToReforge.getType().getMaxDurability();
if (newDurability <= 0) {