Added data argument to vanilla give command
This commit is contained in:
parent
355c7ba241
commit
f6154042c0
@ -12,14 +12,14 @@ public class GiveCommand extends VanillaCommand {
|
|||||||
public GiveCommand() {
|
public GiveCommand() {
|
||||||
super("give");
|
super("give");
|
||||||
this.description = "Gives the specified player a certain amount of items";
|
this.description = "Gives the specified player a certain amount of items";
|
||||||
this.usageMessage = "/give <player> <item> [amount]";
|
this.usageMessage = "/give <player> <item> [amount [data]]";
|
||||||
this.setPermission("bukkit.command.give");
|
this.setPermission("bukkit.command.give");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||||
if (!testPermission(sender)) return true;
|
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);
|
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -33,6 +33,7 @@ public class GiveCommand extends VanillaCommand {
|
|||||||
Command.broadcastCommandMessage(sender, "Giving " + player.getName() + " some " + material.getId() + " (" + material + ")");
|
Command.broadcastCommandMessage(sender, "Giving " + player.getName() + " some " + material.getId() + " (" + material + ")");
|
||||||
|
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
|
short data = 0;
|
||||||
|
|
||||||
if (args.length >= 3) {
|
if (args.length >= 3) {
|
||||||
try {
|
try {
|
||||||
@ -41,9 +42,14 @@ public class GiveCommand extends VanillaCommand {
|
|||||||
|
|
||||||
if (amount < 1) amount = 1;
|
if (amount < 1) amount = 1;
|
||||||
if (amount > 64) amount = 64;
|
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 {
|
} else {
|
||||||
sender.sendMessage("There's no item called " + args[1]);
|
sender.sendMessage("There's no item called " + args[1]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user