Added defensive code in User#getPermissionValue() to avoid similar bugs

This commit is contained in:
Florian CUNY 2018-12-09 14:53:06 +01:00
parent 3ef784b14b
commit 1e679fdd85

View File

@ -185,11 +185,16 @@ public class User {
/**
* Get the maximum value of a numerical permission setting
* @param permissionPrefix the start of the perm, e.g., bskyblock.maxhomes
* @param permissionPrefix the start of the perm, e.g., {@code plugin.mypermission}
* @param defaultValue the default value; the result may be higher or lower than this
* @return max value
*/
public int getPermissionValue(String permissionPrefix, int defaultValue) {
// If there is a dot at the end of the permissionPrefix, remove it
if (permissionPrefix.endsWith(".")) {
permissionPrefix = permissionPrefix.substring(0, permissionPrefix.length()-1);
}
int value = defaultValue;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(permissionPrefix + ".")) {