1.15.2 "Highest" Permission

Discussion in 'Spigot Plugin Development' started by AJ-Plugin-BotDev, Feb 8, 2020.

  1. Hello everyone, basically im making a plugin where you do a command, and based on the permission you have, you get a reward.This is what the config would look like

    Code (YAML):
    Tiers:
      Tier1
    :
       - [MESSAGE] You claimed tier 1
        - [BROADCAST] %player_name% claimed tier 1
        - [COMMAND] give %player_name% diamond 2
      Tier2
    :
       - [MESSAGE] You claimed tier 2
        - [BROADCAST] %player_name% claimed tier 2
        - [COMMAND] give %player_name% diamond 8
    And i want the config to be infinitly expandable.
    Now the issue is checking if they have the permission.
    I cannot simply loop through all the keys, as that starts with tier 1, and when you get tier 2 the tier 1 permission is removed from you. Eg.
    if you are tier 2, the entire plugin breaks as it checks if you have the perm for tier 1 first, and then when you dont it returns true;
    Essentially what i need to do, is have the permission nodes like "pluginName.Tier1" then replace pluginName.Tier with nothing, then sort the numbers, is this the simplest way, and if so could someone expllain how i can loop through all the players permissions. Then i would need to work out how to check which number is the highest, if someone can help me get started with that it would be appreciated
    Thankyou everyone :3
     
  2. You can access a player's all permission with:

    Code (Java):
    Player p;
    Permissible perm = (Permissible) p;

    for(PermissionAttachmentInfo info : perm.getEffectivePermissions()){

      Map<String, Boolean> perms = info.getAttachment().getPermissions();
      for(String permission : perms.keySet()){
        if(perms.get(permission)){ //The value is true, so this node is active
        }
      }

    }
    You can unset the permission:
    Code (Java):
    info.getAttachment().unsetPermission("pluginName.Tier");
    Getting the lowest Tier:

    Code (Java):
    Map<String, Boolean> map = info.getAttachment().getPermissions();

    int index = 1;
    String search = "pluginName.Tier" + index;
    while(map.contains(search)){
      index++;
      search = "pluginName.Tier" + index;
    }
     
  3. I wanna get the highest tier
     
  4. List<String> tiers = new ArrayList<>(getConfig().getConfigurationSection("Tiers").getKeys(false));
    for(int i = tiers.size; i > 0; i--){
    if(p.hasPerm(tiers.get(i)) //Highest
    }
     
  5. Th
    at gives me an index out of bounds specifically this line
    if(sender.hasPermission(tiers.get(i))){
     
  6. Yea that should be tiers.size - 1

    Arrays start at 0 but the size starts at 1 so you always have to subtract 1 ;)
     
    • Like Like x 1
  7. This prints 1 regardless of anything
     
  8. { a, b, c } size is 3 but the index are 0-2 so for(int i = tiers.size; i > 0; i--){ will always get an index out of bounds since it starts 1 past the end index, it should be for (int i = tiers.size -1; i>0; i--)