mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Merge pull request #1757 from SupaHam/fix-metaitemstack-keyword-replacer
Allow KeywordReplacer to input replacements with underscore spacers.
This commit is contained in:
commit
1f0f77ff72
3 changed files with 18 additions and 21 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();
|
||||
|
|
|
@ -120,26 +120,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