Get All of a Players Permissions

Discussion in 'Plugin Development' started by Weasel_Squeezer, Jul 31, 2013.

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

    Weasel_Squeezer

    I need to be able to get all of the permissions a player has as Strings so that I can check them and parse the ending digits off of specific permission nodes. I have looked through the source of the permission package in the Bukkit code, and have read the docs well, and still have problems. right now I am using:

    Code:java
    1. public static int getPlayersLimit(Player player, String permission) {
    2. String perm;
    3. for (PermissionAttachmentInfo pio : player.getEffectivePermissions()) {
    4. perm = pio.getPermission();
    5. System.out.println(perm);
    6. if (perm.startsWith(permission)) {
    7. String ending = perm.substring(perm.lastIndexOf("."), perm.length());
    8. if (isNumeric(ending)) {
    9. return Integer.parseInt(ending);
    10. }
    11. }
    12. }
    13. return -1;
    14. }


    This code does printout a list of permissions, but when I add a permission to the specified player or their group, it does not show up in the list that is printed. I have added the permission with PEX commands and in the actual PEX permission file. Why is it not showing up? does the player.getEffectivePermissions() not actually contain all their permissions?

    anyone?

    its almost like the only permissions that are being printed are the ones that have default set to true in plugin.yml. Does anyone know how to get all a players permissions? preferably without using a dependency like vault

    looks like nobody has any idea. I guess I will have to deal with setting a limit to the numbers like maybe 1000, and then iterate through all 1000 numbers till the player has the permission with that number added to the end of the given permission... sigh

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

    xTrollxDudex

    Weasel_Squeezer
    Seriously, you bumped 3 times in less than an hour?

    Anyways what part is not working?
     
  3. Offline

    Weasel_Squeezer

    It's not so much as the code doesn't work as there are no errors, but it's not doing what I would like and that is give me a list of all the permissions a player has so I can iterate through them as strings and do my handling then. This code I posted only gives a list of permissions the player has that are defined in any plugin.yml. I want to have dynamic permissions that an admin can set that has a specific context such as "plugin.limit", and then they can add a number to the end as the limit.
    Now I know you might be thinking that I can create my own limit system with new configuration files and everything which I most definitely can, but that would involve more work for me, and another learning curve for the admin or player. Everyone knows permissions, and permissions can be set dynamically themselves, so that is why I am favoring them.

    One solution that I have kinda just decided to go with because I cannot solve this, is to just have a maximum number the limit or trailing digit on their permission can be, and then I could just loop say 1000 times and see if the player has the permission ("plugin.limit." + i) I have tested this and it is not incredibly inefficient (only 20ms for 1000), but this is bad practice and I would rather not have to do it this way.

    SOO my question was if anyone had any idea of a solution or workaround to this problem? preferably not using extra dependencies such as vault. just bukkit
     
  4. Offline

    xTrollxDudex

    Weasel_Squeezer
    There is no way to actually add a permission directly to the file without some I/O and reloading the permissions plugin; yipou are much better with vault because a)it is persistent and b)it actually adds the permission
     
  5. Offline

    Weasel_Squeezer

    Well I wasn't really talking about adding the permission to the plugin.yml. I don't need to for my purposes. I will just stick with having a limit of the trailing numerical amount on the permission node.
     
  6. Offline

    Tarestudio

    Weasel_Squeezer
    You could try to get all Permissions that where registered to the Server, loop these and check of player has this permission.
     
  7. Offline

    Weasel_Squeezer

    I b
    I believe thats what player.getEffectivePermissions(); does, only for the specific player. My problem is that the permissions I am looking for will not be registered in any plugin.yml. only in Pex or whichever permission handler is being used. This could be solved with vault, but I don't want to do that.
     
  8. Offline

    lycano

    Weasel_Squeezer you should get permissions for users via API of that permission plugin that is used. For that you need something that can detect what permission plugin is used.

    I dont think that many will use "no permission plugin" but if thats important to you ...

    Your problem is that you add stuff to the player itself via BukkitPerms .. that does not work as the permission plugin will most likely not get those changes during runtime. PEX does scan a player permission when they join but thats kinda hacky ... i recommend not using any SuperPerms and stick with a permission manager like pex or groupmanager from essentials.

    Create an interface and describe your methods you use in all implementing classes like

    Code:java
    1.  
    2. public interface PermissionHandler
    3.  
    4. public int getPlayersLimit(Player player, String permission);
    5.  
    6. }
    7.  


    Now create EssentialsPermissionHandler, BukkitPermissionHandler, PexPermissionHandler and implement this interface.

    Define for each what you have to do for that plugin in getPlayerLimit mehtod.

    Now write a method called registerPermissionHandler() .. do check there what plugin is used e.g. PermissionsEx, Essentials ...

    And if nothing found use BukkitPermissionsHandler like

    // in your main plugin class header
    private static PermissionsHandler permHandler;

    // in registerPermissionsHandler method when nothing matches ...
    permHandler = new BukkitPermissionsHandler()

    create a static method that can get permHandler if you need it everywhere and cant pass it. Otherwise remove static and pass that permHandler to that class you need it in.
     
    Weasel_Squeezer likes this.
  9. Offline

    Tarestudio

    Weasel_Squeezer
    If a permission is not registered, its a bad plugin using this permission...
    Have you tried to use player.recalculatePermissions(); before player.getEffectivePermissions();?
     
  10. Offline

    Weasel_Squeezer

    I know I am not using permissions the exact correct way they were intended, an that is because it would be better for me to use permissions to set limits because I would have to write no extra code, and it would be better for the user because they would have to do no extra configuration on my plugin or commands. I'll re-paste what I said above.
    "Now I know you might be thinking that I can create my own limit system with new configuration files and everything which I most definitely can, but that would involve more work for me, and another learning curve for the admin or player. Everyone knows permissions, and permissions can be set dynamically themselves, so that is why I am favoring them."
    I know that you should generally use functionality the way it was meant to be used, but I just feel that this is a better solution for setting limits as it will not effect ANYTHING. Only make things better. using permissions in this way will not break bukkit, or the permission handling plugin. It is simply being creative with permissions, and I think it would be good to do it this way. (I wouldn't even consider it "hacky". It's just creative)

    I am aware of this and know how to do it, but I was specifically talking about the bukkit API. As I now know that permission plugins do not update bukkit perms on runtime, I was favoring a solution using only bukkit as It would be much less code to write. I can do this though, and will probably end up doing it as it is one of the only 'real' solutions. thanks for commenting though!

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

    lycano

    Weasel_Squeezer the thing about bukkit permission is ... its not used that much as its file based and there is no management ingame.

    There are permission plugins available that do make use of superperms and offer such things but then there is the thing again ... bukkit does not offer permission management they offer the architecture that can be used in a plugin.

    Almost any permission plugin not based on SuperPerms ignore bukkitperms completely except pex which at least can read those values ...

    In the end we still end up in having to check what plugin is used for permissions and create our handlers.

    What might help you out: https://forums.bukkit.org/threads/the-ultimate-guide-to-permissions.80291/
     
  12. Offline

    Weasel_Squeezer

    Wait... I use Pex, so player.hasPermission(); has worked for me and I never second guessed it. Does this not work for other permission plugins? I always wondered why people made their own permission handlers checking for the Permission Plugin loaded...
     
  13. Offline

    xTrollxDudex

    Weasel_Squeezer
    PEX is inherently flawed, breaks bukkit. If I were you I would use Vault.
     
  14. Offline

    lycano

    Weasel_Squeezer well, pex does scan for bukkit perms so they are most likely synced but its hacky so i would not depend on it. Use the API of that permission plugin if you want to support it fully.
     
  15. Offline

    Weasel_Squeezer

    Well this is why I was trying to avoid using vault to hook into permissions, because I would have to check for each and every permissions plugin.
     
Thread Status:
Not open for further replies.

Share This Page