Skip to content

Commit

Permalink
Allow KeywordReplacer to input replacements with underscore spacers.
Browse files Browse the repository at this point in the history
Resolves #1725 and provides a less breaking fix for #1722.

----

Revert "Consume everything after lore as lore in MetaItemStack. Fixes #1722."

This reverts commit 5fa2ce7.
  • Loading branch information
SupaHam committed Jan 7, 2018
1 parent fd6717d commit f0bf359
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Essentials/src/com/earth2me/essentials/Kit.java
Expand Up @@ -185,7 +185,7 @@ public void expandItems(final User user) throws Exception {
public void expandItems(final User user, final List<String> 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();
Expand Down
22 changes: 0 additions & 22 deletions Essentials/src/com/earth2me/essentials/MetaItemStack.java
Expand Up @@ -7,8 +7,6 @@
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;
Expand Down Expand Up @@ -119,26 +117,6 @@ public boolean canSpawn(final IEssentials ess) {
}

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)));
Expand Down
Expand Up @@ -32,13 +32,15 @@ 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<KeywordType, Object> keywordCache = new EnumMap<KeywordType, Object>(KeywordType.class);

public KeywordReplacer(final IText input, final CommandSource sender, final IEssentials ess) {
this.input = input;
this.replaced = new ArrayList<String>(this.input.getLines().size());
this.ess = ess;
this.includePrivate = true;
this.replaceSpacesWithUnderscores = false;
replaceKeywords(sender);
}

Expand All @@ -47,6 +49,17 @@ public KeywordReplacer(final IText input, final CommandSource sender, final IEss
this.replaced = new ArrayList<String>(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<String>(this.input.getLines().size());
this.ess = ess;
this.includePrivate = showPrivate;
this.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores;
replaceKeywords(sender);
}

Expand Down Expand Up @@ -266,6 +279,10 @@ private String replaceLine(String line, final String fullMatch, final String[] m
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);
Expand Down

0 comments on commit f0bf359

Please sign in to comment.