Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Drawethree, Jun 3, 2018.
Hey guys, what's the best way to check for player's highest permission ? Like party.size.5
for(int count = 0; count <= 99; ++count) // I used 99 but that should be the max amount possible
if(playerAmount != null
playerAmount = count;
this is how I would do it.
You can use Player#getEffectivePermissions to get all permissions and then filter them out and fin the highest.
Something along the lines of this should work:
player.getEffectivePermissions().stream().filter(pai -> pai.getPermission().startsWith("party.size.")).mapToInt(pai -> Integer.parseInt(pai.getPermission().substring(11))).max().orElse(0);
may contain errors, did this without an IDE
Will return the highest party size value the player currently has, or, if the player doesn't have any, zero.
I use LuckPerms as permissions plugin, because you can set a meta and then easily access it within code.
I do it this way as well, except I iterate from highest to lowest and break out of the loop as soon as a match is found.
You should consider changing your method.
If for example a player had the permission for size 2 and 5 then he would get the size 2 set to him. Re-read your method and you will understand why. So going from top to bottom is much wiser.
never actually made any plugins that need this, hence the way i "would" do it. But yeah that is a valid point.