From 02df03a4b14a84a899d5e10aca83bdd6b182e060 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Sat, 27 Apr 2013 23:44:23 -0400 Subject: [CHANGE] Rewrite eco command with better logic :: the command will now attempt to do exactly what it is told, with respect to the minimum balance :: fix missing messages --- .../earth2me/essentials/commands/Commandeco.java | 102 +++++++++------------ Essentials/src/messages.properties | 2 + Essentials/src/messages_cs.properties | 2 + Essentials/src/messages_da.properties | 2 + Essentials/src/messages_de.properties | 2 + Essentials/src/messages_en.properties | 2 + Essentials/src/messages_es.properties | 2 + Essentials/src/messages_fi.properties | 2 + Essentials/src/messages_fr.properties | 2 + Essentials/src/messages_it.properties | 2 + Essentials/src/messages_nl.properties | 2 + Essentials/src/messages_pl.properties | 2 + Essentials/src/messages_pt.properties | 2 + Essentials/src/messages_ro.properties | 2 + Essentials/src/messages_se.properties | 2 + 15 files changed, 73 insertions(+), 57 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index 20ec02644..16cbdbcc3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -19,27 +19,26 @@ public class Commandeco extends EssentialsCommand @Override public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - Double broadcast = null; - Double broadcastAll = null; - final double startingBalance = (double)ess.getSettings().getStartingBalance(); + if (args.length < 2) { throw new NotEnoughArgumentsException(); } - EcoCommands cmd; + Commandeco.EcoCommands cmd; + double startingBalance = (double)ess.getSettings().getStartingBalance(); double amount; + Double broadcast = null; + Double broadcastAll = null; try { - cmd = EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH)); - amount = Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")); + cmd = Commandeco.EcoCommands.valueOf(args[0].toUpperCase(Locale.ENGLISH)); + amount = (cmd == Commandeco.EcoCommands.RESET) ? startingBalance : Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")); } catch (Exception ex) { throw new NotEnoughArgumentsException(ex); } - final double minBalance = ess.getSettings().getMinMoney(); - if (args[1].contentEquals("**")) { for (String sUser : ess.getUserMap().getAllUniqueUsers()) @@ -52,28 +51,13 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (player.canAfford(amount, false)) - { - player.takeMoney(amount); - } - else - { - if (player.getMoney() > 0) - { - player.setMoney(0); - } - } + take(amount, player, null); break; case RESET: - player.setMoney(startingBalance); - broadcastAll = startingBalance; - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); - broadcastAll = underMinimum ? minBalance : amount; + set(amount, player, null); + broadcastAll = amount; break; } } @@ -90,28 +74,13 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (player.canAfford(amount)) - { - player.takeMoney(amount); - } - else - { - if (player.getMoney() > 0) - { - player.setMoney(0); - } - } + take(amount, player, null); break; case RESET: - player.setMoney(startingBalance); - broadcast = startingBalance; - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); - broadcast = underMinimum ? minBalance : amount; + set(amount, player, null); + broadcast = amount; break; } } @@ -126,21 +95,12 @@ public class Commandeco extends EssentialsCommand break; case TAKE: - if (!player.canAfford(amount)) - { - throw new Exception(_("notEnoughMoney")); - - } - player.takeMoney(amount, sender); + take(amount, player, sender); break; case RESET: - player.setMoney(startingBalance); - break; - case SET: - boolean underMinimum = (player.getMoney() - amount) < minBalance; - player.setMoney(underMinimum ? minBalance : amount); + set(amount, player, sender); break; } } @@ -155,9 +115,37 @@ public class Commandeco extends EssentialsCommand } } + private void take(double amount, final User player, final CommandSender sender) + { + double money = player.getMoney(); + double minBalance = ess.getSettings().getMinMoney(); + if (money - amount > minBalance) + { + player.takeMoney(amount, sender); + } + else + { + player.sendMessage(_("takenFromAccount", Util.displayCurrency(money - minBalance, ess))); + sender.sendMessage(_("takenFromOthersAccount", Util.displayCurrency(money - minBalance, ess), player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess))); + player.setMoney(minBalance); + } + } + + private void set(double amount, final User player, final CommandSender sender) + { + double minBalance = ess.getSettings().getMinMoney(); + boolean underMinimum = amount < minBalance; + player.setMoney(underMinimum ? minBalance : amount); + player.sendMessage(_("setBal", Util.displayCurrency(player.getMoney(), ess))); + if (sender != null) + { + sender.sendMessage(_("setBalOthers", player.getDisplayName(), Util.displayCurrency(player.getMoney(), ess))); + } + } + private enum EcoCommands { - GIVE, TAKE, RESET, SET + GIVE, TAKE, SET, RESET } -} +} \ No newline at end of file diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index d0165fa6b..8676ba6da 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs. kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 0bb449ca6..cc833c9ff 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -538,3 +538,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index b103b23fc..9707dc6a9 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. \ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 8c4cdd10e..9e4d5f63b 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index d0165fa6b..8676ba6da 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs. kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index fccd18329..13ec76e11 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 246809d82..d59b7ecb3 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 2c6efe7cd..ab71a4ac5 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index ba415179f..245f1c0de 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index d349d5a80..c8a30dbac 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 8dc5095cf..69fcd2ecf 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Niepoprawny typ pogody cannotStackMob=\u00a74Nie masz uprawnien by stackowac wiele mobow kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index a3af47fcf..1682b521c 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_ro.properties b/Essentials/src/messages_ro.properties index 2f525eeec..e6017bc7c 100644 --- a/Essentials/src/messages_ro.properties +++ b/Essentials/src/messages_ro.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index e41278abd..eae144c40 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -535,3 +535,5 @@ pWeatherInvalidAlias=\u00a74Invalid weather type cannotStackMob=\u00a74You do not have permission to stack multiple mobs kitNotFound=\u00a74That kit does not exist. socialSpy=\u00a76SocialSpy for {0}\u00a76: {1} +setBal=\u00a7aYour balance was set to {0}. +setBalOthers=\u00a7aYou set {0}''s balance to {1}. -- cgit v1.2.3 From 0a0369698339f0d0d8ea82d705366c6df6dd057d Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Sun, 28 Apr 2013 16:23:45 -0400 Subject: [API] Add a warp api, with future 3.x support :: minor cleanup --- Essentials/src/com/earth2me/essentials/I18n.java | 1 + Essentials/src/com/earth2me/essentials/IConf.java | 3 +- .../src/com/earth2me/essentials/IReplyTo.java | 11 +++- Essentials/src/com/earth2me/essentials/Warps.java | 42 ++++++++++++++- .../src/com/earth2me/essentials/api/IWarps.java | 60 ++++++++++++++++++++++ .../essentials/api/InvalidNameException.java | 16 ++++++ 6 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/api/IWarps.java create mode 100644 Essentials/src/com/earth2me/essentials/api/InvalidNameException.java diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index 93f743140..b2ae6a73a 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -43,6 +43,7 @@ public class I18n implements II18n instance = null; } + @Override public Locale getCurrentLocale() { return currentLocale; diff --git a/Essentials/src/com/earth2me/essentials/IConf.java b/Essentials/src/com/earth2me/essentials/IConf.java index a523f8638..600c7ed48 100644 --- a/Essentials/src/com/earth2me/essentials/IConf.java +++ b/Essentials/src/com/earth2me/essentials/IConf.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; -public interface IConf { +public interface IConf +{ public void reloadConfig(); } diff --git a/Essentials/src/com/earth2me/essentials/IReplyTo.java b/Essentials/src/com/earth2me/essentials/IReplyTo.java index 5bef5fced..429fd7584 100644 --- a/Essentials/src/com/earth2me/essentials/IReplyTo.java +++ b/Essentials/src/com/earth2me/essentials/IReplyTo.java @@ -2,8 +2,17 @@ package com.earth2me.essentials; import org.bukkit.command.CommandSender; -public interface IReplyTo { +public interface IReplyTo +{ + /** + * Sets the user to reply to + * @param user + */ public void setReplyTo(CommandSender user); + /** + * Gets the user the sender should reply to + * @return + */ public CommandSender getReplyTo(); } diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index 6c3448f4e..ce1eff83a 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -1,6 +1,8 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.api.InvalidNameException; import com.earth2me.essentials.commands.WarpNotFoundException; import java.io.File; import java.io.IOException; @@ -11,7 +13,7 @@ import org.bukkit.Location; import org.bukkit.Server; -public class Warps implements IConf +public class Warps implements IConf, IWarps { private static final Logger logger = Logger.getLogger("Minecraft"); private final Map warpPoints = new HashMap(); @@ -29,6 +31,7 @@ public class Warps implements IConf reloadConfig(); } + @Override public boolean isEmpty() { return warpPoints.isEmpty(); @@ -45,6 +48,7 @@ public class Warps implements IConf return keys; } + @Override public Location getWarp(String warp) throws Exception { EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp)); @@ -55,6 +59,7 @@ public class Warps implements IConf return conf.getLocation(null, server); } + @Override public void setWarp(String name, Location loc) throws Exception { String filename = Util.sanitizeFileName(name); @@ -126,6 +131,41 @@ public class Warps implements IConf } } + // This is for api support, and so 3.x will not break this api + @Override + public Collection getList() + { + final List keys = new ArrayList(); + for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet()) + { + keys.add(stringIgnoreCase.getString()); + } + Collections.sort(keys, String.CASE_INSENSITIVE_ORDER); + return keys; + } + + // This is for api support, and so 3.x will not break this api + @Override + public void removeWarp(String name) throws Exception + { + EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name)); + if (conf == null) + { + throw new Exception(_("warpNotExist")); + } + if (!conf.getFile().delete()) + { + throw new Exception(_("warpDeleteError")); + } + warpPoints.remove(new StringIgnoreCase(name)); + } + + //This is here for future 3.x api support. Not implemented here becasue storage is handled differently + @Override + public File getWarpFile(String name) throws InvalidNameException + { + throw new UnsupportedOperationException("Not supported yet."); + } private static class StringIgnoreCase { diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java new file mode 100644 index 000000000..8bab07397 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java @@ -0,0 +1,60 @@ +package com.earth2me.essentials.api; + +import java.io.File; +import java.util.Collection; +import org.bukkit.Location; + + +public interface IWarps +{ + /** + * Get a warp by name + * + * @param warp - Warp name + * @return - Location the warp is set to + * @throws Exception + */ + Location getWarp(String warp) throws Exception; + + /** + * Gets a list of warps + * + * @return - A {@link Collection} of warps + */ + Collection getList(); + + /** + * Delete a warp from the warp DB + * + * @param name - Name of warp + * @throws Exception + */ + void removeWarp(String name) throws Exception; + + /** + * Set a warp + * + * @param name - Name of warp + * @param loc - Location of warp + * @throws Exception + */ + void setWarp(String name, Location loc) throws Exception; + + /** + * Check to see if the file is empty + * + * @return + */ + boolean isEmpty(); + + /** + * Get a warp file + * note: this is not yet implemented, as 3.x uses different storage methods + * + * @param name - name of file + * @return - an instance of the file + * @throws InvalidNameException - When the file is not found + */ + File getWarpFile(String name) throws InvalidNameException; + +} diff --git a/Essentials/src/com/earth2me/essentials/api/InvalidNameException.java b/Essentials/src/com/earth2me/essentials/api/InvalidNameException.java new file mode 100644 index 000000000..b62a74ce3 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/InvalidNameException.java @@ -0,0 +1,16 @@ +package com.earth2me.essentials.api; + + +public class InvalidNameException extends Exception +{ + /** + * NOTE: This is not implemented yet, just here for future 3.x api support + * Allow serialization of the InvalidNameException exception + */ + private static final long serialVersionUID = 1485321420293663139L; + + public InvalidNameException(Throwable thrwbl) + { + super(thrwbl); + } +} -- cgit v1.2.3 From 28cbac66104f5053cae6166d1895b6fdb6463330 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Sun, 28 Apr 2013 17:22:11 -0400 Subject: cleanup last commit a bit --- Essentials/src/com/earth2me/essentials/Warps.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index ce1eff83a..39f31369c 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -135,29 +135,14 @@ public class Warps implements IConf, IWarps @Override public Collection getList() { - final List keys = new ArrayList(); - for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet()) - { - keys.add(stringIgnoreCase.getString()); - } - Collections.sort(keys, String.CASE_INSENSITIVE_ORDER); - return keys; + return getWarpNames(); } // This is for api support, and so 3.x will not break this api @Override public void removeWarp(String name) throws Exception { - EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name)); - if (conf == null) - { - throw new Exception(_("warpNotExist")); - } - if (!conf.getFile().delete()) - { - throw new Exception(_("warpDeleteError")); - } - warpPoints.remove(new StringIgnoreCase(name)); + delWarp(name); } //This is here for future 3.x api support. Not implemented here becasue storage is handled differently -- cgit v1.2.3 From 79bdd8a212cc02708755942cb2df96aa765fd4b2 Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Mon, 29 Apr 2013 06:31:08 -0500 Subject: Add keyword replacements in kits Add SimpleTextInput constructor for lists Variable refactoring for clarity. --- Essentials/src/com/earth2me/essentials/Kit.java | 17 ++++++++++++----- .../earth2me/essentials/textreader/SimpleTextInput.java | 8 +++++++- 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 lines = new ArrayList(); - public SimpleTextInput (final String input) { + public SimpleTextInput (final String input) + { lines.addAll(Arrays.asList(input.split("\\n"))); } + + public SimpleTextInput (final List input) + { + lines.addAll(input); + } @Override public List getLines() -- cgit v1.2.3 From 006f996283ac17953bd3c3c78f7ba8d17741f9ae Mon Sep 17 00:00:00 2001 From: GunfighterJ Date: Mon, 29 Apr 2013 14:04:59 -0500 Subject: Remove ArrayListInput Formatting --- Essentials/src/com/earth2me/essentials/Kit.java | 4 +-- .../essentials/commands/Commandbalancetop.java | 4 +-- .../essentials/textreader/ArrayListInput.java | 31 ---------------------- .../essentials/textreader/SimpleTextInput.java | 15 ++++++----- 4 files changed, 13 insertions(+), 41 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/textreader/ArrayListInput.java diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index 9bb94555b..571787384 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -107,11 +107,11 @@ public class Kit { IText input = new SimpleTextInput(items); IText output = new KeywordReplacer(input, user, ess); - + boolean spew = false; final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); for (String kitItem : output.getLines()) - { + { if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) { Double value = Double.parseDouble(kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 8cbf41809..b15071805 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import com.earth2me.essentials.textreader.ArrayListInput; +import com.earth2me.essentials.textreader.SimpleTextInput; import com.earth2me.essentials.textreader.TextPager; import java.text.DateFormat; import java.util.*; @@ -21,7 +21,7 @@ public class Commandbalancetop extends EssentialsCommand } private static final int CACHETIME = 2 * 60 * 1000; public static final int MINUSERS = 50; - private static ArrayListInput cache = new ArrayListInput(); + private static SimpleTextInput cache = new SimpleTextInput(); private static long cacheage = 0; private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); diff --git a/Essentials/src/com/earth2me/essentials/textreader/ArrayListInput.java b/Essentials/src/com/earth2me/essentials/textreader/ArrayListInput.java deleted file mode 100644 index 0da83f3b4..000000000 --- a/Essentials/src/com/earth2me/essentials/textreader/ArrayListInput.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.earth2me.essentials.textreader; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - - -public class ArrayListInput implements IText -{ - private final transient List lines = new ArrayList(); - - @Override - public List getLines() - { - return lines; - } - - @Override - public List getChapters() - { - return Collections.emptyList(); - } - - @Override - public Map getBookmarks() - { - return Collections.emptyMap(); - } - -} diff --git a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java index b11907faf..f15ce6df5 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java +++ b/Essentials/src/com/earth2me/essentials/textreader/SimpleTextInput.java @@ -6,17 +6,21 @@ import java.util.*; public class SimpleTextInput implements IText { private final transient List lines = new ArrayList(); - - public SimpleTextInput (final String input) + + public SimpleTextInput(final String input) { lines.addAll(Arrays.asList(input.split("\\n"))); } - - public SimpleTextInput (final List input) + + public SimpleTextInput(final List input) { lines.addAll(input); } - + + public SimpleTextInput() + { + } + @Override public List getLines() { @@ -34,5 +38,4 @@ public class SimpleTextInput implements IText { return Collections.emptyMap(); } - } -- cgit v1.2.3