Any better way of doing this?

Discussion in 'Plugin Development' started by GeorgeeeHD, Apr 23, 2014.

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

    GeorgeeeHD

    Basically I need to run a command as if the player had the permission, but not actually giving them the permission. This is the code, it works but is there a better way?

    Code:java
    1. public void runAsOperator(Player p, String command) {
    2. p.setOp(true);
    3. p.performCommand(command);
    4. p.setOp(false);
    5. }
     
  2. Offline

    killerman747

    You could run a it as a console command?
    Code:java
    1. getServer().dispatchCommand(getServer().getConsoleSender, "your command");
     
  3. Setting a player as operator does not always give them enough permissions to run a command.
    I think the console option is the best one, if you don't want to add or remove any permissions.
     
  4. Offline

    GeorgeeeHD

    killerman747
    Laekh

    Would that run it as if the player typed it though? Because that's what I need.
     
  5. Offline

    killerman747

    GeorgeeeHD
    You might be able to change the sender of the command to the player? Havnt tried it but it might work.
     
  6. What you can do is make sure the command issued can be targeted towards a player.
    If, for example, that command would be /kill, instead of that, it could let it issue the console command /kill (pname)
     
  7. Offline

    Tehmaker

    Code:
    getServer().dispatchCommand(sender, "command in here");
    
    Would run it from the player.
     
  8. Offline

    GeorgeeeHD

    not as if they are op'ed though.
     
  9. Offline

    Tehmaker

    Edit: I would go use the Vault api: https://github.com/MilkBowl/Vault

    It is compatible with most permissions plugins, but essentially, you would still be giving the player the permission. If your way works, it will do.
     
  10. Offline

    coasterman10

    I think you could temporarily give the player a PermissionAttachment allowing that command and then remove it, though I have heard they can cause conflicts. Worth trying though.
     
Thread Status:
Not open for further replies.

Share This Page