From 1c7c7d926e323ec856d2854cddfb47771d711940 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Tue, 29 Oct 2013 17:12:37 +0100 Subject: [PATCH] Fix the /csgive command --- .../java/com/Acrobot/ChestShop/Commands/Give.java | 14 +++++++++----- src/main/resources/plugin.yml | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Commands/Give.java b/src/main/java/com/Acrobot/ChestShop/Commands/Give.java index d6fb678..2b04411 100644 --- a/src/main/java/com/Acrobot/ChestShop/Commands/Give.java +++ b/src/main/java/com/Acrobot/ChestShop/Commands/Give.java @@ -21,13 +21,17 @@ public class Give implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 1) { + return false; + } + Player receiver = (sender instanceof Player ? (Player) sender : null); int quantity = 1; List disregardedIndexes = new ArrayList(); if (args.length > 1) { - for (int index = args.length - 1; index > 0; ++index) { + for (int index = args.length - 1; index >= 0; --index) { Player target = Bukkit.getPlayer(args[index]); if (target == null) { @@ -39,8 +43,8 @@ public class Give implements CommandExecutor { break; } - for (int index = args.length - 1; index > 0; ++index) { - if (!NumberUtil.isInteger(args[index]) && Integer.parseInt(args[index]) > 0) { + for (int index = args.length - 1; index >= 0; --index) { + if (!NumberUtil.isInteger(args[index]) || Integer.parseInt(args[index]) < 0) { continue; } @@ -58,7 +62,7 @@ public class Give implements CommandExecutor { ItemStack item = getItem(args, disregardedIndexes); - if (item == null) { + if (MaterialUtil.isEmpty(item)) { sender.sendMessage(Messages.prefix(Messages.INCORRECT_ITEM_ID)); return true; } @@ -68,7 +72,7 @@ public class Give implements CommandExecutor { sender.sendMessage(Messages.prefix(Messages.ITEM_GIVEN .replace("%item", MaterialUtil.getName(item)) - .replace("player", receiver.getName()))); + .replace("%player", receiver.getName()))); return true; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6b1e33a..89a7184 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -27,7 +27,7 @@ commands: csGive: aliases: [give] description: Gives an item to the appropriate player - usage: / (player) (amount) + usage: / (amount) (player) permission: ChestShop.admin csVersion: aliases: [chestshop]