From 151f95d7fac356af226771124986b27a786de615 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 28 May 2021 10:49:27 +0200 Subject: [PATCH] :sparkles: Add /servers command Add a command that displays all servers --- README.md | 4 +- src/main/java/de/strifel/VTools/VTools.java | 1 + .../VTools/commands/CommandServers.java | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/strifel/VTools/commands/CommandServers.java diff --git a/README.md b/README.md index 94886ae..32ca65d 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,6 @@ Tools for Velocity proxy server. |/find|See on which server a user is|vtools.find and vtools.find.autocomplete| |/send|Send a user to a different server|vtools.send| |/sendall|Send all users to a specific server|vtools.sendall| -|/staffchat|Chat over multiple servers in a staff only chat|vtools.staffchat| \ No newline at end of file +|/staffchat|Chat over multiple servers in a staff only chat|vtools.staffchat| +|/staffchat c:channelname|Chat over multiple servers in a staff only chat in a specific extra permissions channel|vtools.staffchat.channelname| +|/servers|List all servers|vtools.servers| \ No newline at end of file diff --git a/src/main/java/de/strifel/VTools/VTools.java b/src/main/java/de/strifel/VTools/VTools.java index 9b42755..b1f65f0 100644 --- a/src/main/java/de/strifel/VTools/VTools.java +++ b/src/main/java/de/strifel/VTools/VTools.java @@ -28,6 +28,7 @@ public class VTools { server.getCommandManager().register(new CommandStaffChat(server), "staffchat", "sc"); server.getCommandManager().register(new CommandRestart(server), "restart"); server.getCommandManager().register(new CommandTp(server), "tps", "jump"); + server.getCommandManager().register(new CommandServers(server), "servers", "allservers"); } } diff --git a/src/main/java/de/strifel/VTools/commands/CommandServers.java b/src/main/java/de/strifel/VTools/commands/CommandServers.java new file mode 100644 index 0000000..dea2f66 --- /dev/null +++ b/src/main/java/de/strifel/VTools/commands/CommandServers.java @@ -0,0 +1,41 @@ +package de.strifel.VTools.commands; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.ArrayList; +import java.util.List; + +public class CommandServers implements Command { + private final ProxyServer server; + + public CommandServers(ProxyServer server) { + this.server = server; + } + + + @Override + public void execute(CommandSource commandSource, @NonNull String[] strings) { + StringBuilder servers = new StringBuilder(); + for (RegisteredServer server : server.getAllServers()) { + servers.append(server.getServerInfo().getName()); + servers.append(" "); + } + commandSource.sendMessage(TextComponent.of(servers.toString()).color(TextColor.YELLOW)); + } + + @Override + public List suggest(CommandSource source, @NonNull String[] currentArgs) { + return new ArrayList(); + } + + @Override + public boolean hasPermission(CommandSource source, @NonNull String[] args) { + return source.hasPermission("vtools.find"); + } +}