Player.setOp(false) does not work

Discussion in 'Plugin Development' started by MrCreeper, Sep 9, 2011.

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

    MrCreeper

    Hey :)
    That's my code to hook into other plugin commands:
    Code:java
    1.  
    2. Boolean op = user.isOp();
    3. blocked.add(user.getName());
    4. user.chat("/command");
    5. user.setOp(op);
    6. blocked.remove(user.getName());

    It gives a Player op state and executes a command. After executing the op state should switch
    to the original op state, but user.setOp(false) does nothing.

    What's wrong? =/
     
  2. Offline

    desht

    Looks to me like you're trying to run the command before making the call to setOp() ?
     
  3. I'm pretty sure I remember that being fixed in a newer cb build, like 1070 or something. I would look at the commits/changelog for the last couple builds.
     
  4. Offline

    desht

    Good catch - build 1074 fixes it.

    To the OP - if you want your plugin to work with earlier builds, looks like you'll need to call the server config manager directly, e.g.:

    PHP:
    CraftServer cServer = (CraftServer)Bukkit.getServer();
    cServer.getHandle().f(user.getName());   // de-op a player
    The e() and f() methods write the ops.txt file immediately. Unfortunately there's no option to avoid this (for transient op granting like this, it would be better not to write the ops.txt file IMHO). Coincidentally, I've just been working on something similar - check out the grantOpStatus() and revokeOpStatus() methods in https://github.com/desht/ScrollingMenuSign/blob/master/src/me/desht/util/PermissionsUtils.java (credit goes to Edward Hand's original implementation which I borrowed :) ). These two methods grant/revoke ops status without writing the ops.txt file, which has two advantages: 1) less file overhead, 2) more secure since if the server was to crash during the temporary op phase, the player isn't left in the ops.txt file.
     
    tips48 likes this.
  5. Offline

    MrCreeper

    Sorry, pasting mistake,
    there's an "user.setOp(true)" before user.chat(). ^^
    So, it's bukkit's fault? Glad to know, I was already in despair. =D
    I'll use the file writing method until build 1074, it's a more simple transition.
    Thank you guys. =)
     
  6. Offline

    desht

    No problem.

    I should also mention that player.setOp() also writes the ops.txt file immediately - it just calls the e() and/or f() method (at least in 1074+ - in earlier versions, it only calls e()).
     
Thread Status:
Not open for further replies.

Share This Page