blob: 156c280986ec7244826a41265578d06630cb3c4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package org.bukkit.command.defaults;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class GiveCommand extends VanillaCommand {
public GiveCommand() {
super("give");
this.description = "Gives the specified player a certain amount of items";
this.usageMessage = "/give <player> <item> [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 > 4)) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player = Bukkit.getPlayerExact(args[0]);
if (player != null) {
Material material = Material.matchMaterial(args[1]);
if (material != null) {
Command.broadcastCommandMessage(sender, "Giving " + player.getName() + " some " + material.getId() + " (" + material + ")");
int amount = 1;
short data = 0;
if (args.length >= 3) {
try {
amount = Integer.parseInt(args[2]);
} catch (NumberFormatException ex) {}
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, data));
} else {
sender.sendMessage("There's no item called " + args[1]);
}
} else {
sender.sendMessage("Can't find user " + args[0]);
}
return true;
}
@Override
public boolean matches(String input) {
return input.startsWith("give ") || input.equalsIgnoreCase("give");
}
}
|