-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlayerRandom
36 lines (20 loc) · 1014 Bytes
/
PlayerRandom
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
public class PlayerRandom implements Listener {
onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "[" + ChatColor.GOLD + "-" + ChatColor.RED + "] " + ChatColor.BLUE + "Please use " + ChatColor.DARK_BLUE + "/p r");
}
else if (args.length == 1) {
if (label.equalsIgnoreCase("p")) {
if (args[0].equalsIgnoreCase("r")) {
int i = new Random.nextInt(getServer().getOnlinePlayers().length);
Player p = getServer().getOnlinePlayers()[i];
p.getInventory().addItem(new ItemStack(Material.DIAMOND, 5));
bukkit.broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "+" + ChatColor.RED + "] " + ChatColor.BLUE + p + ChatColor.DARK_BLUE + " was randomly chosen and has received 5 diamonds!");
p.sendMessage(ChatColor.LIGHT_GRAY + "5 diamonds were added to your inventory!");
}
return false;
}
}
}