Player.performCommand without the permission?

Discussion in 'Plugin Development' started by twinflyer, Oct 24, 2011.

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

    twinflyer

    Hey everybody

    At the moment I'm creating a plugin, which allows admins to run commands for other players
    The target-player should perform the command, even if he hasn't the permissions.
    Is there another way than opping and deopping this player before/after the player.performCommand?

    twinflyer
    sorry if my writing sucks....I'm writing on a TabletComputer :p
     
  2. Offline

    coldandtired

    Just give the player the permission, do the action, and then take the permission away again.
     
  3. Offline

    Snwspeckle

    How do you apply the permissions. I setup the permissions in the yml and it still says bukkit is sad etc.
     
  4. Offline

    coldandtired

    It all depends on your permissions manager. In Permissions3 it would be something like
    Code:
    permissionsManager.addUserPermission()
    I believe.
     
  5. DONT use permissions 3. You have to attach a permission to the player (player.attachPermission() I think)
     
  6. Offline

    twinflyer

    Would be OK :D
    But how do I get the permission I need?
     
  7. Offline

    coldandtired

    If you're talking about permissions for your own commands you decide what they are. If you mean permissions for anyone else's plugin I don't think it's possible. You might be able to read the plugin.yml file and find what permissions are needed for what command but that's only if the developer put it there.
     
  8. Offline

    desht

    Even that might not be enough, since plugins commonly use subcommands (e.g. /command subcommand args ...), and subcommands don't get listed in plugin.yml.

    To the OP:

    The best to achieve this is to require a superperms-compatible plugin be used, then you can use player.attachPermission() to give the player the nodes he needs, run the command, and then use player.removeAttachment() to take the nodes away again.

    And I'd strongly advise using try/finally to ensure that player.removeAttachment() always gets run, otherwise any command that causes an exception to be thrown will leave the player with permissions he shouldn't have.

    You could also temporarily grant the player op status if the commands being run are from a plugin which doesn't understand superperms, but care should obviously be taken with this. The try/finally thing applies there too, of course.

    Finally, if you really want to support non-superperms permissions plugins, then you need to go read up on those plugins and write code to use each of their APIs separately. Have fun with that.
     
  9. Offline

    twinflyer

    hmmm...
    I just found commsnd signs. But I didn't find how this problem is sloved there.

    twinflyer
     
  10. Offline

    desht

    The new CommandSigns (v1.2) does it like I described above, as does my own ScrollingMenuSign plugin. player.addAttachment().
     
Thread Status:
Not open for further replies.

Share This Page