Fixed realistic weapon damage on 1.13-

This commit is contained in:
Lilac 2019-09-13 22:45:03 +01:00
parent a7cd1e6ffc
commit 61e120c3ca
2 changed files with 5 additions and 10 deletions

View File

@ -4,7 +4,7 @@ stages:
variables: variables:
name: "UltimateStacker" name: "UltimateStacker"
path: "/builds/$CI_PROJECT_PATH" path: "/builds/$CI_PROJECT_PATH"
version: "1.10.6" version: "1.10.7"
build: build:
stage: build stage: build

View File

@ -115,20 +115,18 @@ public class DeathListeners implements Listener {
if (Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && Settings.REALISTIC_DAMAGE.getBoolean()) { if (Settings.KILL_WHOLE_STACK_ON_DEATH.getBoolean() && Settings.REALISTIC_DAMAGE.getBoolean()) {
Player player = (Player) event.getDamager(); Player player = (Player) event.getDamager();
ItemStack tool = player.getInventory().getItemInHand(); ItemStack tool = player.getInventory().getItemInHand();
if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().isUnbreakable() if (tool.getType().getMaxDurability() < 1 || (tool.getItemMeta() != null && (tool.getItemMeta().spigot().isUnbreakable()
|| (ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER) && tool.getItemMeta().spigot().isUnbreakable())))) || (ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER) && tool.getItemMeta().spigot().isUnbreakable()))))
return; return;
int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY); int unbreakingLevel = tool.getEnchantmentLevel(Enchantment.DURABILITY);
Damageable damageable = (Damageable) tool.getItemMeta();
int actualDamage = 0; int actualDamage = 0;
for (int i = 0; i < stack.getAmount(); i++) for (int i = 0; i < stack.getAmount(); i++)
if (checkUnbreakingChance(unbreakingLevel)) if (checkUnbreakingChance(unbreakingLevel))
actualDamage++; actualDamage++;
damageable.setDamage(damageable.getDamage() + actualDamage-1); tool.setDurability((short)(tool.getDurability() + actualDamage));
tool.setItemMeta((ItemMeta) damageable);
if (!this.hasEnoughDurability(tool, 1)) if (!this.hasEnoughDurability(tool, 1))
player.getInventory().setItemInHand(null); player.getInventory().setItemInHand(null);
@ -137,12 +135,9 @@ public class DeathListeners implements Listener {
} }
public boolean hasEnoughDurability(ItemStack tool, int requiredAmount) { public boolean hasEnoughDurability(ItemStack tool, int requiredAmount) {
if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable) || tool.getType().getMaxDurability() < 1) if (tool.getType().getMaxDurability() <= 1)
return true; return true;
return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability();
Damageable damageable = (Damageable) tool.getItemMeta();
int durabilityRemaining = tool.getType().getMaxDurability() - damageable.getDamage();
return durabilityRemaining > requiredAmount;
} }
public boolean checkUnbreakingChance(int level) { public boolean checkUnbreakingChance(int level) {