diff --git a/Essentials/src/main/java/com/earth2me/essentials/Enchantments.java b/Essentials/src/main/java/com/earth2me/essentials/Enchantments.java index d6e9cf071..6464258f2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Enchantments.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Enchantments.java @@ -334,6 +334,17 @@ public final class Enchantments { private Enchantments() { } + public static String getRealName(final Enchantment enchantment) { + if (enchantment == null) { + return null; + } + + if (isFlat) { // 1.13+ only + return enchantment.getKey().getKey(); + } + return enchantment.getName().toLowerCase(Locale.ENGLISH); + } + public static Enchantment getByName(final String name) { if (name == null || name.isEmpty()) { return null; diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index 7aa45627e..a317b2ff2 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -576,7 +576,7 @@ public class MetaItemStack { if (enchantment == null) { return false; } - if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) { + if (hasMetaPermission(sender, "enchantments." + Enchantments.getRealName(enchantment), false, false, ess)) { int level = -1; if (split.length > 1) { try { @@ -619,7 +619,7 @@ public class MetaItemStack { } } } catch (final Exception ex) { - throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex); + throw new Exception("Enchantment " + Enchantments.getRealName(enchantment) + ": " + ex.getMessage(), ex); } } @@ -629,7 +629,7 @@ public class MetaItemStack { return null; } - final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); + final String enchantmentName = Enchantments.getRealName(enchantment); if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) { throw new TranslatableException("enchantmentPerm", enchantmentName); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandenchant.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandenchant.java index 091ee56a7..3e3c652b1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandenchant.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandenchant.java @@ -14,7 +14,6 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -35,7 +34,7 @@ public class Commandenchant extends EssentialsCommand { if (args.length == 0) { final Set usableEnchants = new TreeSet<>(); for (final Map.Entry entry : Enchantments.entrySet()) { - final String name = entry.getValue().getName().toLowerCase(Locale.ENGLISH); + final String name = Enchantments.getRealName(entry.getValue()); if (usableEnchants.contains(name) || (user.isAuthorized("essentials.enchantments." + name) && entry.getValue().canEnchantItem(stack))) { usableEnchants.add(entry.getKey()); } @@ -57,7 +56,7 @@ public class Commandenchant extends EssentialsCommand { metaStack.addEnchantment(user.getSource(), ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"), enchantment, level); stack.setItemMeta(metaStack.getItemStack().getItemMeta()); user.getBase().updateInventory(); - final String enchantName = enchantment.getName().toLowerCase(Locale.ENGLISH).replace('_', ' '); + final String enchantName = Enchantments.getRealName(enchantment).replace('_', ' '); if (level == 0) { user.sendTl("enchantmentRemoved", enchantName); } else { 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 9b9b72656..79043276d 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.items; +import com.earth2me.essentials.Enchantments; import com.earth2me.essentials.IConf; import com.earth2me.essentials.User; import com.earth2me.essentials.craftbukkit.Inventories; @@ -218,7 +219,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb { if (meta.hasEnchants()) { for (final Enchantment e : meta.getEnchants().keySet()) { - sb.append(e.getName().toLowerCase()).append(":").append(meta.getEnchantLevel(e)).append(" "); + sb.append(Enchantments.getRealName(e)).append(":").append(meta.getEnchantLevel(e)).append(" "); } } @@ -263,7 +264,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb { case ENCHANTED_BOOK: final EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) is.getItemMeta(); for (final Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) { - sb.append(e.getName().toLowerCase()).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" "); + sb.append(Enchantments.getRealName(e)).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" "); } break; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java index 47f29285a..fe6734230 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java @@ -106,7 +106,7 @@ public class SignEnchant extends EssentialsSign { throw new SignException(ex, "errorWithMessage", ex.getMessage()); } - final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); + final String enchantmentName = Enchantments.getRealName(enchantment); if (level == 0) { player.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' ')); } else {