Correctly implement Bukkit/Nukkit isPermissionSet method, inline with the behaviour in PermissibleBase (#1403)

This commit is contained in:
Luck 2019-01-31 01:14:38 +00:00
parent 307614e704
commit 43d04a97f5
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 41 additions and 38 deletions

View File

@ -29,6 +29,8 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.bukkit.calculator.DefaultsProcessor;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.ContextsSupplier;
import me.lucko.luckperms.common.model.User;
@ -136,8 +138,17 @@ public class LPPermissible extends PermissibleBase {
throw new NullPointerException("permission");
}
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK).result();
return ts != Tristate.UNDEFINED || Permission.DEFAULT_PERMISSION.getValue(isOp());
TristateResult result = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
if (result.result() == Tristate.UNDEFINED) {
return false;
}
// ignore matches made from looking up in the permission map (replicate bukkit behaviour)
if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) {
return false;
}
return true;
}
@Override
@ -146,16 +157,7 @@ public class LPPermissible extends PermissibleBase {
throw new NullPointerException("permission");
}
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK).result();
if (ts != Tristate.UNDEFINED) {
return true;
}
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
return Permission.DEFAULT_PERMISSION.getValue(isOp());
} else {
return permission.getDefault().getValue(isOp());
}
return isPermissionSet(permission.getName());
}
@Override
@ -179,10 +181,10 @@ public class LPPermissible extends PermissibleBase {
return ts.asBoolean();
}
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
return Permission.DEFAULT_PERMISSION.getValue(isOp());
} else {
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
return permission.getDefault().getValue(isOp());
} else {
return Permission.DEFAULT_PERMISSION.getValue(isOp());
}
}

View File

@ -177,8 +177,8 @@ public final class LPSubscriptionMap extends HashMap<String, Map<Permissible, Bo
// if the key is a player, check their LPPermissible first
if (isPlayer) {
Permissible p = (Permissible) key;
if (p.isPermissionSet(this.permission)) {
return p.hasPermission(this.permission);
if (p.hasPermission(this.permission)) {
return true;
}
}
@ -191,8 +191,8 @@ public final class LPSubscriptionMap extends HashMap<String, Map<Permissible, Bo
// then try the permissible, if we haven't already
if (!isPlayer && key instanceof Permissible) {
Permissible p = (Permissible) key;
if (p.isPermissionSet(this.permission)) {
return p.hasPermission(this.permission);
if (p.hasPermission(this.permission)) {
return true;
}
}
@ -220,7 +220,7 @@ public final class LPSubscriptionMap extends HashMap<String, Map<Permissible, Bo
public @NonNull Set<Permissible> keySet() {
// gather players (LPPermissibles)
Set<Permissible> players = LPSubscriptionMap.this.plugin.getBootstrap().getServer().getOnlinePlayers().stream()
.filter(player -> player.isPermissionSet(this.permission))
.filter(player -> player.hasPermission(this.permission) || player.isPermissionSet(this.permission))
.collect(Collectors.toSet());
// then combine the players with the backing map

View File

@ -28,12 +28,14 @@ package me.lucko.luckperms.nukkit.inject.permissible;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.calculator.result.TristateResult;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.ContextsSupplier;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.util.ImmutableCollectors;
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
import me.lucko.luckperms.nukkit.calculator.DefaultsProcessor;
import me.lucko.luckperms.nukkit.inject.PermissionDefault;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -137,8 +139,17 @@ public class LPPermissible extends PermissibleBase {
throw new NullPointerException("permission");
}
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK).result();
return ts != Tristate.UNDEFINED || PermissionDefault.OP.getValue(isOp());
TristateResult result = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
if (result.result() == Tristate.UNDEFINED) {
return false;
}
// ignore matches made from looking up in the permission map (replicate nukkit behaviour)
if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) {
return false;
}
return true;
}
@Override
@ -147,17 +158,7 @@ public class LPPermissible extends PermissibleBase {
throw new NullPointerException("permission");
}
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsSupplier.getContexts()).getPermissionValue(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK).result();
if (ts != Tristate.UNDEFINED) {
return true;
}
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
return PermissionDefault.OP.getValue(isOp());
} else {
PermissionDefault def = PermissionDefault.fromPermission(permission);
return def != null && def.getValue(isOp());
}
return isPermissionSet(permission.getName());
}
@Override
@ -181,11 +182,11 @@ public class LPPermissible extends PermissibleBase {
return ts.asBoolean();
}
if (!this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
return PermissionDefault.OP.getValue(isOp());
} else {
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
PermissionDefault def = PermissionDefault.fromPermission(permission);
return def != null && def.getValue(isOp());
} else {
return PermissionDefault.OP.getValue(isOp());
}
}

View File

@ -176,7 +176,7 @@ public final class LPSubscriptionMap extends HashMap<String, Set<Permissible>> {
private Sets.SetView<Permissible> getContentView() {
// gather players (LPPermissibles)
Set<Permissible> players = LPSubscriptionMap.this.plugin.getBootstrap().getServer().getOnlinePlayers().values().stream()
.filter(player -> player.isPermissionSet(this.permission))
.filter(player -> player.hasPermission(this.permission) || player.isPermissionSet(this.permission))
.collect(Collectors.toSet());
return Sets.union(players, this.backing);
@ -192,7 +192,7 @@ public final class LPSubscriptionMap extends HashMap<String, Set<Permissible>> {
// then try the permissible
if (key instanceof Permissible) {
Permissible p = (Permissible) key;
return p.isPermissionSet(this.permission);
return p.hasPermission(this.permission);
}
// no result