Code: if(cmd.getName().equalsIgnoreCase("impeach")){ Bukkit.broadcastMessage(ChatColor.RED + sender.getName() + " has voted to impeach the King!"); }
Maybe make a list for ints, and when ever the command is used, add 1 to the int. Then when a player uses the command, check if the ints > allowed. If so, do X to the user
Rather than storing an int, I'd make a HashSet of the Players that have voted and check it's length, never adding the same player more than once.
Awesome! I've quit a few projects because I don't know how to limit users to doing a command 1 time. This is great!
Code: List<String> impeachers = new ArrayList<String>(); if(cmd.getName().equalsIgnoreCase("impeach")){ if(sender instanceof player){ int counter=0; Player p=(Player)sender; final String username=p.getName(); if(!impeachers.contains(username)){ Bukkit.broadcastMessage(ChatColor.RED + sender.getName() + " has voted to impeach the King!"); impeachers.add(username); counter++; }else{ p.sendMessage("You have already voted to impeach the king."); } } } Put the list right under the start of the class. Then use if(counter>=5).... to remove the king.
Actually, now that I'm looking at it again, HashSets don't allow for duplicate values, so you wouldn't even have to check if a Player is already in it. You would just add the player and check the length, if it was the same player they wouldn't be added again.
You definitely don't want to use an ArrayList for this. ArrayLists store indexes and aren't nearly as efficient as HashSet, especially considering you don't need to know the order and wouldn't have to check contains(player) in this situation.
Just because it's only 5 values is no reason to make it less efficient... Code: HashSet<Player> impeachers = new HashSet<Player>(); if(cmd.getName().equalsIgnoreCase("impeach") && sender instanceof Player){ if (impeachers.add((Player)sender)){ Bukkit.broadcastMessage(ChatColor.RED + ((Player)sender).getName() + " has voted to impeach the King!"); if (impeachers.size() >= 5){ //Do whatever } } }