Getting the integer at the end of a permission node?

Discussion in 'Plugin Development' started by Jayjay110, Jun 9, 2011.

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

    Jayjay110

    I cant figure out how to do it, I need it because in my plugin it checks to see the maximum of a number that a user can have, but the number is set out like so, myplugin.amount.<numberhere>
     
  2. Get the node as a string, then split it by the '.' and then parse your 3rd string of the split to an int.
     
  3. Offline

    Jayjay110

    like how exactly? String a = "myplugin.amount."?
     
  4. Offline

    CaiusTSM

    splitting a string puts it into a array of strings try this:
    Code:
    int value = Integer.parseInt(node.split(".")[2]);
    for example if node were a string "myplugin.amount.2"
    node.split(".")[2] would be 2
     
  5. Offline

    Dark_Balor

    I think what he ask is HOW get the string.

    Because you only do something like hasPerm(player, node). He ask how to know what's node the player has.

    I'm wondering the same question ...
     
    Jayjay110 likes this.
  6. Offline

    Paah

    split is based on regex and "." is special character so you need to escape it with \, but \ is also special character so you need double escape.

    "\\."
     
  7. Offline

    CaiusTSM

    oh sorry forgot that:)
     
  8. Offline

    Jayjay110

    THAT IS exactly what im asking, I belive u understand :D, how to do what this guy said?
     
  9. Offline

    DreadKyller

    well permissions uses the Configuration class in bukkit, if you just load the permissions file in a Configuration file you could actually find the value out yourself by getStringList() then split it
     
  10. Reading the config file manually is not what I would recommend since there is stuff like multiworld and Permissions are stored in more than one simple config file by now.

    I suppose there ist a method in the API of the Permissions-Plugin.
    Just take a look at its source code (especially the PermissionsHandler). As for what I have read so far, you should find your solution there.
     
  11. Offline

    Jayjay110

    Yeah thats what I thought, I just thought that someone would have been able to point this out to me :3

    Btw most of the stuff says deprecated?
     
  12. Offline

    DreadKyller

    well to get a persons permissions you'd still have to use the node, and so you'd be doing the same thing, whether it's getting the node of useing getString(path) it not make much difference. In multi world you'd have to get the world as well and just add that name onto it, it would not be hard, player.getWorld().getName(), so, multiworld, so what, you do know that as seeing permissions runs with Configuration class you can do almost anything that permissions does with Configuration? I mean how does that not make sense?

    there is a getPermissions() that returns a String[], but there are 3 perimeters. and I really did not take the time to see what they are.

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

    Dark_Balor

    I think I found how to do it.
    https://github.com/TheYeti/Permissi...java/com/nijiko/permissions/Control.java#L965

    using
    Code:
    getUserPermissionInteger(String world, String name, String permission)
    or
    Code:
    getGroupPermissionInteger(String world, String group, String permission)
    or easier way :
    Code:
    public int getPermissionInteger(String world, String name, String permission)
    To use it we must set a permission node like this :
    Code:
    "users." + name + ".info." + permission
    or
    Code:
    "groups." + group + ".info." + permission
    in the right file (users.yml for the first and groups.yml for the second, of course in the folder that have the name of the world)
    Example:
    I want to set 5 for the permission foo.bar :

    Code:
    users:
        Balor:
            info:
                foo:
                    bar: 5
            groups:
            - Admins
            permissions:
            - 'foo.bar'
    
    Code:
    groups:
        Default:
            default: true
            info:
                prefix: ''
                suffix: ''
                build: false
                foo:
                    bar: 5
            inheritance:
            permissions:
                - 'foo.bar'
    
    If no integer is set, it's returning -1
     
  14. Offline

    DreadKyller

    what he is asking, he has a node like this for example:

    Code:
    groups:
        Default:
            default: true
            info:
                prefix: ''
                suffix: ''
                build: false
             inheritance:
             permissions:
                - 'node.1'
                - 'node.2'
    and he wants to get what number is at the end, he can't just use the getPermission. he needs to get the name of the node, pretend he does not know it, he wants to find out what the host has for the number at the end.
     
  15. Offline

    Dark_Balor

    The way that I propose is the only way to add an Integer to a Permission node.
    Just look the source code of Permission, you'll that the functions that I'm talking about are made for that purpose.
     
  16. Offline

    DreadKyller

    ... wow, the method you are suggesting makes the user have to add another part of the node, that is NOT what JayJay wants and is NOT the only way. I have looked at Permissions several times. here is what I'm trying to say:

    THIS is what JayJay110 wants:

    Code:
    'blah.52'
    he wants to get the 52 in this case from the end of the node name. He does not want to do this:

    Code:
    blah:
        52
    you should read the first post again.

    you can use a Configuration object to get the Strings at "groups.Default.permissions" and for all the strings split it by "." and check to see if [0].equalsIgnoreCase("myplugin")&&[1].equalsIgnoreCase("amount") in this case, if so use Integer.parseInt([2]) that will get the exact result he is talking about in the top post.
     
    Jayjay110 likes this.
  17. Offline

    Jeyge

    I think your best method for right now is to use Entry.getAllPermissions() with Entry being either a User or Group. You can then parse the returned set in any way you want.

    This does sound like something it might be worth requesting a special API call for. Returning all permissions matching a pattern might be useful to other plugins.
     
  18. Offline

    Dark_Balor

    What you don't understand is that with the new Permissions, you can't easily access the configuration file, you must check first the world, then the group of the player and last but not least the player itself.

    And when you do that, you must look each Permission one by one, splitting them... My way to do it, is how Nijiko/TheYeti/rcjrrjcr want us to use Integer/boolean/string in Permissions. There isn't any other way that don't ask to parse yourself the Permissions config.

    Did you tried your method ? because I tried mine, and it's works.

    And in all the case we asking the user to add one new permission node

    Of course with the last version you can do as Jeyge say :
    Code:
    User user = safeGetUser(String world, String name)
    for (String perm : user. getAllPermissions())
    {
     splitFunction(perm);
    }
     
    raunak114 likes this.
  19. Offline

    DreadKyller

    now that's more of what he's looking for than the last script you posted.
     
  20. Offline

    Jayjay110

    Thats what im looking for :3 lol thanks guys
     
  21. Offline

    DreadKyller

    yes, that's exactly what you were looking for, I was commenting on his previous post where he posted something completely different
     
Thread Status:
Not open for further replies.

Share This Page