Op Detection code not working

Discussion in 'Plugin Development' started by Double0negative, Dec 7, 2011.

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

    Double0negative

    Im trying to make it so that we can put the server in "op only" so that one ops can be on the server. For some reason, what seems like pretty straight forward code to me, i cannot get it to work. It just kicks anyone regardless if they are a op or not. The code that im using is

    Code:
        public void toggleOpOnly(boolean b, String msg){
            kickMsg = msg;
            if(opOnly){
                opOnly = false;
            }
            else{
                opOnly = true;
                if(b){
                    Player p[] = this.getServer().getOnlinePlayers();
                    for(int a = 0; a< p.length;a++){
                        if(!p[a].isOp()){
                        p[a].kickPlayer(msg);
                        }
                    }
                }
            }
        }
    
    And when people try to join

    Code:
        public void onPlayerJoin(PlayerJoinEvent event){
                if(opOnly){
                    if(!event.getPlayer().isOp()){
                        event.getPlayer().kickPlayer(kickMsg);
                        say("Kicked player "+event.getPlayer().getDisplayName());
                    }
    
                }
            }
    
     
  2. Does it always kick everyone out? Or only when you toggle the opOnly?

    What does your Bukkit.getPlayer("yourusername").isOp() give you?
     
  3. Offline

    Double0negative

    It kicks everyone when i run toggle op, and then when we a op tries to rejoin it still kicks them along with everyone else. Ill have to try that code when i get home in a few hours, but i have made sure that I am a op
     
  4. Weird... As I see no problems in your code when you use the toggleOpOnly command. (Except that maybe opOnly isn't set. But that doesn't matter because when you use toggleOpOnly they kick ops too. And I can't see why!)

    Edit: To think about it. I really think your not an OP (or at least Bukkit thinks your not one.)
     
  5. Offline

    Double0negative

    Right before i tested the command i ran /op Double0negative and it dd the whole You Are Now Op! thing

    My ops.txt file checks out and everything too

    Code:
    (ops.txt)
    anon232
    double0negative
    curiousdesi
    
     
  6. Offline

    SirTyler

    could be something with capitals, I know that bukkit can be really picky on them sometimes.
     
  7. Offline

    Double0negative

    Possibly, ill be home in about 2.5 hours, ill test it out.
     
  8. Offline

    hatstand

    I did a similar thing:
    This (In my PlayerListener):
    Code:java
    1. public void onPlayerLogin(PlayerLoginEvent e)
    2. {
    3. if(!e.getPlayer().isOp())
    4. {
    5. e.disallow(Result.KICK_OTHER, "Server is offline for maintenance, and will return shortly.");
    6. }
    7. }

    and this (In my onCommand):
    Code:java
    1. for(Player p : getServer().getOnlinePlayers())
    2. {
    3. if(!p.isOp())
    4. {
    5. p.kickPlayer("Server is going down for maintentance.");
    6. }
    7. }

    Work fine for me.
     
    steaks4uce likes this.
  9. Offline

    user_43347

    Best way to do this, the original method is not optimal.
     
Thread Status:
Not open for further replies.

Share This Page