Add and remove * permissions to/from a player

Discussion in 'Plugin Development' started by FunnyItsElmo, Apr 17, 2014.

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


    How can i add all permissions to a player and also remove them here is my current code but it seems not to work.
    PermissionAttachment attachment = player.addAttachment(BukkitSystem.getPlugin());
    attachment.setPermission("*", true);
    and also i have no idea how i can remove all permissions form a player. has somebody an idea?



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


  3. I am not entirely sure what exactly you want to reach and why, so here some text:

    Short version: If you really want to catch all, even unregistered permissions and permissions of which one does not know if it's actually good to add them instead of negating (e.g. pointlessessentials.suicideonjoin), then you clearly need "hacks", in terms of overriding some internals (see PermissionsEx code for Permissible/PermissionAttachment, not entirely sure right now which one).
    Long version: below.

    Using "no hacks" will be an incomplete solution...

    There is no concept of "all permissions" in Bukkit.

    If you consider the fact that not all plugins either specify their permissions in the plugin.yml, nor do do they register all permissions at startup, then how would having "unknown permissions" even work?

    Some plugins use permissions based on player names or region names, which probably can't even be known beforehand.

    The permissions plugins that provide a "*" permission usually use hacks to provide those, for that they implement their own classes for permission lookup and inject those somehow (don't ask me the details, but with a '*' permission they would return true always on a query, unless they have overriding individual permissions and it actually is overridden).

    Another big question is.... which "all" permissions do you want to add to a player? Sometimes there are permissions that are meant to exclude each other, i.e. either should be false for the plugin functioning right, or permissions that are harmful directly or indirectly, so in general it should not be recommended having all permissions. I personally prefer to use permissions such, that adding a permission should not cause direct harm, so it's "admin-safe" to have all, but others do other things, probably with a good reasoning.

    Probably shouldn't forget to add the allperms permission to the PluginManager.(Edit: copy and paste fail)

    So my suggestion is to actually define an extra permission group in a permissions plugin and add "all needed" permissions one by one, nowadays some plugins have shortcut permissions, so it is not that hard anymore - a little more work, certainly.

    Pro (no hacks used):
    An alternative could be to add all permissions to the player, which have OP or true as permission-default - unfortunately some that use false, are missing.

    You could still do the somewhat clean thing to schedule a task to execute after plugins are initialized and define a new Permission(....) named "allperms", and add it as parent permission of all permissions that you can get hold of with default set to true. Then you add that "allperms" permission to a player to grant as much as reasonable. A configurable list of permissions to add anyway and maybe logging a list of skipped permissions (due to false default value), could be a fancy but still clean addition.

    PluginManager.getPermissions() allows getting all permissions, though i am not entirely sure if there really are all child permissions inside, or if one has to walk through their child permissions recursively - i assume all are in there, but it's subject to testing, maybe the API docs help, but don't bet on it. I am also not sure if all command-permissions are inside, so to blow it up a little one could get all plugins, then for each plugin get the commands from the description file and check if they have a permission and add it, if not already done - but really that's a little bit up to experimenting.

    One could go a step further and create some heuristic about which permissions with a default "false" would be addable as "true" by default - but that's already fishy.

    Edit: Probably shouldn't forget to add the allperms permission to the PluginManager.

    So all in all adding all op permissions without being op, probably also does not make all that much of sense, because one could be op instead, though the double book keeping with op and permissions files is a reason to not use both. Effectiveness depends on how many of your plugins actually use op-defaults or register their permissions at all. Nice add-ons like blacklist/whitelist extra permissions could be useful, default configs for certain typical plugins could be a selling argument.

    Peculiar topic. This touches what i did not mention above - if you are writing a plugin that is supposed to be the only permission plugin, then you can do all this, however Bukkit is not fit for having plugins override each others permissions, you can not reliably negate a permission that another plugin has added explicitly, unless you mess with the PermissionAttachment(s) of the other plugin, leading to potential consistency-trouble and even worse.

    Assume your plugin is the only one, you would do the same as adding all permissions, create a permission "noperms" and set it as parent of all permissions that you can get hold of (really all in this case), but this time with a "false" default value.

    Also add the noperms permission to the PluginManager.
  4. Offline


    Could you not make console run the command? If its on an event you could do something like this.

    1. this.getServer().dispatchCommand(getServer().getConsoleSender(), "pex user" + event.getName() + "add *");

    Then you could do

    1. this.getServer().dispatchCommand(getServer().getConsoleSender(), "pex user" + event.getName() + "remove *");

    to remove it?
Thread Status:
Not open for further replies.

Share This Page