From f6154042c03805a811e84a7c34d9bd7a4b010948 Mon Sep 17 00:00:00 2001 From: Tahg Date: Mon, 9 Jan 2012 01:09:36 -0500 Subject: Added data argument to vanilla give command --- src/main/java/org/bukkit/command/defaults/GiveCommand.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/bukkit/command/defaults/GiveCommand.java b/src/main/java/org/bukkit/command/defaults/GiveCommand.java index 62393170..156c2809 100644 --- a/src/main/java/org/bukkit/command/defaults/GiveCommand.java +++ b/src/main/java/org/bukkit/command/defaults/GiveCommand.java @@ -12,14 +12,14 @@ public class GiveCommand extends VanillaCommand { public GiveCommand() { super("give"); this.description = "Gives the specified player a certain amount of items"; - this.usageMessage = "/give [amount]"; + this.usageMessage = "/give [amount [data]]"; this.setPermission("bukkit.command.give"); } @Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; - if ((args.length < 2) || (args.length > 3)) { + if ((args.length < 2) || (args.length > 4)) { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; } @@ -33,6 +33,7 @@ public class GiveCommand extends VanillaCommand { Command.broadcastCommandMessage(sender, "Giving " + player.getName() + " some " + material.getId() + " (" + material + ")"); int amount = 1; + short data = 0; if (args.length >= 3) { try { @@ -41,9 +42,14 @@ public class GiveCommand extends VanillaCommand { if (amount < 1) amount = 1; if (amount > 64) amount = 64; + if (args.length >= 4) { + try { + data = Short.parseShort(args[3]); + } catch (NumberFormatException ex) {} + } } - player.getInventory().addItem(new ItemStack(material, amount)); + player.getInventory().addItem(new ItemStack(material, amount, data)); } else { sender.sendMessage("There's no item called " + args[1]); } -- cgit v1.2.3