From 63dcc56735b9863fb229350bc09e01ece574115c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 7 Sep 2019 17:09:36 -0400 Subject: [PATCH] Also sort servers for /glist all --- .../proxy/command/BuiltinCommandUtil.java | 21 +++++++++++++++++++ .../proxy/command/GlistCommand.java | 2 +- .../proxy/command/ServerCommand.java | 3 +-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/command/BuiltinCommandUtil.java diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/BuiltinCommandUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/command/BuiltinCommandUtil.java new file mode 100644 index 000000000..4d5ee1414 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/BuiltinCommandUtil.java @@ -0,0 +1,21 @@ +package com.velocitypowered.proxy.command; + +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +class BuiltinCommandUtil { + + private BuiltinCommandUtil() { + throw new AssertionError(); + } + + static List sortedServerList(ProxyServer proxy) { + List servers = new ArrayList<>(proxy.getAllServers()); + servers.sort(Comparator.comparing(RegisteredServer::getServerInfo)); + return Collections.unmodifiableList(servers); + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/GlistCommand.java index f520e1131..2c7ddf9a6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/GlistCommand.java @@ -35,7 +35,7 @@ public class GlistCommand implements Command { } else if (args.length == 1) { String arg = args[0]; if (arg.equalsIgnoreCase("all")) { - for (RegisteredServer server : server.getAllServers()) { + for (RegisteredServer server : BuiltinCommandUtil.sortedServerList(server)) { sendServerPlayers(source, server, true); } sendTotalProxyCount(source); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java index e209ca893..b94cc34fb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java @@ -63,8 +63,7 @@ public class ServerCommand implements Command { // Assemble the list of servers as components TextComponent.Builder serverListBuilder = TextComponent.builder("Available servers: ") .color(TextColor.YELLOW); - List servers = new ArrayList<>(server.getAllServers()); - servers.sort(Comparator.comparing(RegisteredServer::getServerInfo)); + List servers = BuiltinCommandUtil.sortedServerList(server); for (int i = 0; i < servers.size(); i++) { RegisteredServer rs = servers.get(i); serverListBuilder.append(formatServerComponent(currentServer, rs));