geforkt von Mirrors/Velocity
Properly initialise console permissions using the PermissionsSetupEvent
Dieser Commit ist enthalten in:
Ursprung
ef578ff69b
Commit
ea42f47c7b
@ -1,6 +1,5 @@
|
|||||||
package com.velocitypowered.proxy;
|
package com.velocitypowered.proxy;
|
||||||
|
|
||||||
import com.velocitypowered.proxy.console.VelocityConsole;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -28,6 +27,6 @@ public class Velocity {
|
|||||||
|
|
||||||
double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
|
double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
|
||||||
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
|
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
|
||||||
new VelocityConsole(server).start();
|
server.getConsoleCommandSource().start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.event.EventManager;
|
import com.velocitypowered.api.event.EventManager;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
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.AnnotatedConfig;
|
||||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||||
|
import com.velocitypowered.proxy.console.VelocityConsole;
|
||||||
import com.velocitypowered.proxy.messages.VelocityChannelRegistrar;
|
import com.velocitypowered.proxy.messages.VelocityChannelRegistrar;
|
||||||
import com.velocitypowered.proxy.network.ConnectionManager;
|
import com.velocitypowered.proxy.network.ConnectionManager;
|
||||||
import com.velocitypowered.proxy.network.http.NettyHttpClient;
|
import com.velocitypowered.proxy.network.http.NettyHttpClient;
|
||||||
@ -37,7 +37,6 @@ import com.velocitypowered.proxy.util.Ratelimiter;
|
|||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.serializer.ComponentSerializers;
|
|
||||||
import net.kyori.text.serializer.GsonComponentSerializer;
|
import net.kyori.text.serializer.GsonComponentSerializer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
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<UUID, ConnectedPlayer> connectionsByUuid = new ConcurrentHashMap<>();
|
||||||
private final Map<String, ConnectedPlayer> connectionsByName = new ConcurrentHashMap<>();
|
private final Map<String, ConnectedPlayer> connectionsByName = new ConcurrentHashMap<>();
|
||||||
private final CommandSource consoleCommandSource = new CommandSource() {
|
private final VelocityConsole console = new VelocityConsole(this);
|
||||||
@Override
|
|
||||||
public void sendMessage(Component component) {
|
|
||||||
logger.info(ComponentSerializers.LEGACY.serialize(component));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull Tristate getPermissionValue(@NonNull String permission) {
|
|
||||||
return Tristate.TRUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private Ratelimiter ipAttemptLimiter;
|
private Ratelimiter ipAttemptLimiter;
|
||||||
private VelocityEventManager eventManager;
|
private VelocityEventManager eventManager;
|
||||||
private VelocityScheduler scheduler;
|
private VelocityScheduler scheduler;
|
||||||
@ -148,6 +137,9 @@ public class VelocityServer implements ProxyServer {
|
|||||||
// issues) and there is almost no chance ExecutionException will be thrown.
|
// 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());
|
this.cm.bind(configuration.getBind());
|
||||||
|
|
||||||
if (configuration.isQueryEnabled()) {
|
if (configuration.isQueryEnabled()) {
|
||||||
@ -297,8 +289,8 @@ public class VelocityServer implements ProxyServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandSource getConsoleCommandSource() {
|
public VelocityConsole getConsoleCommandSource() {
|
||||||
return consoleCommandSource;
|
return console;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package com.velocitypowered.proxy.console;
|
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 com.velocitypowered.proxy.VelocityServer;
|
||||||
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
|
import net.kyori.text.serializer.ComponentSerializers;
|
||||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
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.Candidate;
|
||||||
import org.jline.reader.LineReader;
|
import org.jline.reader.LineReader;
|
||||||
import org.jline.reader.LineReaderBuilder;
|
import org.jline.reader.LineReaderBuilder;
|
||||||
@ -11,20 +20,38 @@ import org.jline.reader.LineReaderBuilder;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
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 final VelocityServer server;
|
||||||
|
private PermissionFunction permissionFunction = PermissionFunction.ALWAYS_TRUE;
|
||||||
|
|
||||||
public VelocityConsole(VelocityServer server) {
|
public VelocityConsole(VelocityServer server) {
|
||||||
this.server = 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
|
@Override
|
||||||
protected LineReader buildReader(LineReaderBuilder builder) {
|
protected LineReader buildReader(LineReaderBuilder builder) {
|
||||||
return super.buildReader(builder
|
return super.buildReader(builder
|
||||||
.appName("Velocity")
|
.appName("Velocity")
|
||||||
.completer((reader, parsedLine, list) -> {
|
.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 -> {
|
o.ifPresent(offers -> {
|
||||||
for (String offer : offers) {
|
for (String offer : offers) {
|
||||||
list.add(new Candidate(offer));
|
list.add(new Candidate(offer));
|
||||||
@ -41,8 +68,8 @@ public final class VelocityConsole extends SimpleTerminalConsole {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void runCommand(String command) {
|
protected void runCommand(String command) {
|
||||||
if (!this.server.getCommandManager().execute(this.server.getConsoleCommandSource(), command)) {
|
if (!this.server.getCommandManager().execute(this, command)) {
|
||||||
server.getConsoleCommandSource().sendMessage(TextComponent.of("Command not found.", TextColor.RED));
|
sendMessage(TextComponent.of("Command not found.", TextColor.RED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren