From d1955da8137496da548071fe97fcf8d7119e8b0e Mon Sep 17 00:00:00 2001 From: Jerry Date: Sun, 28 May 2023 14:13:55 +0800 Subject: [PATCH] fix /server --- src/main/java/de/strifel/VTools/VTools.java | 2 +- .../VTools/commands/CommandServer.java | 29 +++++++++++++------ .../VTools/listeners/utils/GlistUtil.java | 6 ++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java index 092ab76..5b84099 100644 --- a/src/main/java/de/strifel/VTools/VTools.java +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -40,7 +40,7 @@ public class VTools { server.getCommandManager().register("staffchat", new CommandStaffChat(server), "sc"); server.getCommandManager().register("restart", new CommandRestart(server)); server.getCommandManager().register("tps", new CommandTp(server), "jump"); - server.getCommandManager().register("server", new CommandServer(server)); + server.getCommandManager().register("server", new CommandServer(server), "serverv"); server.getCommandManager().register("servers", new CommandServers(server), "allservers"); new TGBridge(this).register(); new PlayerStatus(this).register(); diff --git a/src/main/java/de/strifel/VTools/commands/CommandServer.java b/src/main/java/de/strifel/VTools/commands/CommandServer.java index 7231e9c..d42e47f 100644 --- a/src/main/java/de/strifel/VTools/commands/CommandServer.java +++ b/src/main/java/de/strifel/VTools/commands/CommandServer.java @@ -1,10 +1,12 @@ package de.strifel.VTools.commands; -import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import de.strifel.VTools.commands.utils.ServerUtil; +import net.kyori.adventure.text.Component; + +import static de.strifel.VTools.VTools.COLOR_RED; public class CommandServer extends ServerUtil implements SimpleCommand { @@ -16,15 +18,24 @@ public class CommandServer extends ServerUtil implements SimpleCommand { } @Override - public boolean hasPermission(Invocation commandInvocation) { - CommandSource invocationSource = commandInvocation.source(); - if (invocationSource.hasPermission("vtools.servertp.auto") && invocationSource instanceof Player) { - Player player = (Player)invocationSource; - if (server.getAllPlayers().stream().anyMatch(p -> p.hasPermission("vtools.send") && p.hasPermission("vtools.send.revcmsg"))) { - return true; + public void execute(final SimpleCommand.Invocation invocation) { + if (invocation.source() instanceof Player) { + if ( + invocation.source().hasPermission("velocity.command.server") || + server.getAllPlayers().stream().anyMatch(p -> p.hasPermission("vtools.send") && p.hasPermission("vtools.send.recvmsg"))) { + super.execute(invocation); + } + else { + invocation.source().sendMessage(Component.text("Supervisor offline.").color(COLOR_RED)); } - return false; } - else return invocationSource.hasPermission("vtools.servertp"); + else { + invocation.source().sendMessage(Component.text("Command is only for players.").color(COLOR_RED)); + } + } + + @Override + public boolean hasPermission(Invocation commandInvocation) { + return commandInvocation.source().hasPermission("vtools.server.auto"); } } diff --git a/src/main/java/de/strifel/VTools/listeners/utils/GlistUtil.java b/src/main/java/de/strifel/VTools/listeners/utils/GlistUtil.java index 96cdb96..6bde375 100644 --- a/src/main/java/de/strifel/VTools/listeners/utils/GlistUtil.java +++ b/src/main/java/de/strifel/VTools/listeners/utils/GlistUtil.java @@ -54,10 +54,12 @@ public class GlistUtil { TextComponent.Builder builder = Component.text() .append(Component.text("[" + server.getServerInfo().getName() + "] ", - NamedTextColor.DARK_AQUA)) + NamedTextColor.DARK_AQUA) + .clickEvent(ClickEvent.runCommand("/server " + server.getServerInfo().getName())) + + ) .append(Component.text("(" + onServer.size() + ")", NamedTextColor.GRAY)) .append(Component.text(": ")) - .clickEvent(ClickEvent.runCommand("/server " + server.getServerInfo().getName())) .resetStyle(); for (int i = 0; i < onServer.size(); i++) {