From fe95cfe03bdc294bbb0c2b205d07cbb5ceead8f6 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 7 Apr 2012 03:34:01 +0100 Subject: [PATCH] New ingame command syntax: /kit New Permission: essentials.kit.others - allows giving kits to other people. New console commands: /kit & /kit --- .../src/com/earth2me/essentials/Kit.java | 2 +- .../essentials/commands/Commandkit.java | 93 +++++++++++++------ Essentials/src/plugin.yml | 2 +- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Kit.java b/Essentials/src/com/earth2me/essentials/Kit.java index b6363b183..5edd40776 100644 --- a/Essentials/src/com/earth2me/essentials/Kit.java +++ b/Essentials/src/com/earth2me/essentials/Kit.java @@ -23,7 +23,7 @@ public class Kit final StringBuilder list = new StringBuilder(); for (String kiteItem : kits.getKeys(false)) { - if (user.isAuthorized("essentials.kit." + kiteItem.toLowerCase(Locale.ENGLISH))) + if (user == null || user.isAuthorized("essentials.kit." + kiteItem.toLowerCase(Locale.ENGLISH))) { list.append(" ").append(capitalCase(kiteItem)); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 67f0fafd0..514a5acca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.*; import static com.earth2me.essentials.I18n._; import java.util.*; import org.bukkit.Server; +import org.bukkit.command.CommandSender; public class Commandkit extends EssentialsCommand @@ -18,39 +19,75 @@ public class Commandkit extends EssentialsCommand { if (args.length < 1) { - final String kitList = Kit.listKits(ess, user); - if (kitList.length() > 0) - { - user.sendMessage(_("kits", kitList)); - } - else - { - user.sendMessage(_("noKits")); - } + listKits(user); throw new NoChargeException(); } + else if (args.length > 1 && user.isAuthorized("essentials.kit.others")) + { + final User userTo = getPlayer(server, args, 1, true); + final String kitName = args[0].toLowerCase(Locale.ENGLISH); + giveKit(userTo, user, kitName); + } else { final String kitName = args[0].toLowerCase(Locale.ENGLISH); - final Map kit = ess.getSettings().getKit(kitName); - - if (!user.isAuthorized("essentials.kit." + kitName)) - { - throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); - } - - final List items = Kit.getItems(user, kit); - - Kit.checkTime(user, kitName, kit); - - final Trade charge = new Trade("kit-" + kitName, ess); - charge.isAffordableFor(user); - - Kit.expandItems(ess, user, items); - - charge.charge(user); - user.sendMessage(_("kitGive", kitName)); - + giveKit(user, user, kitName); } } + + @Override + public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception + { + if (args.length < 2) + { + listKits(sender); + throw new NoChargeException(); + } + else + { + final User userTo = getPlayer(server, args, 1, true); + final String kitName = args[0].toLowerCase(Locale.ENGLISH); + + final Map kit = ess.getSettings().getKit(kitName); + final List items = Kit.getItems(userTo, kit); + Kit.expandItems(ess, userTo, items); + + sender.sendMessage(_("kitGive", kitName)); + } + } + + private void listKits(CommandSender sender) throws Exception + { + final String kitList = Kit.listKits(ess, null); + if (kitList.length() > 0) + { + sender.sendMessage(_("kits", kitList)); + } + else + { + sender.sendMessage(_("noKits")); + } + } + + private void giveKit(User userTo, User userFrom, String kitName) throws Exception + { + final Map kit = ess.getSettings().getKit(kitName); + + if (!userFrom.isAuthorized("essentials.kit." + kitName)) + { + throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); + } + + final List items = Kit.getItems(userTo, kit); + + Kit.checkTime(userFrom, kitName, kit); + + final Trade charge = new Trade("kit-" + kitName, ess); + charge.isAffordableFor(userFrom); + + Kit.expandItems(ess, userTo, items); + + charge.charge(userFrom); + userTo.sendMessage(_("kitGive", kitName)); + } } diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 459dec26f..3e1dc52c0 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -180,7 +180,7 @@ commands: aliases: [ekickall] kit: description: Obtains the specified kit or views all available kits. - usage: / [kit] + usage: / [kit] [player] aliases: [ekit,kits,ekits] kill: description: Kills specified player.