3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +01:00

Properly initialise console permissions using the PermissionsSetupEvent

Dieser Commit ist enthalten in:
Luck 2018-09-20 19:00:42 +01:00
Ursprung ef578ff69b
Commit ea42f47c7b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EFA9B3EC5FD90F8B
3 geänderte Dateien mit 39 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,5 @@
package com.velocitypowered.proxy;
import com.velocitypowered.proxy.console.VelocityConsole;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -28,6 +27,6 @@ public class Velocity {
double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
new VelocityConsole(server).start();
server.getConsoleCommandSource().start();
}
}

Datei anzeigen

@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
@ -22,6 +21,7 @@ import com.velocitypowered.proxy.command.VelocityCommandManager;
import com.velocitypowered.proxy.config.AnnotatedConfig;
import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.console.VelocityConsole;
import com.velocitypowered.proxy.messages.VelocityChannelRegistrar;
import com.velocitypowered.proxy.network.ConnectionManager;
import com.velocitypowered.proxy.network.http.NettyHttpClient;
@ -37,7 +37,6 @@ import com.velocitypowered.proxy.util.Ratelimiter;
import io.netty.bootstrap.Bootstrap;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.serializer.ComponentSerializers;
import net.kyori.text.serializer.GsonComponentSerializer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -73,17 +72,7 @@ public class VelocityServer implements ProxyServer {
private final Map<UUID, ConnectedPlayer> connectionsByUuid = new ConcurrentHashMap<>();
private final Map<String, ConnectedPlayer> connectionsByName = new ConcurrentHashMap<>();
private final CommandSource consoleCommandSource = new CommandSource() {
@Override
public void sendMessage(Component component) {
logger.info(ComponentSerializers.LEGACY.serialize(component));
}
@Override
public @NonNull Tristate getPermissionValue(@NonNull String permission) {
return Tristate.TRUE;
}
};
private final VelocityConsole console = new VelocityConsole(this);
private Ratelimiter ipAttemptLimiter;
private VelocityEventManager eventManager;
private VelocityScheduler scheduler;
@ -148,6 +137,9 @@ public class VelocityServer implements ProxyServer {
// issues) and there is almost no chance ExecutionException will be thrown.
}
// init console permissions after plugins are loaded
console.setupPermissions();
this.cm.bind(configuration.getBind());
if (configuration.isQueryEnabled()) {
@ -297,8 +289,8 @@ public class VelocityServer implements ProxyServer {
}
@Override
public CommandSource getConsoleCommandSource() {
return consoleCommandSource;
public VelocityConsole getConsoleCommandSource() {
return console;
}
@Override

Datei anzeigen

@ -1,9 +1,18 @@
package com.velocitypowered.proxy.console;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.proxy.VelocityServer;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.format.TextColor;
import net.kyori.text.serializer.ComponentSerializers;
import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jline.reader.Candidate;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
@ -11,20 +20,38 @@ import org.jline.reader.LineReaderBuilder;
import java.util.List;
import java.util.Optional;
public final class VelocityConsole extends SimpleTerminalConsole {
public final class VelocityConsole extends SimpleTerminalConsole implements CommandSource {
private static final Logger logger = LogManager.getLogger(VelocityConsole.class);
private final VelocityServer server;
private PermissionFunction permissionFunction = PermissionFunction.ALWAYS_TRUE;
public VelocityConsole(VelocityServer server) {
this.server = server;
}
@Override
public void sendMessage(Component component) {
logger.info(ComponentSerializers.LEGACY.serialize(component));
}
@Override
public @NonNull Tristate getPermissionValue(@NonNull String permission) {
return this.permissionFunction.getPermissionValue(permission);
}
public void setupPermissions() {
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> PermissionFunction.ALWAYS_TRUE);
this.server.getEventManager().fire(event).join(); // this is called on startup, we can safely #join
this.permissionFunction = event.createFunction(this);
}
@Override
protected LineReader buildReader(LineReaderBuilder builder) {
return super.buildReader(builder
.appName("Velocity")
.completer((reader, parsedLine, list) -> {
Optional<List<String>> o = server.getCommandManager().offerSuggestions(server.getConsoleCommandSource(), parsedLine.line());
Optional<List<String>> o = this.server.getCommandManager().offerSuggestions(this, parsedLine.line());
o.ifPresent(offers -> {
for (String offer : offers) {
list.add(new Candidate(offer));
@ -41,8 +68,8 @@ public final class VelocityConsole extends SimpleTerminalConsole {
@Override
protected void runCommand(String command) {
if (!this.server.getCommandManager().execute(this.server.getConsoleCommandSource(), command)) {
server.getConsoleCommandSource().sendMessage(TextComponent.of("Command not found.", TextColor.RED));
if (!this.server.getCommandManager().execute(this, command)) {
sendMessage(TextComponent.of("Command not found.", TextColor.RED));
}
}