Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ public void activated() {
}

return server.getEventManager()
.fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
.fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSION_PROVIDER))
.thenAcceptAsync(event -> {
if (!mcConnection.isClosed()) {
// wait for permissions to load, then set the players permission function
final PermissionFunction function = event.createFunction(player);
PermissionFunction function = event.createFunction(player);
if (function == 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 back to the default permission function.",
event.getProvider().getClass().getName(), player.getUsername());
} else {
player.setPermissionFunction(function);
function = ConnectedPlayer.DEFAULT_PERMISSION_PROVIDER.createFunction(player);
}
player.setPermissionFunction(function);
startLoginCompletion(player);
}
}, mcConnection.eventLoop());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
public static final int MAX_CLIENTSIDE_PLUGIN_CHANNELS = Integer.getInteger("velocity.max-clientside-plugin-channels", 1024);
private static final PlainTextComponentSerializer PASS_THRU_TRANSLATE =
PlainTextComponentSerializer.builder().flattener(TranslatableMapper.FLATTENER).build();
static final PermissionProvider DEFAULT_PERMISSIONS = s -> PermissionFunction.ALWAYS_UNDEFINED;
static final PermissionProvider DEFAULT_PERMISSION_PROVIDER = s -> PermissionFunction.ALWAYS_UNDEFINED;

private static final ComponentLogger logger = ComponentLogger.logger(ConnectedPlayer.class);

Expand Down Expand Up @@ -214,7 +214,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
this.virtualHost = virtualHost;
this.rawVirtualHost = rawVirtualHost;
this.handshakeIntent = handshakeIntent;
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
this.permissionFunction = DEFAULT_PERMISSION_PROVIDER.createFunction(this);
this.connectionPhase = connection.getType().getInitialClientPhase();
this.onlineMode = onlineMode;
this.clientsideChannels = CappedSet.create(MAX_CLIENTSIDE_PLUGIN_CHANNELS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

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.PermissionProvider;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.proxy.VelocityServer;
Expand Down Expand Up @@ -54,12 +53,14 @@
*/
public final class VelocityConsole extends SimpleTerminalConsole implements ConsoleCommandSource {

private static final PermissionProvider DEFAULT_PERMISSION_PROVIDER = s -> PermissionFunction.ALWAYS_TRUE;

private static final Logger logger = LogManager.getLogger(VelocityConsole.class);
private static final ComponentLogger componentLogger = ComponentLogger
.logger(VelocityConsole.class);

private final VelocityServer server;
private PermissionFunction permissionFunction = ALWAYS_TRUE;
private PermissionFunction permissionFunction;
private static final @NotNull PointersSupplier<VelocityConsole> POINTERS = PointersSupplier.<VelocityConsole>builder()
.resolving(PermissionChecker.POINTER, VelocityConsole::getPermissionChecker)
.resolving(Identity.LOCALE, (console) -> ClosestLocaleMatcher.INSTANCE
Expand All @@ -69,6 +70,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons

public VelocityConsole(VelocityServer server) {
this.server = server;
this.permissionFunction = DEFAULT_PERMISSION_PROVIDER.createFunction(this);
}

@Override
Expand All @@ -94,7 +96,7 @@ public void setupStreams() {
* Sets up permissions for the console.
*/
public void setupPermissions() {
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE);
PermissionsSetupEvent event = new PermissionsSetupEvent(this, DEFAULT_PERMISSION_PROVIDER);
// 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) {
Expand All @@ -103,7 +105,7 @@ public void setupPermissions() {
+ " 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.permissionFunction = DEFAULT_PERMISSION_PROVIDER.createFunction(this);
}
}

Expand Down