mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 05:01:28 +00:00
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 5fa2ce7d9e
.
This commit is contained in:
parent
fd6717d06d
commit
f0bf359df3
3 changed files with 18 additions and 23 deletions
|
@ -185,7 +185,7 @@ public class Kit {
|
|||
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();
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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<KeywordType, Object> keywordCache = new EnumMap<KeywordType, Object>(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<String>(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<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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue