summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunfighterJ <joseph.jenniges@gmail.com>2013-04-29 06:31:08 -0500
committerGunfighterJ <joseph.jenniges@gmail.com>2013-04-29 06:31:08 -0500
commit79bdd8a212cc02708755942cb2df96aa765fd4b2 (patch)
treeb481793932a4038fc2f984a9c007db3ddc425926
parent28cbac66104f5053cae6166d1895b6fdb6463330 (diff)
downloadEssentials-79bdd8a212cc02708755942cb2df96aa765fd4b2.tar
Essentials-79bdd8a212cc02708755942cb2df96aa765fd4b2.tar.gz
Essentials-79bdd8a212cc02708755942cb2df96aa765fd4b2.tar.lz
Essentials-79bdd8a212cc02708755942cb2df96aa765fd4b2.tar.xz
Essentials-79bdd8a212cc02708755942cb2df96aa765fd4b2.zip
Add keyword replacements in kits
Add SimpleTextInput constructor for lists Variable refactoring for clarity.
-rw-r--r--Essentials/src/com/earth2me/essentials/Kit.java17
-rw-r--r--Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java8
2 files changed, 19 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java
index 962d8ca25..9bb94555b 100644
--- a/Essentials/src/com/earth2me/essentials/Kit.java
+++ b/Essentials/src/com/earth2me/essentials/Kit.java
@@ -4,6 +4,9 @@ import static com.earth2me.essentials.I18n._;
import static com.earth2me.essentials.I18n.capitalCase;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
+import com.earth2me.essentials.textreader.IText;
+import com.earth2me.essentials.textreader.KeywordReplacer;
+import com.earth2me.essentials.textreader.SimpleTextInput;
import java.util.*;
import java.util.logging.Level;
import org.bukkit.configuration.ConfigurationSection;
@@ -102,24 +105,28 @@ public class Kit
{
try
{
+ IText input = new SimpleTextInput(items);
+ IText output = new KeywordReplacer(input, user, ess);
+
boolean spew = false;
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
- for (String d : items)
- {
- if (d.startsWith(ess.getSettings().getCurrencySymbol()))
+ for (String kitItem : output.getLines())
+ {
+ if (kitItem.startsWith(ess.getSettings().getCurrencySymbol()))
{
- Double value = Double.parseDouble(d.substring(ess.getSettings().getCurrencySymbol().length()).trim());
+ Double value = Double.parseDouble(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
Trade t = new Trade(value, ess);
t.pay(user);
continue;
}
- final String[] parts = d.split(" ");
+ final String[] parts = kitItem.split(" ");
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
final MetaItemStack metaStack = new MetaItemStack(parseStack);
if (parts.length > 2)
{
+ // We pass a null sender here because kits should not do perm checks
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
}
diff --git a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java
index 57e599ff2..b11907faf 100644
--- a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java
+++ b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java
@@ -7,9 +7,15 @@ public class SimpleTextInput implements IText
{
private final transient List<String> lines = new ArrayList<String>();
- public SimpleTextInput (final String input) {
+ public SimpleTextInput (final String input)
+ {
lines.addAll(Arrays.asList(input.split("\\n")));
}
+
+ public SimpleTextInput (final List<String> input)
+ {
+ lines.addAll(input);
+ }
@Override
public List<String> getLines()