Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
permission Tristate and function exchanged with adventure
Dieser Commit ist enthalten in:
Ursprung
64ea90d254
Commit
cc67b99c8b
@ -9,9 +9,9 @@ package com.velocitypowered.api.event.permission;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.event.annotation.AwaitingEvent;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.permission.PermissionProvider;
|
||||
import com.velocitypowered.api.permission.PermissionSubject;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
@ -44,13 +44,13 @@ public final class PermissionsSetupEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the provider function to obtain a {@link PermissionFunction} for the subject.
|
||||
* Uses the provider function to obtain a {@link PermissionChecker} for the subject.
|
||||
*
|
||||
* @param subject the subject
|
||||
* @return the obtained permission function
|
||||
*/
|
||||
public PermissionFunction createFunction(PermissionSubject subject) {
|
||||
return this.provider.createFunction(subject);
|
||||
public PermissionChecker createChecker(PermissionSubject subject) {
|
||||
return this.provider.createChecker(subject);
|
||||
}
|
||||
|
||||
public PermissionProvider getProvider() {
|
||||
@ -58,7 +58,7 @@ public final class PermissionsSetupEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link PermissionFunction} that should be used for the subject.
|
||||
* Sets the {@link PermissionChecker} that should be used for the subject.
|
||||
*
|
||||
* <p>Specifying <code>null</code> will reset the provider to the default
|
||||
* instance given when the event was posted.</p>
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Velocity Contributors
|
||||
*
|
||||
* The Velocity API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the api top-level directory.
|
||||
*/
|
||||
|
||||
package com.velocitypowered.api.permission;
|
||||
|
||||
/**
|
||||
* Function that calculates the permission settings for a given {@link PermissionSubject}.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PermissionFunction {
|
||||
|
||||
/**
|
||||
* A permission function that always returns {@link Tristate#TRUE}.
|
||||
*/
|
||||
PermissionFunction ALWAYS_TRUE = p -> Tristate.TRUE;
|
||||
|
||||
/**
|
||||
* A permission function that always returns {@link Tristate#FALSE}.
|
||||
*/
|
||||
PermissionFunction ALWAYS_FALSE = p -> Tristate.FALSE;
|
||||
|
||||
/**
|
||||
* A permission function that always returns {@link Tristate#UNDEFINED}.
|
||||
*/
|
||||
PermissionFunction ALWAYS_UNDEFINED = p -> Tristate.UNDEFINED;
|
||||
|
||||
/**
|
||||
* Gets the subjects setting for a particular permission.
|
||||
*
|
||||
* @param permission the permission
|
||||
* @return the value the permission is set to
|
||||
*/
|
||||
Tristate getPermissionValue(String permission);
|
||||
}
|
@ -7,17 +7,19 @@
|
||||
|
||||
package com.velocitypowered.api.permission;
|
||||
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
|
||||
/**
|
||||
* Provides {@link PermissionFunction}s for {@link PermissionSubject}s.
|
||||
* Provides {@link PermissionChecker}s for {@link PermissionSubject}s.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface PermissionProvider {
|
||||
|
||||
/**
|
||||
* Creates a {@link PermissionFunction} for the subject.
|
||||
* Creates a {@link PermissionChecker} for the subject.
|
||||
*
|
||||
* @param subject the subject
|
||||
* @return the function
|
||||
*/
|
||||
PermissionFunction createFunction(PermissionSubject subject);
|
||||
PermissionChecker createChecker(PermissionSubject subject);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
package com.velocitypowered.api.permission;
|
||||
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
|
||||
/**
|
||||
* Represents a object that has a set of queryable permissions.
|
||||
@ -21,7 +22,7 @@ public interface PermissionSubject {
|
||||
* @return whether or not the subject has the permission
|
||||
*/
|
||||
default boolean hasPermission(String permission) {
|
||||
return getPermissionValue(permission).asBoolean();
|
||||
return getPermissionValue(permission).toBooleanOrElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,7 +31,7 @@ public interface PermissionSubject {
|
||||
* @param permission the permission
|
||||
* @return the value the permission is set to
|
||||
*/
|
||||
Tristate getPermissionValue(String permission);
|
||||
TriState getPermissionValue(String permission);
|
||||
|
||||
/**
|
||||
* Gets the permission checker for the subject.
|
||||
@ -38,6 +39,6 @@ public interface PermissionSubject {
|
||||
* @return subject's permission checker
|
||||
*/
|
||||
default PermissionChecker getPermissionChecker() {
|
||||
return permission -> getPermissionValue(permission).toAdventureTriState();
|
||||
return this::getPermissionValue;
|
||||
}
|
||||
}
|
||||
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2022 Velocity Contributors
|
||||
*
|
||||
* The Velocity API is licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in the api top-level directory.
|
||||
*/
|
||||
|
||||
package com.velocitypowered.api.permission;
|
||||
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Represents three different states of a setting.
|
||||
*
|
||||
* <p>Possible values:</p>
|
||||
* <p></p>
|
||||
* <ul>
|
||||
* <li>{@link #TRUE} - a positive setting</li>
|
||||
* <li>{@link #FALSE} - a negative (negated) setting</li>
|
||||
* <li>{@link #UNDEFINED} - a non-existent setting</li>
|
||||
* </ul>
|
||||
*/
|
||||
public enum Tristate {
|
||||
|
||||
/**
|
||||
* A value indicating a positive setting.
|
||||
*/
|
||||
TRUE(true),
|
||||
|
||||
/**
|
||||
* A value indicating a negative (negated) setting.
|
||||
*/
|
||||
FALSE(false),
|
||||
|
||||
/**
|
||||
* A value indicating a non-existent setting.
|
||||
*/
|
||||
UNDEFINED(false);
|
||||
|
||||
/**
|
||||
* Returns a {@link Tristate} from a boolean.
|
||||
*
|
||||
* @param val the boolean value
|
||||
* @return {@link #TRUE} or {@link #FALSE}, if the value is <code>true</code> or
|
||||
* <code>false</code>, respectively.
|
||||
*/
|
||||
public static Tristate fromBoolean(boolean val) {
|
||||
return val ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Tristate} from a nullable boolean.
|
||||
*
|
||||
* <p>Unlike {@link #fromBoolean(boolean)}, this method returns {@link #UNDEFINED}
|
||||
* if the value is null.</p>
|
||||
*
|
||||
* @param val the boolean value
|
||||
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value is <code>null</code>,
|
||||
* <code>true</code> or <code>false</code>, respectively.
|
||||
*/
|
||||
public static Tristate fromNullableBoolean(@Nullable Boolean val) {
|
||||
if (val == null) {
|
||||
return UNDEFINED;
|
||||
}
|
||||
return val ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
private final boolean booleanValue;
|
||||
|
||||
Tristate(boolean booleanValue) {
|
||||
this.booleanValue = booleanValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the Tristate as a boolean.
|
||||
*
|
||||
* <p>A value of {@link #UNDEFINED} converts to false.</p>
|
||||
*
|
||||
* @return a boolean representation of the Tristate.
|
||||
*/
|
||||
public boolean asBoolean() {
|
||||
return this.booleanValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the equivalent Adventure {@link TriState}.
|
||||
*
|
||||
* @return equivalent Adventure TriState
|
||||
*/
|
||||
public TriState toAdventureTriState() {
|
||||
if (this == Tristate.TRUE) {
|
||||
return TriState.TRUE;
|
||||
} else if (this == Tristate.UNDEFINED) {
|
||||
return TriState.NOT_SET;
|
||||
} else if (this == Tristate.FALSE) {
|
||||
return TriState.FALSE;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,6 @@ import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
@ -39,6 +38,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
|
||||
/**
|
||||
* Implements the Velocity default {@code /glist} command.
|
||||
@ -60,7 +60,7 @@ public class GlistCommand {
|
||||
LiteralCommandNode<CommandSource> totalNode = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("glist")
|
||||
.requires(source ->
|
||||
source.getPermissionValue("velocity.command.glist") == Tristate.TRUE)
|
||||
source.getPermissionValue("velocity.command.glist") == TriState.TRUE)
|
||||
.executes(this::totalCount)
|
||||
.build();
|
||||
ArgumentCommandNode<CommandSource, String> serverNode = RequiredArgumentBuilder
|
||||
|
@ -22,7 +22,6 @@ import static net.kyori.adventure.text.event.HoverEvent.showText;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
@ -37,6 +36,7 @@ import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
|
||||
/**
|
||||
* Implements Velocity's {@code /server} command.
|
||||
@ -161,6 +161,6 @@ public class ServerCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final SimpleCommand.Invocation invocation) {
|
||||
return invocation.source().getPermissionValue("velocity.command.server") != Tristate.FALSE;
|
||||
return invocation.source().getPermissionValue("velocity.command.server") != TriState.FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
@ -59,6 +58,7 @@ import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@ -200,7 +200,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.reload") == Tristate.TRUE;
|
||||
return source.getPermissionValue("velocity.command.reload") == TriState.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.info") != Tristate.FALSE;
|
||||
return source.getPermissionValue("velocity.command.info") != TriState.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE;
|
||||
return source.getPermissionValue("velocity.command.plugins") == TriState.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final CommandSource source, final String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE;
|
||||
return source.getPermissionValue("velocity.command.plugins") == TriState.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +481,7 @@ public class VelocityCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(CommandSource source, String @NonNull [] args) {
|
||||
return source.getPermissionValue("velocity.command.heap") == Tristate.TRUE;
|
||||
return source.getPermissionValue("velocity.command.heap") == TriState.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.proxy.crypto.IdentifiedKey;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
@ -45,6 +44,8 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -107,8 +108,8 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
||||
.thenAcceptAsync(event -> {
|
||||
if (!mcConnection.isClosed()) {
|
||||
// wait for permissions to load, then set the players permission function
|
||||
final PermissionFunction function = event.createFunction(player);
|
||||
if (function == null) {
|
||||
final PermissionChecker checker = event.createChecker(player);
|
||||
if (checker == null) {
|
||||
logger.error(
|
||||
"A plugin permission provider {} provided an invalid permission function"
|
||||
+ " for player {}. This is a bug in the plugin, not in Velocity. Falling"
|
||||
@ -116,7 +117,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
||||
event.getProvider().getClass().getName(),
|
||||
player.getUsername());
|
||||
} else {
|
||||
player.setPermissionFunction(function);
|
||||
player.setPermissionChecker(checker);
|
||||
}
|
||||
completeLoginProtocolPhaseAndInitialize(player);
|
||||
}
|
||||
|
@ -35,9 +35,7 @@ import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.permission.PermissionProvider;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
@ -111,6 +109,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.title.Title.Times;
|
||||
import net.kyori.adventure.title.TitlePart;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@ -132,7 +131,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
.mapper(TranslatableComponent.class, TranslatableComponent::key)
|
||||
.build())
|
||||
.build();
|
||||
static final PermissionProvider DEFAULT_PERMISSIONS = s -> PermissionFunction.ALWAYS_UNDEFINED;
|
||||
static final PermissionProvider DEFAULT_PERMISSIONS = s -> PermissionChecker.always(TriState.NOT_SET);
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ConnectedPlayer.class);
|
||||
|
||||
@ -143,7 +142,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
private final MinecraftConnection connection;
|
||||
private final @Nullable InetSocketAddress virtualHost;
|
||||
private GameProfile profile;
|
||||
private PermissionFunction permissionFunction;
|
||||
private PermissionChecker permissionChecker;
|
||||
private int tryIndex = 0;
|
||||
private long ping = -1;
|
||||
private final boolean onlineMode;
|
||||
@ -168,7 +167,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
.withDynamic(Identity.NAME, this::getUsername)
|
||||
.withDynamic(Identity.DISPLAY_NAME, () -> Component.text(this.getUsername()))
|
||||
.withDynamic(Identity.LOCALE, this::getEffectiveLocale)
|
||||
.withStatic(PermissionChecker.POINTER, getPermissionChecker())
|
||||
.withDynamic(PermissionChecker.POINTER, () -> this.permissionChecker)
|
||||
.withStatic(FacetPointers.TYPE, Type.PLAYER)
|
||||
.build();
|
||||
private @Nullable String clientBrand;
|
||||
@ -184,7 +183,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
this.profile = profile;
|
||||
this.connection = connection;
|
||||
this.virtualHost = virtualHost;
|
||||
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
|
||||
this.permissionChecker = PermissionChecker.always(TriState.NOT_SET);
|
||||
this.connectionPhase = connection.getType().getInitialClientPhase();
|
||||
this.knownChannels = CappedSet.create(MAX_PLUGIN_CHANNELS);
|
||||
this.onlineMode = onlineMode;
|
||||
@ -319,8 +318,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
return Optional.ofNullable(virtualHost);
|
||||
}
|
||||
|
||||
void setPermissionFunction(PermissionFunction permissionFunction) {
|
||||
this.permissionFunction = permissionFunction;
|
||||
void setPermissionChecker(PermissionChecker permissionChecker) {
|
||||
this.permissionChecker = permissionChecker;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -909,8 +908,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(String permission) {
|
||||
return permissionFunction.getPermissionValue(permission);
|
||||
public TriState getPermissionValue(String permission) {
|
||||
return permissionChecker.value(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,11 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.console;
|
||||
|
||||
import static com.velocitypowered.api.permission.PermissionFunction.ALWAYS_TRUE;
|
||||
|
||||
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.util.ClosestLocaleMatcher;
|
||||
@ -37,6 +33,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -57,7 +54,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
private static final Logger logger = LogManager.getLogger(VelocityConsole.class);
|
||||
|
||||
private final VelocityServer server;
|
||||
private PermissionFunction permissionFunction = ALWAYS_TRUE;
|
||||
private PermissionChecker permissionChecker = PermissionChecker.always(TriState.TRUE);
|
||||
private final @NotNull Pointers pointers = ConsoleCommandSource.super.pointers().toBuilder()
|
||||
.withDynamic(PermissionChecker.POINTER, this::getPermissionChecker)
|
||||
.withDynamic(Identity.LOCALE, () -> ClosestLocaleMatcher.INSTANCE
|
||||
@ -78,8 +75,8 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Tristate getPermissionValue(@NonNull String permission) {
|
||||
return this.permissionFunction.getPermissionValue(permission);
|
||||
public @NonNull TriState getPermissionValue(@NonNull String permission) {
|
||||
return this.permissionChecker.value(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,16 +91,16 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
* Sets up permissions for the console.
|
||||
*/
|
||||
public void setupPermissions() {
|
||||
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE);
|
||||
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> PermissionChecker.always(TriState.TRUE));
|
||||
// we can safely block here, this is before any listeners fire
|
||||
this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this);
|
||||
if (this.permissionFunction == null) {
|
||||
this.permissionChecker = this.server.getEventManager().fire(event).join().createChecker(this);
|
||||
if (this.permissionChecker == null) {
|
||||
logger.error(
|
||||
"A plugin permission provider {} provided an invalid permission function"
|
||||
+ " for the console. This is a bug in the plugin, not in Velocity. Falling"
|
||||
+ " back to the default permission function.",
|
||||
event.getProvider().getClass().getName());
|
||||
this.permissionFunction = ALWAYS_TRUE;
|
||||
this.permissionChecker = PermissionChecker.always(TriState.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,13 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.proxy.event.MockEventManager;
|
||||
import com.velocitypowered.proxy.event.VelocityEventManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
@ -66,7 +67,7 @@ abstract class CommandTestSuite {
|
||||
|
||||
final void assertPlayerSuggestions(final String input, final String... expectedSuggestions) {
|
||||
final var player = mock(Player.class);
|
||||
when(player.getPermissionValue(any())).thenReturn(Tristate.UNDEFINED);
|
||||
when(player.getPermissionValue(any())).thenReturn(TriState.NOT_SET);
|
||||
final var actual = manager.offerSuggestions(player, input).join();
|
||||
assertEquals(Arrays.asList(expectedSuggestions), actual);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
package com.velocitypowered.proxy.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
|
||||
/**
|
||||
* A fake {@link CommandSource}.
|
||||
@ -28,7 +28,7 @@ public class MockCommandSource implements CommandSource {
|
||||
public static final CommandSource INSTANCE = new MockCommandSource();
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(final String permission) {
|
||||
return Tristate.UNDEFINED;
|
||||
public TriState getPermissionValue(final String permission) {
|
||||
return TriState.NOT_SET;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren