diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index 015eb03f1..d1edb3e02 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -210,7 +210,7 @@ public class MetaItemStack { final boolean value = split.length <= 1 || Boolean.parseBoolean(split[1]); setUnbreakable(ess, stack, value); } else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && hasMetaPermission(sender, "head", false, true, ess)) { - if (MaterialUtil.isPlayerHead(stack.getType(), stack.getDurability())) { + if (MaterialUtil.isPlayerHead(stack)) { final String owner = split[1]; setSkullOwner(ess, stack, owner); } else { diff --git a/Essentials/src/main/java/com/earth2me/essentials/Trade.java b/Essentials/src/main/java/com/earth2me/essentials/Trade.java index 94da5c9f2..aa595a0ba 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Trade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Trade.java @@ -3,6 +3,7 @@ package com.earth2me.essentials; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.SetExpFix; import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; import net.ess3.api.IUser; import net.ess3.api.MaxMoneyException; @@ -95,8 +96,10 @@ public class Trade { } else { if (charge.getItemStack() != null) { sb.append(charge.getItemStack().getAmount()).append(","); - sb.append(charge.getItemStack().getType().toString()).append(","); - sb.append(charge.getItemStack().getDurability()); + sb.append(charge.getItemStack().getType()).append(","); + if (VersionUtil.PRE_FLATTENING) { + sb.append(charge.getItemStack().getDurability()); + } } if (charge.getMoney() != null) { sb.append(charge.getMoney()).append(","); @@ -119,8 +122,10 @@ public class Trade { } else { if (pay.getItemStack() != null) { sb.append(pay.getItemStack().getAmount()).append(","); - sb.append(pay.getItemStack().getType().toString()).append(","); - sb.append(pay.getItemStack().getDurability()); + sb.append(pay.getItemStack().getType()).append(","); + if (VersionUtil.PRE_FLATTENING) { + sb.append(pay.getItemStack().getDurability()); + } } if (pay.getMoney() != null) { sb.append(pay.getMoney()).append(","); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index af075539b..596268dc4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -319,7 +319,7 @@ public class User extends UserData implements Comparable, IMessageRecipien if (isAuthorized("essentials.itemspawn.item-all") || isAuthorized("essentials.itemspawn.item-" + name)) return true; - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { final int id = material.getId(); if (isAuthorized("essentials.itemspawn.item-" + id)) return true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Worth.java b/Essentials/src/main/java/com/earth2me/essentials/Worth.java index f8c4af03b..1e8ca1107 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Worth.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Worth.java @@ -30,13 +30,15 @@ public class Worth implements IConf { * @return The price from the config. */ public BigDecimal getPrice(final IEssentials ess, final ItemStack itemStack) { - BigDecimal result; + BigDecimal result = BigDecimal.ONE.negate(); final String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); - // Check for matches with data value from stack - // Note that we always default to BigDecimal.ONE.negate(), equivalent to -1 - result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate()); + if (VersionUtil.PRE_FLATTENING) { + // Check for matches with data value from stack + // Note that we always default to BigDecimal.ONE.negate(), equivalent to -1 + result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate()); + } // Check for matches with data value 0 if (result.signum() < 0) { @@ -140,7 +142,7 @@ public class Worth implements IConf { String path = "worth." + itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); // Spigot 1.13+ throws an exception if a 1.13+ plugin even *attempts* to do set data. - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01) && itemStack.getType().getData() == null) { + if (VersionUtil.PRE_FLATTENING && itemStack.getType().getData() == null) { // Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0. path = path + "." + itemStack.getDurability(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandclearinventory.java index 65d49d44f..2f98a21bd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandclearinventory.java @@ -130,7 +130,7 @@ public class Commandclearinventory extends EssentialsCommand { } else { for (final Item item : items) { final ItemStack stack = new ItemStack(item.getMaterial()); - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { stack.setDurability(item.getData()); } // amount -1 means all items will be cleared diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java index 7fd64cb20..d6c869e47 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade.OverflowType; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.MaxMoneyException; import org.bukkit.Material; import org.bukkit.Server; @@ -161,8 +162,7 @@ public class Commandcondense extends EssentialsCommand { iter.remove(); continue; } - - if (inputSlot.getDurability() == Short.MAX_VALUE) { + if (VersionUtil.PRE_FLATTENING && inputSlot.getDurability() == Short.MAX_VALUE) { inputSlot.setDurability((short) 0); } if (!inputSlot.isSimilar(stack)) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgive.java index 58310a1a2..981bd7cc8 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgive.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.MetaItemStack; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.utils.NumberUtil; +import com.earth2me.essentials.utils.VersionUtil; import com.google.common.collect.Lists; import org.bukkit.Material; import org.bukkit.Server; @@ -37,7 +38,7 @@ public class Commandgive extends EssentialsLoopCommand { } try { - if (args.length > 3 && NumberUtil.isInt(args[2]) && NumberUtil.isInt(args[3])) { + if (args.length > 3 && VersionUtil.PRE_FLATTENING && NumberUtil.isInt(args[2]) && NumberUtil.isInt(args[3])) { stack.setAmount(Integer.parseInt(args[2])); stack.setDurability(Short.parseShort(args[3])); } else if (args.length > 2 && Integer.parseInt(args[2]) > 0) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java index ba6ceeb3f..e2c2a778e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commanditemdb.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.utils.VersionUtil; import org.bukkit.Material; @@ -36,7 +37,7 @@ public class Commanditemdb extends EssentialsCommand { String itemId = "none"; - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { itemId = itemStack.getType().getId() + ":" + itemStack.getDurability(); } @@ -49,7 +50,7 @@ public class Commanditemdb extends EssentialsCommand { if (itemHeld && itemStack.getType() != Material.AIR) { final int maxuses = itemStack.getType().getMaxDurability(); - final int durability = (maxuses + 1) - itemStack.getDurability(); + final int durability = (maxuses + 1) - MaterialUtil.getDamage(itemStack); if (maxuses != 0) { sender.sendMessage(tl("durability", Integer.toString(durability))); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index 3e4dcb487..4daba50dd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -117,7 +117,7 @@ public class Commandrecipe extends EssentialsCommand { if (item == null) { continue; } - if (item.getDurability() == Short.MAX_VALUE) { + if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) { item.setDurability((short) 0); } view.getTopInventory().setItem(j * 3 + k + 1, item); @@ -159,7 +159,7 @@ public class Commandrecipe extends EssentialsCommand { final InventoryView view = user.getBase().openWorkbench(null, true); for (int i = 0; i < ingredients.size(); i++) { final ItemStack item = ingredients.get(i); - if (item.getDurability() == Short.MAX_VALUE) { + if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) { item.setDurability((short) 0); } view.setItem(i + 1, item); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrepair.java index 252a23036..834e7a3bc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrepair.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.utils.VersionUtil; import com.google.common.collect.Lists; @@ -39,7 +40,7 @@ public class Commandrepair extends EssentialsCommand { public void repairHand(final User user) throws Exception { final ItemStack item = user.getItemInHand(); - if (item == null || item.getType().isBlock() || item.getDurability() == 0) { + if (item == null || item.getType().isBlock() || MaterialUtil.getDamage(item) == 0) { throw new Exception(tl("repairInvalidType")); } @@ -81,16 +82,16 @@ public class Commandrepair extends EssentialsCommand { throw new Exception(tl("repairInvalidType")); } - if (item.getDurability() == 0) { + if (MaterialUtil.getDamage(item) == 0) { throw new Exception(tl("repairAlreadyFixed")); } - item.setDurability((short) 0); + MaterialUtil.setDamage(item, 0); } - private void repairItems(final ItemStack[] items, final IUser user, final List repaired) throws Exception { + private void repairItems(final ItemStack[] items, final IUser user, final List repaired) { for (final ItemStack item : items) { - if (item == null || item.getType().isBlock() || item.getDurability() == 0) { + if (item == null || item.getType().isBlock() || MaterialUtil.getDamage(item) == 0) { continue; } @@ -123,7 +124,7 @@ public class Commandrepair extends EssentialsCommand { private Trade getCharge(final Material material) { final String itemName = material.toString().toLowerCase(Locale.ENGLISH); - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { final int itemId = material.getId(); return new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + itemId, new Trade("repair-item", ess), ess), ess); } else { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrest.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrest.java index 451371972..c59179aaa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrest.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrest.java @@ -19,7 +19,7 @@ public class Commandrest extends EssentialsLoopCommand { @Override public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { sender.sendMessage(tl("unsupportedFeature")); return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java index 07b9aac8c..af5d3a20a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java @@ -42,7 +42,7 @@ public class Commandskull extends EssentialsCommand { final SkullMeta metaSkull; boolean spawn = false; - if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull.getType(), itemSkull.getDurability())) { + if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull)) { metaSkull = (SkullMeta) itemSkull.getItemMeta(); } else if (user.isAuthorized("essentials.skull.spawn")) { itemSkull = new ItemStack(SKULL_ITEM, 1, (byte) 3); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java index 4df511d90..b8cca0db2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandworth.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.collect.Lists; import org.bukkit.Server; @@ -87,7 +88,7 @@ public class Commandworth extends EssentialsCommand { } final BigDecimal result = worth.multiply(BigDecimal.valueOf(amount)); - sender.sendMessage(is.getDurability() != 0 ? tl("worthMeta", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), is.getDurability(), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)) : tl("worth", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); + sender.sendMessage(MaterialUtil.getDamage(is) != 0 ? tl("worthMeta", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), MaterialUtil.getDamage(is), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)) : tl("worth", is.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess))); return result; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java index 2e8c7e0b4..4feb311c1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -23,6 +23,7 @@ import org.bukkit.inventory.meta.FireworkEffectMeta; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.plugin.Plugin; import org.bukkit.potion.Potion; @@ -279,12 +280,22 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb { serializeEffectMeta(sb, fireworkEffectMeta.getEffect()); } } else if (MaterialUtil.isPotion(material)) { - final Potion potion = Potion.fromDamage(is.getDurability()); - for (final PotionEffect e : potion.getEffects()) { - // long but needs to be effect:speed power:2 duration:120 in that order. - sb.append("splash:").append(potion.isSplash()).append(" ").append("effect:").append(e.getType().getName().toLowerCase()).append(" ").append("power:").append(e.getAmplifier()).append(" ").append("duration:").append(e.getDuration() / 20).append(" "); + final boolean splash; + final Collection effects; + if (VersionUtil.PRE_FLATTENING) { + final Potion potion = Potion.fromDamage(is.getDurability()); + splash = potion.isSplash(); + effects = potion.getEffects(); + } else { + splash = is.getType() == Material.SPLASH_POTION; + effects = ((PotionMeta) is.getItemMeta()).getCustomEffects(); } - } else if (MaterialUtil.isPlayerHead(material, is.getData().getData())) { + + for (final PotionEffect e : effects) { + // long but needs to be effect:speed power:2 duration:120 in that order. + sb.append("splash:").append(splash).append(" ").append("effect:").append(e.getType().getName().toLowerCase()).append(" ").append("power:").append(e.getAmplifier()).append(" ").append("duration:").append(e.getDuration() / 20).append(" "); + } + } else if (MaterialUtil.isPlayerHead(is)) { // item stack with meta final SkullMeta skullMeta = (SkullMeta) is.getItemMeta(); if (skullMeta != null && skullMeta.hasOwner()) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignTrade.java index d6e5fe4e3..2af7b759b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignTrade.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.Trade.OverflowType; import com.earth2me.essentials.Trade.TradeType; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.MaterialUtil; import com.earth2me.essentials.utils.NumberUtil; import net.ess3.api.IEssentials; import net.ess3.api.MaxMoneyException; @@ -83,7 +84,7 @@ public class SignTrade extends EssentialsSign { private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException { final Trade trade = getTrade(sign, 2, AmountType.COST, false, true, ess); - if (trade.getItemStack() != null && player.getBase().getItemInHand() != null && trade.getItemStack().getType() == player.getBase().getItemInHand().getType() && trade.getItemStack().getDurability() == player.getBase().getItemInHand().getDurability() && trade.getItemStack().getEnchantments().equals(player.getBase().getItemInHand().getEnchantments())) { + if (trade.getItemStack() != null && player.getBase().getItemInHand() != null && trade.getItemStack().getType() == player.getBase().getItemInHand().getType() && MaterialUtil.getDamage(trade.getItemStack()) == MaterialUtil.getDamage(player.getBase().getItemInHand()) && trade.getItemStack().getEnchantments().equals(player.getBase().getItemInHand().getEnchantments())) { final int amount = trade.getItemStack().getAmount(); if (player.getBase().getInventory().containsAtLeast(trade.getItemStack(), amount)) { final ItemStack stack = player.getBase().getItemInHand().clone(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java index b418d568b..31a76f230 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.utils; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import org.bukkit.material.MaterialData; import java.lang.reflect.InvocationTargetException; @@ -11,7 +13,6 @@ import java.util.EnumSet; import java.util.Set; public final class MaterialUtil { - public static final Material SPAWNER = EnumUtil.getMaterial("MOB_SPAWNER", "SPAWNER"); private static final Set BEDS; private static final Set BANNERS; @@ -129,20 +130,12 @@ public final class MaterialUtil { return LEATHER_ARMOR.contains(material); } - public static boolean isMobHead(final Material material, final int durability) { - if (MOB_HEADS.contains(material)) { + public static boolean isPlayerHead(final ItemStack stack) { + if (PLAYER_HEADS.contains(stack.getType())) { return true; } - return LEGACY_SKULLS.contains(material) && (durability != 3); - } - - public static boolean isPlayerHead(final Material material, final int durability) { - if (PLAYER_HEADS.contains(material)) { - return true; - } - - return LEGACY_SKULLS.contains(material) && durability == 3; + return VersionUtil.PRE_FLATTENING && LEGACY_SKULLS.contains(stack.getType()) && stack.getDurability() == 3; } public static boolean isPotion(final Material material) { @@ -166,13 +159,35 @@ public final class MaterialUtil { } public static boolean isSkull(final Material material) { - return isPlayerHead(material, -1) || isMobHead(material, -1); + return PLAYER_HEADS.contains(material) || LEGACY_SKULLS.contains(material); } public static boolean isAir(final Material material) { return material == Material.AIR || (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01) && material.isAir()); } + public static int getDamage(final ItemStack stack) { + if (VersionUtil.PRE_FLATTENING) { + return stack.getDurability(); + } + if (stack.getItemMeta() instanceof Damageable) { + return ((Damageable) stack.getItemMeta()).getDamage(); + } + return 0; + } + + public static void setDamage(final ItemStack stack, final int damage) { + if (VersionUtil.PRE_FLATTENING) { + stack.setDurability((short) damage); + } else { + if (stack.getItemMeta() instanceof Damageable) { + final Damageable damageable = (Damageable) stack.getItemMeta(); + damageable.setDamage(damage); + stack.setItemMeta(damageable); + } + } + } + public static Material convertFromLegacy(final int id, final byte damage) { for (final Material material : EnumSet.allOf(Material.class)) { if (material.getId() == id) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java index 710e7a172..d9e4f9c02 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java @@ -38,6 +38,8 @@ public final class VersionUtil { private static final Set supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_1_R01); + public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01); + private static final Map unsupportedServerClasses; static { diff --git a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index 97f0b7675..07f47153a 100644 --- a/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/main/java/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -69,7 +69,23 @@ public class EssentialsAntiBuildListener implements Listener { } return false; } - return metaPermCheck(user, action, block.getType(), block.getData()); + if (VersionUtil.PRE_FLATTENING) { + return metaPermCheck(user, action, block.getType(), block.getData()); + } + return metaPermCheck(user, action, block.getType()); + } + + private boolean metaPermCheck(final User user, final String action, final ItemStack item) { + if (item == null) { + if (ess.getSettings().isDebug()) { + logger.log(Level.INFO, "AntiBuild permission check failed, invalid item."); + } + return false; + } + if (VersionUtil.PRE_FLATTENING) { + return metaPermCheck(user, action, item.getType(), item.getDurability()); + } + return metaPermCheck(user, action, item.getType()); } public boolean metaPermCheck(final User user, final String action, final Material material) { @@ -81,7 +97,7 @@ public class EssentialsAntiBuildListener implements Listener { final String blockPerm = "essentials.build." + action + "." + material; final String dataPerm = blockPerm + ":" + data; - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) { + if (VersionUtil.PRE_FLATTENING) { if (user.getBase().isPermissionSet(dataPerm)) { return user.isAuthorized(dataPerm); } else { @@ -322,7 +338,7 @@ public class EssentialsAntiBuildListener implements Listener { } if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { - if (event.hasItem() && !metaPermCheck(user, "interact", item.getType(), item.getDurability())) { + if (event.hasItem() && !metaPermCheck(user, "interact", item)) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { user.sendMessage(tl("antiBuildUse", item.getType().toString())); @@ -347,7 +363,7 @@ public class EssentialsAntiBuildListener implements Listener { final ItemStack item = event.getRecipe().getResult(); if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { - if (!metaPermCheck(user, "craft", item.getType(), item.getDurability())) { + if (!metaPermCheck(user, "craft", item)) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) { user.sendMessage(tl("antiBuildCraft", item.getType().toString())); @@ -364,7 +380,7 @@ public class EssentialsAntiBuildListener implements Listener { final ItemStack item = event.getItemDrop().getItemStack(); if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { - if (!metaPermCheck(user, "drop", item.getType(), item.getDurability())) { + if (!metaPermCheck(user, "drop", item)) { event.setCancelled(true); user.getBase().updateInventory(); if (ess.getSettings().warnOnBuildDisallow()) { @@ -391,7 +407,7 @@ public class EssentialsAntiBuildListener implements Listener { final ItemStack item = event.getItem().getItemStack(); if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { - if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) { + if (!metaPermCheck(user, "pickup", item)) { event.setCancelled(true); } } @@ -406,7 +422,7 @@ public class EssentialsAntiBuildListener implements Listener { final ItemStack item = event.getItem().getItemStack(); if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild()) { - if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) { + if (!metaPermCheck(user, "pickup", item)) { event.setCancelled(true); } }