1.14.4 Simple Rank / Permissions

Discussion in 'Spigot Plugin Development' started by Hampion, Mar 28, 2020.

  1. Hello there,

    I am fairly new to the Spigot API. I have been testing around trying to make a rank plugin that also enables groups to have permissions. For the start I was planning just to do all the permissions via config. I have set it up so far that I can set players ranks and that's all great. When it came to the permissions part I am very much clueless. I have given an attempt and managed to get the permissions working on a HashMap. However this is not really working properly and it seems that the groups are not really identified as they all get the same permissions, can't tell what I am doing wrong. Below you will find my source code, I really hope someone can help me out here! Thanks!

    MAIN - https://pastebin.com/dvryPryk

    PLAYERMANAGER - https://pastebin.com/wUfN6wUn

    ^^ I also have an event and the rank command but didn't think they would be necessary.

    My config.yml looks like this:

    Groups:
    guest:
    permissions:
    - tutorial.blockbreak

    (No matter the if add new groups to that it still does not work and adds all the permissions for every group on each player).

    I know I am probably doing something stupid, so please try not to take offence or anything! Thank you all.
     
  2. Remember that the white space in YAML matters a lot. Next time, post the config in src brackets so we can see the whitespace because as it stands, you have three nodes, "Groups" "guest" and "permissions" not the tiered thing you are look for ("guest" below groups etc.). Just an FYI if you ever need to post your config again.

    On to your actual issue. Remember that Java is an Object-Oriented language and we can use this to our advantage and it will make your life a lot easier down the road. Lets create a "Group" object. What properties would we expect a group to have? Obviously a list of permissions, probably a list of players, a list of permissions, a prefix etc. If we setup this object properly we can check if a player is a part of a group and if so check to see if the permission is in that group's list. Or some other more efficient workflow, perhaps instead the hashmap maps a player to a group.

    The reason all your players get all the permissions for all the groups is because of the permissionSetter method. You loop through each group and each list of permissions in each group and add it to the PermissionAttachment. Add only the group you want by navigating directly to that group's list of permissions.