Two things: 1. Why did you add a for loop that only ever has one iteration? It's completely unnecessary. 2. The way you threw on that extra curly brace to the end of the file makes me cringe. You should always keep your code indented properly, otherwise you'll make stupid mistakes.
A couple of things to add to nisovin's list. No need to cast sender to a Player, just use sender.sendMessage. If you want the command to only be usable by a player, do an instanceof check on the sender and send a message to the sender if they aren't a player. Yours will result in an exception if the command is used from the server console or something else. Should return true if the command is a valid command. Why add 1 to the return of Random.nextInt? Just use 0 and 1 instead of 1 and 2. Should create the Random instance as a class instance instead of a method instance. Could use a switch or ternary operator instead of an if/elseif. Code:JAVA private Random random = new Random(); public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (label.equalsIgnoreCase("flip")) { if (sender instanceof Player) { String output = null; switch (this.random.nextInt(2)) { case 0: output = ChatColor.RED + "HEADS!"; break; case 1: output = ChatColor.GOLD + "TAILS!"; break; } if (output != null) { // Just in case sender.sendMessage(output); } } else { sender.sendMessage("This command can only be used by a player."); } return true; } return false;}
Hey man just wanted to say thank you for contributing this, it helped me out with my project greatly (sorta unrelated). Thanks