mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Issue fixed
This commit is contained in:
parent
f22960b068
commit
a76bc04386
@ -62,6 +62,6 @@ public class RepairPower extends DoubleStat implements ConsumableItemInteraction
|
||||
}
|
||||
|
||||
// vanilla durability
|
||||
return RepairUtils.repairPower(playerData, target, consumable, repairPower);
|
||||
return RepairUtils.repairPower(playerData, target, consumable, -1, repairPower);
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,6 @@ public class RepairPowerPercent extends DoubleStat implements ConsumableItemInte
|
||||
}
|
||||
|
||||
// vanilla durability
|
||||
return RepairUtils.repairPower(playerData, target, consumable, repairPower);
|
||||
return RepairUtils.repairPower(playerData, target, consumable, repairPower, -1);
|
||||
}
|
||||
}
|
||||
|
@ -25,23 +25,27 @@ public class RepairUtils {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static boolean repairPower(@NotNull PlayerData playerData, @NotNull NBTItem target, @NotNull Consumable consumable, double repairPower) {
|
||||
public static boolean repairPower(@NotNull PlayerData playerData, @NotNull NBTItem target, @NotNull Consumable consumable, double repairPercentage, int repairUses) {
|
||||
final Player player = playerData.getPlayer();
|
||||
if (!target.getBoolean("Unbreakable") && target.getItem().hasItemMeta() && target.getItem().getItemMeta() instanceof Damageable
|
||||
final boolean percentage = repairPercentage > 0;
|
||||
if (!target.getBoolean("Unbreakable")
|
||||
&& target.getItem().hasItemMeta()
|
||||
&& target.getItem().getItemMeta() instanceof Damageable
|
||||
&& ((Damageable) target.getItem().getItemMeta()).getDamage() > 0) {
|
||||
RepairItemEvent called = new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPower);
|
||||
RepairItemEvent called = percentage ? new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairPercentage) : new RepairItemEvent(playerData, consumable.getMMOItem(), target, repairUses);
|
||||
Bukkit.getPluginManager().callEvent(called);
|
||||
if (called.isCancelled())
|
||||
return false;
|
||||
int uses = percentage ? (int) (target.getItem().getType().getMaxDurability() * (repairPercentage / 100)) : repairUses;
|
||||
|
||||
ItemMeta meta = target.getItem().getItemMeta();
|
||||
((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - called.getRepaired()));
|
||||
((Damageable) meta).setDamage(Math.max(0, ((Damageable) meta).getDamage() - uses));
|
||||
target.getItem().setItemMeta(meta);
|
||||
Message.REPAIRED_ITEM.format(ChatColor.YELLOW,
|
||||
"#item#",
|
||||
MMOUtils.getDisplayName(target.getItem()),
|
||||
"#amount#",
|
||||
String.valueOf(called.getRepaired() == -1 ? called.getRepairedPercent() : called.getRepaired()))
|
||||
String.valueOf(uses))
|
||||
.send(player);
|
||||
CustomSoundListener.playConsumableSound(consumable.getItem(), player);
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user