mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Move op handling into a permission processor
This commit is contained in:
parent
ca33cee79d
commit
ec2cb5007c
@ -66,8 +66,15 @@ public class BukkitCalculatorFactory implements CalculatorFactory {
|
|||||||
processors.add(new WildcardProcessor());
|
processors.add(new WildcardProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
if (metadata.getHolderType() == HolderType.USER) {
|
||||||
processors.add(new DefaultsProcessor(this.plugin, queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false)));
|
boolean op = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
|
||||||
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
|
processors.add(new DefaultsProcessor(this.plugin, op));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (op) {
|
||||||
|
processors.add(new OpProcessor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PermissionCalculator(this.plugin, metadata, processors.build());
|
return new PermissionCalculator(this.plugin, metadata, processors.build());
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.bukkit.calculator;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
|
||||||
|
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
||||||
|
|
||||||
|
import net.luckperms.api.util.Tristate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission Processor which is added for opped users, to simply return true if
|
||||||
|
* no other processors match.
|
||||||
|
*/
|
||||||
|
public class OpProcessor implements PermissionProcessor {
|
||||||
|
private static final TristateResult TRUE_RESULT = new TristateResult.Factory(OpProcessor.class).result(Tristate.TRUE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TristateResult hasPermission(String permission) {
|
||||||
|
return TRUE_RESULT;
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||||
import me.lucko.luckperms.bukkit.calculator.DefaultsProcessor;
|
import me.lucko.luckperms.bukkit.calculator.DefaultsProcessor;
|
||||||
import me.lucko.luckperms.bukkit.context.BukkitContextManager;
|
import me.lucko.luckperms.bukkit.calculator.OpProcessor;
|
||||||
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
import me.lucko.luckperms.common.context.QueryOptionsCache;
|
||||||
@ -141,13 +141,19 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
TristateResult result = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
|
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
|
||||||
if (result.result() == Tristate.UNDEFINED) {
|
if (result.result() == Tristate.UNDEFINED) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore matches made from looking up in the permission map (replicate bukkit behaviour)
|
// ignore matches made from looking up in the permission map (replicate bukkit behaviour)
|
||||||
return !(result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause()));
|
if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore the op processor
|
||||||
|
return result.processorClass() != OpProcessor.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -166,13 +172,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
return this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result().asBoolean();
|
||||||
if (ts != Tristate.UNDEFINED) {
|
|
||||||
return ts.asBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isOp = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
|
|
||||||
return Permission.DEFAULT_PERMISSION.getValue(isOp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -182,17 +182,15 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK);
|
||||||
if (ts != Tristate.UNDEFINED) {
|
|
||||||
return ts.asBoolean();
|
// override default op handling using the Permission class we have
|
||||||
|
if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
|
// 'op == true' is implied by the presence of the OpProcessor class
|
||||||
|
return permission.getDefault().getValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isOp = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
|
return result.result().asBoolean();
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
|
||||||
return permission.getDefault().getValue(isOp);
|
|
||||||
} else {
|
|
||||||
return Permission.DEFAULT_PERMISSION.getValue(isOp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,8 +66,15 @@ public class NukkitCalculatorFactory implements CalculatorFactory {
|
|||||||
processors.add(new WildcardProcessor());
|
processors.add(new WildcardProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS) && metadata.getHolderType() == HolderType.USER) {
|
if (metadata.getHolderType() == HolderType.USER) {
|
||||||
processors.add(new DefaultsProcessor(this.plugin, queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false)));
|
boolean op = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
|
||||||
|
if (this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
|
processors.add(new DefaultsProcessor(this.plugin, op));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (op) {
|
||||||
|
processors.add(new OpProcessor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PermissionCalculator(this.plugin, metadata, processors.build());
|
return new PermissionCalculator(this.plugin, metadata, processors.build());
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.nukkit.calculator;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
|
||||||
|
import me.lucko.luckperms.common.calculator.result.TristateResult;
|
||||||
|
|
||||||
|
import net.luckperms.api.util.Tristate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission Processor which is added for opped users, to simply return true if
|
||||||
|
* no other processors match.
|
||||||
|
*/
|
||||||
|
public class OpProcessor implements PermissionProcessor {
|
||||||
|
private static final TristateResult TRUE_RESULT = new TristateResult.Factory(OpProcessor.class).result(Tristate.TRUE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TristateResult hasPermission(String permission) {
|
||||||
|
return TRUE_RESULT;
|
||||||
|
}
|
||||||
|
}
|
@ -35,7 +35,7 @@ import me.lucko.luckperms.common.util.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent;
|
||||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||||
import me.lucko.luckperms.nukkit.calculator.DefaultsProcessor;
|
import me.lucko.luckperms.nukkit.calculator.DefaultsProcessor;
|
||||||
import me.lucko.luckperms.nukkit.context.NukkitContextManager;
|
import me.lucko.luckperms.nukkit.calculator.OpProcessor;
|
||||||
import me.lucko.luckperms.nukkit.inject.PermissionDefault;
|
import me.lucko.luckperms.nukkit.inject.PermissionDefault;
|
||||||
|
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
@ -142,13 +142,19 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
throw new NullPointerException("permission");
|
throw new NullPointerException("permission");
|
||||||
}
|
}
|
||||||
|
|
||||||
TristateResult result = this.user.getCachedData().getPermissionData(this.queryOptionsSupplier.getQueryOptions()).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
|
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK);
|
||||||
if (result.result() == Tristate.UNDEFINED) {
|
if (result.result() == Tristate.UNDEFINED) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore matches made from looking up in the permission map (replicate nukkit behaviour)
|
// ignore matches made from looking up in the permission map (replicate nukkit behaviour)
|
||||||
return !(result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause()));
|
if (result.processorClass() == DefaultsProcessor.class && "permission map".equals(result.cause())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore the op processor
|
||||||
|
return result.processorClass() != OpProcessor.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -167,13 +173,7 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
return this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission, PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result().asBoolean();
|
||||||
if (ts != Tristate.UNDEFINED) {
|
|
||||||
return ts.asBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isOp = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
|
|
||||||
return PermissionDefault.OP.getValue(isOp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -183,18 +183,18 @@ public class LPPermissible extends PermissibleBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
QueryOptions queryOptions = this.queryOptionsSupplier.getQueryOptions();
|
||||||
Tristate ts = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK).result();
|
TristateResult result = this.user.getCachedData().getPermissionData(queryOptions).checkPermission(permission.getName(), PermissionCheckEvent.Origin.PLATFORM_PERMISSION_CHECK);
|
||||||
if (ts != Tristate.UNDEFINED) {
|
|
||||||
return ts.asBoolean();
|
// override default op handling using the Permission class we have
|
||||||
|
if (result.processorClass() == OpProcessor.class && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
|
||||||
|
// 'op == true' is implied by the presence of the OpProcessor class
|
||||||
|
PermissionDefault def = PermissionDefault.fromPermission(permission);
|
||||||
|
if (def != null) {
|
||||||
|
return def.getValue(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isOp = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
|
return result.result().asBoolean();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user