mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-07 17:28:03 +08:00
improved /plan servers command
This commit is contained in:
parent
6d941766f1
commit
be08b73eb1
@ -3,6 +3,7 @@ package com.djrapitops.plan.command.commands;
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.locale.Msg;
|
||||
@ -12,7 +13,7 @@ import com.djrapitops.plugin.command.ISender;
|
||||
import com.djrapitops.plugin.command.SubCommand;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This SubCommand is used to list all servers found in the database.
|
||||
@ -40,9 +41,9 @@ public class ListServersCommand extends SubCommand {
|
||||
String tCol = colorScheme.getTertiaryColor();
|
||||
try {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString() + mCol + " Servers");
|
||||
Map<Integer, String> serverNames = Database.getActive().fetch().getServerNamesByID();
|
||||
for (Map.Entry<Integer, String> entry : serverNames.entrySet()) {
|
||||
sender.sendMessage(" " + tCol + entry.getKey() + sCol + " : " + entry.getValue());
|
||||
List<Server> servers = Database.getActive().fetch().getServers();
|
||||
for (Server server : servers) {
|
||||
sender.sendMessage(" " + tCol + server.getId() + sCol + " : " + server.getName() + " : " + server.getWebAddress());
|
||||
}
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
} catch (DBException e) {
|
||||
|
@ -84,4 +84,6 @@ public interface FetchOperations {
|
||||
Map<Integer, String> getServerNamesByID() throws DBException;
|
||||
|
||||
Map<UUID, Map<UUID, List<Session>>> getSessionsInLastMonth() throws DBException;
|
||||
|
||||
List<Server> getServers() throws DBException;
|
||||
}
|
||||
|
@ -395,4 +395,16 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
throw SQLErrorUtil.getExceptionFor(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Server> getServers() throws DBException {
|
||||
Map<UUID, Server> bukkitServers = getBukkitServers();
|
||||
Optional<Server> bungeeInformation = getBungeeInformation();
|
||||
|
||||
List<Server> servers = new ArrayList<>(bukkitServers.values());
|
||||
bungeeInformation.ifPresent(servers::add);
|
||||
|
||||
Collections.sort(servers);
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class Server {
|
||||
public class Server implements Comparable<Server> {
|
||||
private final UUID uuid;
|
||||
private int id;
|
||||
private String name;
|
||||
@ -85,4 +85,9 @@ public class Server {
|
||||
", maxPlayers=" + maxPlayers +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Server other) {
|
||||
return Integer.compare(this.id, other.id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user