mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-09-30 00:27:26 +02:00
Add keyword replacements in kits
Add SimpleTextInput constructor for lists Variable refactoring for clarity.
This commit is contained in:
parent
28cbac6610
commit
79bdd8a212
@ -4,6 +4,9 @@ import static com.earth2me.essentials.I18n._;
|
|||||||
import static com.earth2me.essentials.I18n.capitalCase;
|
import static com.earth2me.essentials.I18n.capitalCase;
|
||||||
import com.earth2me.essentials.commands.NoChargeException;
|
import com.earth2me.essentials.commands.NoChargeException;
|
||||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
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.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -102,24 +105,28 @@ public class Kit
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
IText input = new SimpleTextInput(items);
|
||||||
|
IText output = new KeywordReplacer(input, user, ess);
|
||||||
|
|
||||||
boolean spew = false;
|
boolean spew = false;
|
||||||
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
|
||||||
for (String d : items)
|
for (String kitItem : output.getLines())
|
||||||
{
|
{
|
||||||
if (d.startsWith(ess.getSettings().getCurrencySymbol()))
|
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);
|
Trade t = new Trade(value, ess);
|
||||||
t.pay(user);
|
t.pay(user);
|
||||||
continue;
|
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 ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||||
final MetaItemStack metaStack = new MetaItemStack(parseStack);
|
final MetaItemStack metaStack = new MetaItemStack(parseStack);
|
||||||
|
|
||||||
if (parts.length > 2)
|
if (parts.length > 2)
|
||||||
{
|
{
|
||||||
|
// We pass a null sender here because kits should not do perm checks
|
||||||
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
|
metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,10 +7,16 @@ public class SimpleTextInput implements IText
|
|||||||
{
|
{
|
||||||
private final transient List<String> lines = new ArrayList<String>();
|
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")));
|
lines.addAll(Arrays.asList(input.split("\\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SimpleTextInput (final List<String> input)
|
||||||
|
{
|
||||||
|
lines.addAll(input);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getLines()
|
public List<String> getLines()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user