From 55074872feaa3d5b226d1f48389733c028d6fbf5 Mon Sep 17 00:00:00 2001 From: md678685 Date: Sun, 23 Dec 2018 23:02:36 +0000 Subject: [PATCH] Add setting to enable item ID recognition on signs Item IDs can now be enabled for existing signs by manually changing a config option, but there is no facility to create new signs with item IDs. --- .../src/com/earth2me/essentials/ISettings.java | 2 ++ .../src/com/earth2me/essentials/Settings.java | 18 +++++++++++++++++- .../essentials/signs/EssentialsSign.java | 15 +++++++++++++-- .../earth2me/essentials/signs/SignTrade.java | 2 +- Essentials/src/config.yml | 5 +++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 37e53519b..91c98b71f 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -320,4 +320,6 @@ public interface ISettings extends IConf { String getItemDbType(); boolean isForceEnableRecipe(); + + boolean allowOldIdSigns(); } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index c11aa7c61..6b5b32826 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -538,7 +538,8 @@ public class Settings implements net.ess3.api.ISettings { isCompassTowardsHomePerm = _isCompassTowardsHomePerm(); isAllowWorldInBroadcastworld = _isAllowWorldInBroadcastworld(); itemDbType = _getItemDbType(); - forceEnableRecipe = config.getBoolean("force-enable-recipe", false); + forceEnableRecipe = _isForceEnableRecipe(); + allowOldIdSigns = _allowOldIdSigns(); } private List itemSpawnBl = new ArrayList(); @@ -1482,8 +1483,23 @@ public class Settings implements net.ess3.api.ISettings { private boolean forceEnableRecipe; // https://github.com/EssentialsX/Essentials/issues/1397 + private boolean _isForceEnableRecipe() { + return config.getBoolean("force-enable-recipe", false); + } + @Override public boolean isForceEnableRecipe() { return forceEnableRecipe; } + + private boolean allowOldIdSigns; + + private boolean _allowOldIdSigns() { + return config.getBoolean("allow-old-id-signs", false); + } + + @Override + public boolean allowOldIdSigns() { + return allowOldIdSigns; + } } diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 19660446a..4cb06b15c 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -309,7 +309,7 @@ public class EssentialsSign { final int amount = getIntegerPositive(getSignText(sign, amountIndex)); return new Trade(amount, ess); } - final ItemStack item = getItemStack(itemType, 1, ess); + final ItemStack item = getItemStack(itemType, 1, true, ess); final int amount = Math.min(getIntegerPositive(getSignText(sign, amountIndex)), item.getType().getMaxStackSize() * player.getBase().getInventory().getSize()); if (item.getType() == Material.AIR || amount < 1) { throw new SignException(tl("moreThanZero")); @@ -346,6 +346,17 @@ public class EssentialsSign { } protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException { + return getItemStack(itemName, quantity, false, ess); + } + + protected final ItemStack getItemStack(final String itemName, final int quantity, final boolean allowId, final IEssentials ess) throws SignException { + if (allowId && ess.getSettings().allowOldIdSigns()) { + final Material newMaterial = ess.getItemDb().getFromLegacy(itemName); + if (newMaterial != null) { + return new ItemStack(newMaterial, quantity); + } + } + try { final ItemStack item = ess.getItemDb().get(itemName); item.setAmount(quantity); @@ -420,7 +431,7 @@ public class EssentialsSign { sign.setLine(index, quantity + " exp"); return new Trade(quantity, ess); } else { - final ItemStack stack = getItemStack(item, quantity, ess); + final ItemStack stack = getItemStack(item, quantity, true, ess); sign.setLine(index, quantity + " " + item); return new Trade(stack, ess); } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 4b8015b5d..c4a61e313 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -237,7 +237,7 @@ public class SignTrade extends EssentialsSign { return new Trade((amountType == AmountType.COST ? stackamount : amount), ess); } else { final int stackamount = getIntegerPositive(split[0]); - final ItemStack item = getItemStack(split[1], stackamount, ess); + final ItemStack item = getItemStack(split[1], stackamount, true, ess); int amount = getInteger(split[2]); if (amountType == AmountType.ROUNDED) { amount -= amount % stackamount; diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index b35c4f9f8..c28cc5fbd 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -322,6 +322,11 @@ enabledSigns: # Lower numbers will reduce the possibility of lag, but may annoy players. sign-use-per-second: 4 +# Allow item IDs on pre-existing signs on 1.13 and above. +# You cannot use item IDs on new signs, but this will allow players to interact with signs that +# were placed before 1.13. +allow-old-id-signs: false + # List of sign names Essentials should not protect. This feature is especially useful when # another plugin provides a sign that EssentialsX provides, but Essentials overrides. # For example, if a plugin provides a [kit] sign, and you wish to use theirs instead of