From f0bf359df366f8e26d63f3c015fa5b7614778df6 Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Sun, 7 Jan 2018 01:21:19 +0000 Subject: [PATCH] Allow KeywordReplacer to input replacements with underscore spacers. Resolves #1725 and provides a less breaking fix for #1722. ---- Revert "Consume everything after lore as lore in MetaItemStack. Fixes #1722." This reverts commit 5fa2ce7d9e2a51e760055298901bebb1f8c1e0ee. --- .../src/com/earth2me/essentials/Kit.java | 2 +- .../earth2me/essentials/MetaItemStack.java | 22 ------------------- .../textreader/KeywordReplacer.java | 17 ++++++++++++++ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 3bc9d2d44..aac3323e5 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -185,7 +185,7 @@ public class Kit { public void expandItems(final User user, final List items) throws Exception { try { IText input = new SimpleTextInput(items); - IText output = new KeywordReplacer(input, user.getSource(), ess); + IText output = new KeywordReplacer(input, user.getSource(), ess, true, true); boolean spew = false; final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); diff --git a/Essentials/src/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/com/earth2me/essentials/MetaItemStack.java index 26e5a4d1a..dbe30cfde 100644 --- a/Essentials/src/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/com/earth2me/essentials/MetaItemStack.java @@ -7,8 +7,6 @@ import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.base.Joiner; import net.ess3.api.IEssentials; - -import org.apache.commons.lang.ArrayUtils; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; @@ -119,26 +117,6 @@ public class MetaItemStack { } public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, String[] string, int fromArg, final IEssentials ess) throws Exception { - // Make any entries after lore definition become the lore and not parsed. - { - int loreIndex = -1; - boolean dirty = false; - for (int i = 0; i < string.length; i++) { - String _str = string[i]; - if (loreIndex == -1) { - if (_str.matches("^lore" + splitPattern.pattern() + ".*")) { - loreIndex = i; - } - } else { - string[loreIndex] += " " + string[i]; - string[i] = null; - dirty = true; - } - } - if (dirty) { - string = (String[]) ArrayUtils.subarray(string, 0, loreIndex + 1); - } - } if (string[fromArg].startsWith("{") && hasMetaPermission(sender, "vanilla", false, true, ess)) { try { stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length))); diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 8c304c2c9..2a1ed4cae 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -32,6 +32,7 @@ public class KeywordReplacer implements IText { private final transient IEssentials ess; private final transient boolean includePrivate; private transient ExecuteTimer execTimer; + private final transient boolean replaceSpacesWithUnderscores; private final EnumMap keywordCache = new EnumMap(KeywordType.class); public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess) { @@ -39,6 +40,7 @@ public class KeywordReplacer implements IText { this.replaced = new ArrayList(this.input.getLines().size()); this.ess = ess; this.includePrivate = true; + this.replaceSpacesWithUnderscores = false; replaceKeywords(sender); } @@ -47,6 +49,17 @@ public class KeywordReplacer implements IText { this.replaced = new ArrayList(this.input.getLines().size()); this.ess = ess; this.includePrivate = showPrivate; + this.replaceSpacesWithUnderscores = false; + replaceKeywords(sender); + } + + public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess, final boolean showPrivate, + boolean replaceSpacesWithUnderscores) { + this.input = input; + this.replaced = new ArrayList(this.input.getLines().size()); + this.ess = ess; + this.includePrivate = showPrivate; + this.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores; replaceKeywords(sender); } @@ -266,6 +279,10 @@ public class KeywordReplacer implements IText { break; } + if (this.replaceSpacesWithUnderscores) { + replacer = replacer.replaceAll("\\s", "_"); + } + //If this is just a regular keyword, lets throw it into the cache if (validKeyword.getType().equals(KeywordCachable.CACHEABLE)) { keywordCache.put(validKeyword, replacer);