Question regarding player.chat()

Discussion in 'Plugin Development' started by Icculus, Mar 5, 2015.

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

    Icculus

    Hi,

    I am trying to figure out a way to allow players to be able to issue commands which are really calling commands from other mods behind the scenes, the problem is that they would not have normal access to use those commands. That probably sounds more confusing than I mean so I'll explain with a quick example.

    Suppose I want to add a load_cannon command to a plugin where the load_cannon command
    behind the scenes calls the 'schematic load cannon_schematic' and then the 'paste' commands from the WorldEdit mod.

    I believe that if I use player.chat() to accomplish this the players would still be subject to their permissions, which would not normally include the schematic load or paste commands, so what would be the best approach to solve this?

    Thank you for any help you can provide,
    Andy

    I think I found the answer using the WorldEdit API... If anyone has a suggestion for an easier approach I'd love to hear it, but this looks doable.

    Thanks

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Mar 5, 2015
  2. Offline

    timtower Administrator Administrator Moderator

    @Icculus I think that you are talking about plugins, not mods. Right?
    And server.dispatchCommand(commandsender, command)
     
  3. Offline

    pie_flavor

    @Icculus I get it. and @timtower he wants them to have access to the commands even if they wouldn't otherwise.
    Icculus wat you can do is get all the registered commands. check if the player has each one. If he doesn't, save it to a list or hashmap and give him the permission. Then call what timtower said, then remove all the permissions from the player that are in the list. If you haven't worked with player permissions before then you say PermissionAttachment attach = player.addAttachment(plugin); and use PermissionAttachment#setPermission(true) to give and setPermission(false) to take away, then just use attach.remove() to clear it.
     
  4. Offline

    Icculus

    I did try dispatchCommand() but it also used the same permissions ...
     
  5. Offline

    timtower Administrator Administrator Moderator

    @Icculus Then you need to add the permission, fire the command, remove the permission like @pie_flavor said.
     
  6. Offline

    Icculus

    How do I determine the name of the permission to use? Basically I want to grant permission for the player to use the //schematic load command and the //paste command but I am new to permissions in general and am unsure of how to determine which permissions to use with addAttachment.

    Edit:

    I toggled on pex debug status for my test user to see which permissions appeared and saw a LONG list of permissions such as:
    checked for "worldedit.limit.unrestricted", no permission found
    checked for "worldedit.tool.lrbuild", no permission found
    ...
    checked for "worldedit.clipboard.paste", no permission found

    So I tried adding the following to add permissions temporarily:
    me.addAttachment(this, "worldedit.*", true);

    But it did not have any effect. Any help would be greatly appreciated!

    Thank you!
    -Andy

    I never could get addAttachment to work, however I was able to use a dispatchCommand to have pex grant the user permissions, then performCommand, then use pex again to remove the permissions... Not the most graceful solution but until I can figure out why addAttachment wasn't working it'll have to do.

    Thanks,
    Andy

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    Icculus

    Yep, I have looked at it. I have tried setting things up the way they were presented in the wiki as well as other examples I have found from the forums but it never seemed to add the proper permissions. One question I have is do I use the current plugin for addAttachment (eg player.addAttachment(this) ) or do I use the worldedit plugin which is where the commands come from that I want to set permissions for (//schematic and //paste) - I believe I tried both and neither one worked but it'd still be helpful to know the answer to that question. Thanks.
     
  8. @Icculus Remember that you need to tahg us so we know you responded. :)
    Anyway, that isn't the way I would add permissions to a player. The Wiki says to create a PermissionAttachment,
    Code:
    PermissionAttachment attachment = player.addAttachment(plugin);
    Then you need to define what permission you want to add and if you want them to have it or not.
    Code:
    attachment.setPermission("worldedit.*", true);
    If you want to remove a player's permission, then you would do,
    Code:
    attachment.unsetPermission("worldedit.*");
    Hope that cleared things up a little. :)
     
Thread Status:
Not open for further replies.

Share This Page