mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-04-26 16:39:45 +00:00
Better handle kit item casting.
This commit is contained in:
parent
7fe83dbd91
commit
867bfbf1b8
3 changed files with 23 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue