Hey, I was looking at some forums and seeing some threads about if everyone is OP. Well, Here it goes. First, we get the online players: Code:java for(Player player:getServer().getOnlinePlayers()) {} Then, we want to check if the player is OP. Code:java for(Player player:getServer().getOnlinePlayers()) {if(player.isOp()) {//do stuff}} Now we create an array list, but wait... this goes BEFORE the online players. Code:java ArrayList<Player> array = new ArrayList<Player>();for(Player player:getServer().getOnlinePlayers()) {if(player.isOp()) {array.add(player.getName());}} Now if the player is OP, it will add them to the array list 'array' And then, count the size compared to the array list size. Code:java ArrayList<Player> array = new ArrayList<Player>();for(Player player:getServer().getOnlinePlayers()) {if(player.isOp()) {array.add(player.getName());}}if(array.size() == getServer().getOnlinePlayers().size()) {//Do stuff if everyone is OP!}else {//Someone isn't OP!} And done! *Reccomend to put this in PlayerJoin, or something. EDIT - Make sure to clear the array list first! I didn't write this in eclipse, so it may have errors, tell me please! Thanks for reading, Cya!
ChipDev Looks nice. I see an interesting way to make an in-game command, something like /oplist since vanilla Minecraft nor Bukkit has that type of command. This has given me some idea c:
ChipDev Bukkit#getOperators() Code:java Bukkit.getOperators().size() == Bukkit.getOnlinePlayers().size() Just cut all your code down to one line!
ChipDev Even if the getOperators() didn't exist, there's no need to make an ArrayList of the operators with the express purpose of checking if everyone is op. For example, why not a method such as this? PHP: public boolean isEveryoneOp() { for(Player p : Bukkit.getOnlinePlayers()) if(!p.isOp()) return false; return true;} No offence, but this is another resource that doesn't really provide any use. I don't mean to get you down or anything, I admire the fact that you want to contribute and help people, but fact is this isn't really helpful. I would advise you to save your efforts and work on something bigger that really will be helpful to someone.
I'm pretty sure this would also not work. The getOperators returns a list of all operators, online and offline. So if you compare this size to the online list, they may not match even if there are only OPs online. getOperators: So really the best method is the one posted by AdamQpzm
RingOfStorms AdamQpzm Ah, I was under the impression that if every OP was online and no one else. Dumb me
true. Don't highlight the next line. I do think, and yes, posting something bad makes me learn, of course.
Is there a correct section for what he posted? From my knowledge (and unfortunately, experience), there is no correct section for such celebration.