[Basic] If everyone on the server is OP

Discussion in 'Resources' started by ChipDev, Nov 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ChipDev

    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
    1. for(Player player:getServer().getOnlinePlayers()) {
    2. }

    Then, we want to check if the player is OP.
    Code:java
    1. for(Player player:getServer().getOnlinePlayers()) {
    2. if(player.isOp()) {
    3. //do stuff
    4. }
    5. }

    Now we create an array list, but wait... this goes BEFORE the online players.
    Code:java
    1. ArrayList<Player> array = new ArrayList<Player>();
    2. for(Player player:getServer().getOnlinePlayers()) {
    3. if(player.isOp()) {
    4. array.add(player.getName());
    5. }
    6. }

    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
    1. ArrayList<Player> array = new ArrayList<Player>();
    2. for(Player player:getServer().getOnlinePlayers()) {
    3. if(player.isOp()) {
    4. array.add(player.getName());
    5. }
    6. }
    7. if(array.size() == getServer().getOnlinePlayers().size()) {
    8. //Do stuff if everyone is OP!
    9. }
    10. else {
    11. //Someone isn't OP!
    12. }

    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!
     
  2. Offline

    Googlelover1234

    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 likes this.
  3. Offline

    ChipDev

    Great! :D
     
  4. Offline

    teej107

    ChipDev
    Bukkit#getOperators()
    Code:java
    1. Bukkit.getOperators().size() == Bukkit.getOnlinePlayers().size()

    Just cut all your code down to one line!
     
  5. Offline

    ChipDev

    This is how it works,
    And that's a method? Wow.. I guess I'm bad with my methods >.<
     
  6. Offline

    xTrollxDudex

    Halp im get eror sais dat i get too 3
     
    rbrick, Cirno and teej107 like this.
  7. 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. :)
     
  8. Offline

    ChipDev

    Ahh... another unuseful post. nuuuu
     
  9. Offline

    RingOfStorms

    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:
    [​IMG]

    So really the best method is the one posted by AdamQpzm
     
    teej107 and AdamQpzm like this.
  10. Offline

    teej107

    RingOfStorms AdamQpzm Ah, I was under the impression that if every OP was online and no one else. Dumb me :p
     
    AdamQpzm likes this.
  11. Offline

    ChipDev

    We'll, if ALL operators are on at the same time, no one else..
     
  12. Offline

    DevRosemberg

    aaaaaaaandddd, same as always, think before posting.
     
    number1_Master, teej107 and AdamQpzm like this.
  13. Offline

    ChipDev

    true.
    Don't highlight the next line.
    I do think, and yes, posting something bad makes me learn, of course.
     
  14. Offline

    DevRosemberg

    YESSS REACHED 200 LIKES
     
  15. Offline

    ChipDev

    good for you.
    wrong.. section..
    wrong... post......
     
  16. Is there a correct section for what he posted? From my knowledge (and unfortunately, experience), there is no correct section for such celebration.
     
  17. Offline

    ChipDev

    *I mean my that, his own profile.
    or Offtopic
     
Thread Status:
Not open for further replies.

Share This Page