diff options
author | KHobbits <rob@khobbits.co.uk> | 2013-05-27 02:25:30 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2013-05-27 02:25:30 +0100 |
commit | 867bfbf1b858b94a61f58e8b1a5a9261f91a7644 (patch) | |
tree | 8e2504868e39b1139636cca21c284c6ad8dd6ce6 | |
parent | 7fe83dbd916858d718dd86b6ecfb4a672abc57e5 (diff) | |
download | Essentials-867bfbf1b858b94a61f58e8b1a5a9261f91a7644.tar Essentials-867bfbf1b858b94a61f58e8b1a5a9261f91a7644.tar.gz Essentials-867bfbf1b858b94a61f58e8b1a5a9261f91a7644.tar.lz Essentials-867bfbf1b858b94a61f58e8b1a5a9261f91a7644.tar.xz Essentials-867bfbf1b858b94a61f58e8b1a5a9261f91a7644.zip |
Better handle kit item casting.
3 files changed, 23 insertions, 16 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index d3ade5a03..b5fd48d5d 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -130,21 +130,35 @@ public class Kit } } - public static List<String> getItems(final User user, final Map<String, Object> kit) throws Exception + public static List<String> getItems(final IEssentials ess, final User user, final Map<String, Object> kit) throws Exception { if (kit == null) { throw new Exception(_("kitNotFound")); } - try { - return (List<String>)kit.get("items"); + final List<String> itemList = new ArrayList<String>(); + final Object kitItems = kit.get("items"); + if (kitItems instanceof List) + { + for (Object item : (List)kitItems) + { + if (item instanceof String) + { + itemList.add(item.toString()); + continue; + } + throw new Exception("Error parsing kit item: " + item.toString()); + } + return itemList; + } + throw new Exception("Error parsing kit: " + kitItems.toString()); } catch (Exception e) { - user.sendMessage(_("kitError2")); - throw new Exception(_("kitErrorHelp"), e); + ess.getLogger().log(Level.WARNING, e.getMessage()); + throw new Exception(_("kitError2"), e); } } @@ -201,14 +215,7 @@ public class Kit catch (Exception e) { user.updateInventory(); - if (ess.getSettings().isDebug()) - { - ess.getLogger().log(Level.WARNING, e.getMessage()); - } - else - { - ess.getLogger().log(Level.WARNING, e.getMessage()); - } + ess.getLogger().log(Level.WARNING, e.getMessage()); throw new Exception(_("kitError2"), e); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 1c9bec8d3..0cbab8cb6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -56,7 +56,7 @@ public class Commandkit extends EssentialsCommand final String kitName = args[0].toLowerCase(Locale.ENGLISH); final Map<String, Object> kit = ess.getSettings().getKit(kitName); - final List<String> items = Kit.getItems(userTo, kit); + final List<String> items = Kit.getItems(ess, userTo, kit); Kit.expandItems(ess, userTo, items); sender.sendMessage(_("kitGiveTo", kitName, userTo.getDisplayName())); @@ -78,7 +78,7 @@ public class Commandkit extends EssentialsCommand throw new Exception(_("noKitPermission", "essentials.kits." + kitName)); } - final List<String> items = Kit.getItems(userTo, kit); + final List<String> items = Kit.getItems(ess, userTo, kit); Kit.checkTime(userFrom, kitName, kit); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignKit.java b/Essentials/src/com/earth2me/essentials/signs/SignKit.java index 391b23407..5616a969c 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignKit.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignKit.java @@ -60,7 +60,7 @@ public class SignKit extends EssentialsSign { final Map<String, Object> kit = ess.getSettings().getKit(kitName); Kit.checkTime(player, kitName, kit); - final List<String> items = Kit.getItems(player, kit); + final List<String> items = Kit.getItems(ess, player, kit); Kit.expandItems(ess, player, items); charge.charge(player); Trade.log("Sign", "Kit", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); |