New ingame command syntax: /kit <kit> <playername>

New Permission: essentials.kit.others - allows giving kits to other people.
New console commands: /kit & /kit <kit> <playername>
This commit is contained in:
KHobbits 2012-04-07 03:34:01 +01:00
parent 7a6368a980
commit fe95cfe03b
3 changed files with 67 additions and 30 deletions

View File

@ -23,7 +23,7 @@ public class Kit
final StringBuilder list = new StringBuilder(); final StringBuilder list = new StringBuilder();
for (String kiteItem : kits.getKeys(false)) 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)); list.append(" ").append(capitalCase(kiteItem));
} }

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.*;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import java.util.*; import java.util.*;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender;
public class Commandkit extends EssentialsCommand public class Commandkit extends EssentialsCommand
@ -18,39 +19,75 @@ public class Commandkit extends EssentialsCommand
{ {
if (args.length < 1) if (args.length < 1)
{ {
final String kitList = Kit.listKits(ess, user); listKits(user);
if (kitList.length() > 0)
{
user.sendMessage(_("kits", kitList));
}
else
{
user.sendMessage(_("noKits"));
}
throw new NoChargeException(); 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 else
{ {
final String kitName = args[0].toLowerCase(Locale.ENGLISH); final String kitName = args[0].toLowerCase(Locale.ENGLISH);
final Map<String, Object> kit = ess.getSettings().getKit(kitName); giveKit(user, user, kitName);
if (!user.isAuthorized("essentials.kit." + kitName))
{
throw new Exception(_("noKitPermission", "essentials.kit." + kitName));
}
final List<String> 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));
} }
} }
@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<String, Object> kit = ess.getSettings().getKit(kitName);
final List<String> 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<String, Object> kit = ess.getSettings().getKit(kitName);
if (!userFrom.isAuthorized("essentials.kit." + kitName))
{
throw new Exception(_("noKitPermission", "essentials.kit." + kitName));
}
final List<String> 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));
}
} }

View File

@ -180,7 +180,7 @@ commands:
aliases: [ekickall] aliases: [ekickall]
kit: kit:
description: Obtains the specified kit or views all available kits. description: Obtains the specified kit or views all available kits.
usage: /<command> [kit] usage: /<command> [kit] [player]
aliases: [ekit,kits,ekits] aliases: [ekit,kits,ekits]
kill: kill:
description: Kills specified player. description: Kills specified player.