Allow multiple kits to be spawned per command.

This commit is contained in:
KHobbits 2014-06-23 00:38:13 +01:00
parent f76a517339
commit 6c7ba6a76f

View file

@ -31,13 +31,13 @@ public class Commandkit extends EssentialsCommand
else if (args.length > 1 && user.isAuthorized("essentials.kit.others")) else if (args.length > 1 && user.isAuthorized("essentials.kit.others"))
{ {
final User userTo = getPlayer(server, user, args, 1); final User userTo = getPlayer(server, user, args, 1);
final String kitName = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); final String kitNames = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim();
giveKit(userTo, user, kitName); giveKits(userTo, user, kitNames);
} }
else else
{ {
final String kitName = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim(); final String kitNames = StringUtil.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim();
giveKit(user, user, kitName); giveKits(user, user, kitNames);
} }
} }
@ -53,8 +53,10 @@ public class Commandkit extends EssentialsCommand
else else
{ {
final User userTo = getPlayer(server, args, 1, true, false); final User userTo = getPlayer(server, args, 1, true, false);
final String kitName = args[0].toLowerCase(Locale.ENGLISH); final String[] kits = args[0].toLowerCase(Locale.ENGLISH).split(",");
for (final String kitName : kits)
{
final Map<String, Object> kit = ess.getSettings().getKit(kitName); final Map<String, Object> kit = ess.getSettings().getKit(kitName);
final List<String> items = Kit.getItems(ess, userTo, kitName, kit); final List<String> items = Kit.getItems(ess, userTo, kitName, kit);
Kit.expandItems(ess, userTo, items); Kit.expandItems(ess, userTo, items);
@ -63,6 +65,21 @@ public class Commandkit extends EssentialsCommand
userTo.sendMessage(tl("kitReceive", kitName)); userTo.sendMessage(tl("kitReceive", kitName));
} }
} }
}
private void giveKits(User userTo, User userFrom, String kitNames) throws Exception
{
if (kitNames.isEmpty())
{
throw new Exception(tl("kitError2"));
}
String[] kits = kitNames.split(",");
for (final String kitName : kits)
{
giveKit(userTo, userFrom, kitName);
}
}
private void giveKit(User userTo, User userFrom, String kitName) throws Exception private void giveKit(User userTo, User userFrom, String kitName) throws Exception
{ {
@ -80,14 +97,19 @@ public class Commandkit extends EssentialsCommand
final List<String> items = Kit.getItems(ess, userTo, kitName, kit); final List<String> items = Kit.getItems(ess, userTo, kitName, kit);
final Trade charge = new Trade("kit-" + kitName, ess); final Trade charge = new Trade("kit-" + kitName, new Trade("kit-kit", ess), ess);
charge.isAffordableFor(userFrom); charge.isAffordableFor(userFrom);
Kit.checkTime(userFrom, kitName, kit); Kit.checkTime(userFrom, kitName, kit);
Kit.expandItems(ess, userTo, items); Kit.expandItems(ess, userTo, items);
charge.charge(userFrom); charge.charge(userFrom);
if (!userFrom.equals(userTo))
{
userFrom.sendMessage(tl("kitGiveTo", kitName, userTo.getDisplayName())); userFrom.sendMessage(tl("kitGiveTo", kitName, userTo.getDisplayName()));
}
userTo.sendMessage(tl("kitReceive", kitName)); userTo.sendMessage(tl("kitReceive", kitName));
} }
} }