Rewrite the info command

The info command can now display information about proxies, hosts and servers (not just SubServers)
This commit is contained in:
ME1312 2018-08-10 00:50:10 -04:00
parent 545565512b
commit 215097976c
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
29 changed files with 1536 additions and 349 deletions

View File

@ -97,7 +97,7 @@ public class ExternalSubCreator extends SubCreator {
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"), false);
if (!server.getBoolean("Editable", true)) subserver.setEditable(true);
if (server.getBoolean("Editable", true)) subserver.setEditable(true);
if (server.getBoolean("Auto-Restart")) subserver.setAutoRestart(true);
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
for (String group : server.getStringList("Group")) subserver.addGroup(group);

View File

@ -75,11 +75,15 @@ public class InternalSubCreator extends SubCreator {
history.add(template);
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
if (templates.keySet().contains(other.toLowerCase())) {
YAMLSection config = build(thread, dir, other, templates.get(other.toLowerCase()), version, history);
if (config == null) {
throw new SubCreatorException();
if (templates.get(other.toLowerCase()).isEnabled()) {
YAMLSection config = build(thread, dir, other, templates.get(other.toLowerCase()), version, history);
if (config == null) {
throw new SubCreatorException();
} else {
server.setAll(config);
}
} else {
server.setAll(config);
System.out.println(name + File.separator + "Creator > Skipping disabled template: " + other);
}
} else {
System.out.println(name + File.separator + "Creator > Skipping missing template: " + other);
@ -232,7 +236,7 @@ public class InternalSubCreator extends SubCreator {
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"), false);
if (!server.getBoolean("Editable", true)) subserver.setEditable(true);
if (server.getBoolean("Editable", true)) subserver.setEditable(true);
if (server.getBoolean("Auto-Restart")) subserver.setAutoRestart(true);
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
for (String group : server.getStringList("Group")) subserver.addGroup(group);

View File

@ -16,9 +16,11 @@ Lang:
'Command.Generic.Exception': '&cSubServers &4&l\u00BB&c An unexpected exception has occurred while parsing this command'
'Command.Generic.Invalid-Subcommand': '&cSubServers &4&l\u00BB&c Unknown sub-command: $str$'
'Command.Generic.Invalid-Permission': '&cSubServers &4&l\u00BB&c You need &4&n$str$&c to use this command'
'Command.Generic.Unknown-Host': '&cSubServers &4&l\u00BB&c There is no Host with that name'
'Command.Generic.Unknown-Server': '&cSubServers &4&l\u00BB&c There is no Server with that name'
'Command.Generic.Unknown-SubServer': '&cSubServers &4&l\u00BB&c There is no SubServer with that name'
'Command.Generic.Unknown-Proxy': '&cSubServers &4&l\u00BB&c There is no proxy with that name'
'Command.Generic.Unknown-Host': '&cSubServers &4&l\u00BB&c There is no host with that name'
'Command.Generic.Unknown-Group': '&cSubServers &4&l\u00BB&c There is no group with that name'
'Command.Generic.Unknown-Server': '&cSubServers &4&l\u00BB&c There is no server with that name'
'Command.Generic.Unknown-SubServer': '&cSubServers &4&l\u00BB&c There is no subserver with that name'
'Command.Help.Header': '&7SubServers &8&l\u00BB&7 Command Help:'
'Command.Help.Help': ' &7Help:&f $str$'
'Command.Help.List': ' &7List:&f $str$'
@ -40,11 +42,15 @@ Lang:
'Command.List.Header': '&7: '
'Command.List.Divider': '&7, '
'Command.List.Empty': '&7(none)'
'Command.Info': '&7SubServers &8&l\u00BB&7 Info on &f$str$&7:'
'Command.Info.Unknown': '&cSubServers &4&l\u00BB&c There is no Server with that name'
'Command.Info.Invalid': '&cSubServers &4&l\u00BB&c That Server is not a SubServer'
'Command.Info.Format': '- &f$str$&7: &r'
'Command.Info.List': ' - $str$'
'Command.Info': '&7SubServers &8&l\u00BB&7 Info on $str$&7: &r'
'Command.Info.Unknown': '&cSubServers &4&l\u00BB&c There is no object with that name'
'Command.Info.Unknown-Type': '&cSubServers &4&l\u00BB&c There is no object type with that name'
'Command.Info.Unknown-Proxy': '&cSubServers &4&l\u00BB&c There is no proxy with that name'
'Command.Info.Unknown-Host': '&cSubServers &4&l\u00BB&c There is no host with that name'
'Command.Info.Unknown-Group': '&cSubServers &4&l\u00BB&c There is no group with that name'
'Command.Info.Unknown-Server': '&cSubServers &4&l\u00BB&c There is no server with that name'
'Command.Info.Format': ' -> &7$str$&7: &r'
'Command.Info.List': ' - '
'Command.Start': '&aSubServers &2&l\u00BB&a Starting SubServer'
'Command.Start.Unknown': '&cSubServers &4&l\u00BB&c There is no Server with that name'
'Command.Start.Invalid': '&cSubServers &4&l\u00BB&c That Server is not a SubServer'

View File

@ -7,6 +7,7 @@ import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
import net.ME1312.SubServers.Bungee.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
@ -229,38 +230,130 @@ public final class SubCommand extends CommandX {
}
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
if (args.length > 1) {
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(args[1].toLowerCase())) {
sender.sendMessage("SubServers > There is no server with that name");
} else if (!(servers.get(args[1].toLowerCase()) instanceof SubServer)) {
sender.sendMessage("SubServers > That Server is not a SubServer");
} else {
SubServer server = (SubServer) servers.get(args[1].toLowerCase());
sender.sendMessage("SubServers > Info on " + server.getDisplayName() + ':');
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" - Real Name: " + server.getName());
sender.sendMessage(" - Host: " + server.getHost().getDisplayName() + ((!server.getHost().getName().equals(server.getHost().getDisplayName()))?" ("+server.getHost().getName()+')':""));
sender.sendMessage(" - Enabled: " + ((server.isEnabled())?"yes":"no"));
sender.sendMessage(" - Editable: " + ((server.isEditable())?"yes":"no"));
if (server.getGroups().size() > 0) {
sender.sendMessage(" - Groups:");
for (String group : server.getGroups()) sender.sendMessage(" - " + group);
}
if (server.isTemporary()) sender.sendMessage(" - Temporary: yes");
sender.sendMessage(" - Running: " + ((server.isRunning())?"yes":"no"));
sender.sendMessage(" - Logging: " + ((server.isLogging())?"yes":"no"));
sender.sendMessage(" - Address: " + server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort());
sender.sendMessage(" - Auto Restart: " + ((server.willAutoRestart())?"yes":"no"));
sender.sendMessage(" - Hidden: " + ((server.isHidden())?"yes":"no"));
if (server.getIncompatibilities().size() > 0) {
List<SubServer> current = server.getCurrentIncompatibilities();
sender.sendMessage(" - Incompatibilities:");
for (SubServer other : server.getIncompatibilities()) sender.sendMessage(" - " + other.getDisplayName() + ((current.contains(other))?"*":"") + ((!other.getName().equals(other.getDisplayName()))?" ("+other.getName()+')':""));
}
sender.sendMessage(" - Signature: " + server.getSignature());
String type = (args.length > 2)?args[1]:null;
String name = args[(type != null)?2:1];
Runnable getServer = () -> {
Server server = plugin.api.getServer(name);
if (server != null) {
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + ChatColor.WHITE + server.getDisplayName());
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + server.getName());
if (server instanceof SubServer) {
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + ChatColor.RED + "no");
sender.sendMessage(" -> Host: " + ChatColor.WHITE + ((SubServer) server).getHost().getName());
}
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + ChatColor.WHITE + server.getGroups().get(0)));
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + ChatColor.WHITE + group);
sender.sendMessage(" -> Address: " + ChatColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
sender.sendMessage(" -> Connected: " + ((server.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Players: " + ChatColor.AQUA + server.getPlayers().size() + " online");
}
sender.sendMessage(" -> MOTD: " + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + server.getSignature());
if (server instanceof SubServer) {
sender.sendMessage(" -> Logging: " + ((((SubServer) server).isLogging())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (((SubServer) server).isTemporary()) sender.sendMessage(" -> Temporary: " + ChatColor.GREEN + "yes");
else sender.sendMessage(" -> Auto Restart: " + ((((SubServer) server).willAutoRestart())?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
}
sender.sendMessage(" -> Restricted: " + ((server.isRestricted())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (SubServer other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.getName().toLowerCase());
sender.sendMessage(" -> Incompatibilities:");
for (SubServer other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(" - " + ((current.contains(other.getName().toLowerCase()))?ChatColor.WHITE:ChatColor.GRAY) + other);
}
sender.sendMessage(" -> Hidden: " + ((server.isHidden())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
} else {
if (type == null) {
sender.sendMessage("SubServers > There is no object with that name");
} else {
sender.sendMessage("SubServers > There is no server with that name");
}
}
};
Runnable getGroup = () -> {
List<Server> group = plugin.api.getGroup(name);
if (group != null) {
sender.sendMessage("SubServers > Info on Group: " + ChatColor.WHITE + name);
sender.sendMessage(" -> Servers: " + ((group.size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.size()));
for (Server server : group) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
} else {
if (type == null) {
getServer.run();
} else {
sender.sendMessage("SubServers > There is no group with that name");
}
}
};
Runnable getHost = () -> {
Host host = plugin.api.getHost(name);
if (host != null) {
sender.sendMessage("SubServers > Info on Host: " + ChatColor.WHITE + host.getDisplayName());
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + host.getName());
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Address: " + ChatColor.WHITE + host.getAddress().getHostAddress());
if (host instanceof ClientHandler && ((ClientHandler) host).getSubData() != null) sender.sendMessage(" -> Connected: " + ChatColor.GREEN + "yes");
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(" - " + ((template.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + host.getSignature());
} else {
if (type == null) {
getGroup.run();
} else {
sender.sendMessage("SubServers > There is no host with that name");
}
}
};
Runnable getProxy = () -> {
Proxy proxy = plugin.api.getProxy(name);
if (proxy != null) {
sender.sendMessage("SubServers > Info on Proxy: " + ChatColor.WHITE + proxy.getDisplayName());
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
sender.sendMessage(" -> Connected: " + ((proxy.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
} else {
if (type == null) {
getHost.run();
} else {
sender.sendMessage("SubServers > There is no proxy with that name");
}
}
};
if (type == null) {
getProxy.run();
} else {
switch (type.toLowerCase()) {
case "p":
case "proxy":
getProxy.run();
break;
case "h":
case "host":
getHost.run();
break;
case "g":
case "group":
getGroup.run();
break;
case "s":
case "server":
case "subserver":
getServer.run();
break;
default:
sender.sendMessage("SubServers > There is no object type with that name");
}
}
} else {
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <SubServer>");
sender.sendMessage("SubServers > Usage: " + label + " " + args[1].toLowerCase() + " [proxy|host|group|server] <Name>");
}
} else if (args[0].equalsIgnoreCase("start")) {
if (args.length > 1) {
@ -422,7 +515,7 @@ public final class SubCommand extends CommandX {
" List: /sub list",
" Version: /sub version",
" Reload: /sub reload [all|configs|templates]",
" Server Info: /sub info <SubServer>",
" Info: /sub info [proxy|host|group|server] <Name>",
" Start Server: /sub start <SubServer>",
" Stop Server: /sub stop <SubServer>",
" Terminate Server: /sub kill <SubServer>",
@ -457,8 +550,103 @@ public final class SubCommand extends CommandX {
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
}
} else {
if (args[0].equals("info") || args[0].equals("status") ||
args[0].equals("start") ||
if (args[0].equals("info") || args[0].equals("status")) {
if (args.length == 2) {
List<String> list = new ArrayList<String>();
List<String> subcommands = new ArrayList<String>();
subcommands.add("proxy");
subcommands.add("host");
subcommands.add("group");
subcommands.add("server");
if (last.length() == 0) {
list.addAll(subcommands);
for (Proxy proxy : plugin.api.getProxies().values()) if (!list.contains(proxy.getName())) list.add(proxy.getName());
for (Host host : plugin.api.getHosts().values()) if (!list.contains(host.getName())) list.add(host.getName());
for (String group : plugin.api.getGroups().keySet()) if (!list.contains(group)) list.add(group);
for (Server server : plugin.api.getServers().values()) if (!list.contains(server.getName())) list.add(server.getName());
} else {
for (String command : subcommands) {
if (!list.contains(command) && command.toLowerCase().startsWith(last))
list.add(last + command.substring(last.length()));
}
for (Proxy proxy : plugin.api.getProxies().values()) {
if (!list.contains(proxy.getName()) && proxy.getName().toLowerCase().startsWith(last))
list.add(last + proxy.getName().substring(last.length()));
}
for (Host host : plugin.api.getHosts().values()) {
if (!list.contains(host.getName()) && host.getName().toLowerCase().startsWith(last))
list.add(last + host.getName().substring(last.length()));
}
for (String group : plugin.api.getGroups().keySet()) {
if (!list.contains(group) && group.toLowerCase().startsWith(last))
list.add(last + group.substring(last.length()));
}
for (Server server : plugin.api.getServers().values()) {
if (!list.contains(server.getName()) && server.getName().toLowerCase().startsWith(last))
list.add(last + server.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
if (last.length() == 0) {
switch (args[1].toLowerCase()) {
case "p":
case "proxy":
for (Proxy proxy : plugin.api.getProxies().values()) list.add(proxy.getName());
break;
case "h":
case "host":
for (Host host : plugin.api.getHosts().values()) list.add(host.getName());
break;
case "g":
case "group":
list.addAll(plugin.api.getGroups().keySet());
break;
case "s":
case "server":
case "subserver":
for (Server server : plugin.api.getServers().values()) list.add(server.getName());
break;
}
} else {
switch (args[1].toLowerCase()) {
case "p":
case "proxy":
for (Proxy proxy : plugin.api.getProxies().values()) {
if (!list.contains(proxy.getName()) && proxy.getName().toLowerCase().startsWith(last))
list.add(last + proxy.getName().substring(last.length()));
}
break;
case "h":
case "host":
for (Host host : plugin.api.getHosts().values()) {
if (host.getName().toLowerCase().startsWith(last))
list.add(last + host.getName().substring(last.length()));
}
break;
case "g":
case "group":
for (String group : plugin.api.getGroups().keySet()) {
if (group.toLowerCase().startsWith(last))
list.add(last + group.substring(last.length()));
}
break;
case "s":
case "server":
case "subserver":
for (Server server : plugin.api.getServers().values()) {
if (server.getName().toLowerCase().startsWith(last))
list.add(last + server.getName().substring(last.length()));
}
break;
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
}
} else if (args[0].equals("start") ||
args[0].equals("stop") ||
args[0].equals("kill") || args[0].equals("terminate")) {
List<String> list = new ArrayList<String>();

View File

@ -377,7 +377,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
int subservers = 0;
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading SubServers...");
if (!posted) Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (!running) {
if (running) {
System.out.println("SubServers > Received request from system to shutdown");
try {
shutdown();

View File

@ -400,7 +400,7 @@ public class InternalUIRenderer extends UIRenderer {
block = createItem("STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", (short) 5);
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GREEN + plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Version"));
blockMeta.setLore(Arrays.asList(ChatColor.GRAY + "v" + options.getVersion().toString()));
blockMeta.setLore(Arrays.asList(ChatColor.GRAY + "Minecraft " + options.getVersion().toString()));
}
block.setItemMeta(blockMeta);
inv.setItem(32, block);

View File

@ -272,6 +272,15 @@ public class Host {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Host
*
* @return Raw Host
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -138,6 +138,15 @@ public class Proxy {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Proxy
*
* @return Raw Proxy
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -141,6 +141,15 @@ public class Server {
return timestamp;
}
/**
* Get the raw representation of the Server
*
* @return Raw Server
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -10,6 +10,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.*;
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private Host host = null;
/**
@ -37,6 +38,13 @@ public class SubServer extends Server {
return obj instanceof SubServer && super.equals(obj);
}
@Override
public void refresh() {
host = null;
incompatibilities = null;
super.refresh();
}
/**
* Starts the Server
*
@ -231,6 +239,15 @@ public class SubServer extends Server {
return raw.getBoolean("running");
}
/**
* Grabs the Host of the Server
*
* @return The Host Name
*/
public String getHost() {
return raw.getRawString("host");
}
/**
* Grabs the Host of the Server
*
@ -345,6 +362,40 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible-list"));
}
/**
* Get all listed incompatibilities for this Server
*
* @param callback Incompatibility List
*/
public void getIncompatibilities(Callback<List<SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
Runnable run = () -> {
try {
callback.run(incompatibilities);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
};
if (incompatibilities == null) {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatableNames.add(subserver.toLowerCase());
SubAPI.getInstance().getSubServers(subservers -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (SubServer subserver : subservers.values())
if (incompatableNames.contains(subserver.getName().toLowerCase()))
incompatibilities.add(subserver);
this.incompatibilities = incompatibilities;
run.run();
});
} else {
run.run();
}
}
/**
* Get incompatibility issues this server currently has
*
@ -354,6 +405,24 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible"));
}
/**
* Get incompatibility issues this server currently has
*
* @param callback Current Incompatibility List
*/
public void getCurrentIncompatibilities(Callback<List<SubServer>> callback) {
getIncompatibilities(incompatibilities -> {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatableNames.add(subserver.toLowerCase());
LinkedList<SubServer> current = new LinkedList<SubServer>();
for (SubServer subserver : incompatibilities)
if (incompatableNames.contains(subserver.getName().toLowerCase()))
current.add(subserver);
callback.run(current);
});
}
/**
* If the Server is Temporary
*

View File

@ -4,10 +4,7 @@ import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
import net.ME1312.SubServers.Client.Bukkit.Network.API.Proxy;
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
import net.ME1312.SubServers.Client.Bukkit.Network.API.*;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -180,49 +177,127 @@ public final class SubCommand implements CommandExecutor {
}
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
if (args.length > 1) {
plugin.api.getServer(args[1], subserver -> {
if (subserver == null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown"));
} else if (!(subserver instanceof SubServer)) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Invalid"));
} else ((SubServer) subserver).getHost(host -> {
if (host == null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Invalid"));
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", subserver.getDisplayName()));
if (!subserver.getName().equals(subserver.getDisplayName()))
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name") + ChatColor.AQUA + subserver.getName());
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host") + ChatColor.AQUA + host.getName());
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((((SubServer) subserver).isEnabled())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable") + ((((SubServer) subserver).isEditable())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
if (subserver.getGroups().size() > 0) {
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group"));
for (String group : subserver.getGroups())
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ChatColor.GOLD + group));
}
if (((SubServer) subserver).isTemporary()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary") + ChatColor.GREEN+"yes");
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((((SubServer) subserver).isRunning())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging") + ((((SubServer) subserver).isLogging())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.AQUA + subserver.getAddress().getAddress().getHostAddress());
} else {
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA + subserver.getAddress().getPort());
}
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart") + ((((SubServer) subserver).willAutoRestart())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden") + ((subserver.isHidden())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
if (((SubServer) subserver).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) subserver).getCurrentIncompatibilities()) current.add(other.toLowerCase());
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities"));
for (String other : ((SubServer) subserver).getIncompatibilities())
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ((current.contains(other.toLowerCase()))?ChatColor.DARK_RED:ChatColor.RED) + other));
}
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + subserver.getSignature());
String type = (args.length > 2)?args[1]:null;
String name = args[(type != null)?2:1];
Runnable getServer = () -> plugin.api.getServer(name, server -> {
if (server != null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", ((server instanceof SubServer)?"Sub":"") + "Server") + ChatColor.WHITE + server.getDisplayName());
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + server.getName());
if (server instanceof SubServer) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!((SubServer) server).isEditable()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable") + ChatColor.RED + "no");
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host") + ChatColor.WHITE + ((SubServer) server).getHost());
}
});
if (server.getGroups().size() > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":"")) + ((server.getGroups().size() > 1)?"":ChatColor.WHITE + server.getGroups().get(0)));
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ChatColor.WHITE + group);
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA.toString() + server.getAddress().getPort());
if (server instanceof SubServer) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((server.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + server.getPlayers().size() + " online");
}
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD") + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + server.getSignature());
if (server instanceof SubServer) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging") + ((((SubServer) server).isLogging())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (((SubServer) server).isTemporary()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary") + ChatColor.GREEN + "yes");
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart") + ((((SubServer) server).willAutoRestart())?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
}
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Restricted") + ((server.isRestricted())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities"));
for (String other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((current.contains(other.toLowerCase()))?ChatColor.WHITE:ChatColor.GRAY) + other);
}
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden") + ((server.isHidden())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
} else {
if (type == null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown"));
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Server"));
}
}
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Group") + ChatColor.WHITE + name);
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers") + ((group.size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.size()));
for (Server server : group) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
} else {
if (type == null) {
getServer.run();
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Group"));
}
}
});
Runnable getHost = () -> plugin.api.getHost(name, host -> {
if (host != null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Host") + ChatColor.WHITE + host.getDisplayName());
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + host.getName());
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + host.getAddress().getHostAddress());
if (host.getSubData() != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ChatColor.GREEN + "yes");
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers") + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates") + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((template.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + host.getSignature());
} else {
if (type == null) {
getGroup.run();
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Host"));
}
}
});
Runnable getProxy = () -> plugin.api.getProxy(name, proxy -> {
if (proxy != null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy") + ChatColor.WHITE + proxy.getDisplayName());
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + proxy.getName());
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
if (proxy.isRedis()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + proxy.getPlayers().size() + " online");
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + proxy.getSignature());
} else {
if (type == null) {
getHost.run();
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Proxy"));
}
}
});
if (type == null) {
getProxy.run();
} else {
switch (type.toLowerCase()) {
case "p":
case "proxy":
getProxy.run();
break;
case "h":
case "host":
getHost.run();
break;
case "g":
case "group":
getGroup.run();
break;
case "s":
case "server":
case "subserver":
getServer.run();
break;
default:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Type"));
}
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <SubServer>"));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " [proxy|host|group|server] <Name>"));
}
} else if (args[0].equalsIgnoreCase("start")) {
if (args.length > 1) {
@ -477,7 +552,7 @@ public final class SubCommand implements CommandExecutor {
plugin.api.getLang("SubServers", "Command.Help.Help").replace("$str$", label.toLowerCase() + " help"),
plugin.api.getLang("SubServers", "Command.Help.List").replace("$str$", label.toLowerCase() + " list"),
plugin.api.getLang("SubServers", "Command.Help.Version").replace("$str$", label.toLowerCase() + " version"),
plugin.api.getLang("SubServers", "Command.Help.Info").replace("$str$", label.toLowerCase() + " info <SubServer>"),
plugin.api.getLang("SubServers", "Command.Help.Info").replace("$str$", label.toLowerCase() + " info [proxy|host|group|server] <Name>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Start").replace("$str$", label.toLowerCase() + " start <SubServer>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Stop").replace("$str$", label.toLowerCase() + " stop <SubServer>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", label.toLowerCase() + " kill <SubServer>"),

View File

@ -0,0 +1,169 @@
package net.ME1312.SubServers.Client.Sponge.Library;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyle;
import org.spongepowered.api.text.format.TextStyles;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.regex.Pattern;
/**
* Color Code Converter Enum
*/
public enum ChatColor {
AQUA('b', TextColors.AQUA),
BLACK('0', TextColors.BLACK),
BLUE('9', TextColors.BLUE),
BOLD('l', TextStyles.BOLD),
DARK_AQUA('3', TextColors.DARK_AQUA),
DARK_BLUE('1', TextColors.DARK_BLUE),
DARK_GRAY('8', TextColors.DARK_GRAY),
DARK_GREEN('2', TextColors.DARK_GREEN),
DARK_PURPLE('5', TextColors.DARK_PURPLE),
DARK_RED('4', TextColors.DARK_RED),
GOLD('6', TextColors.GOLD),
GRAY('7', TextColors.GRAY),
GREEN('a', TextColors.GREEN),
ITALIC('o', TextStyles.ITALIC),
LIGHT_PURPLE('d', TextColors.LIGHT_PURPLE),
MAGIC('k', TextStyles.OBFUSCATED),
RED('c', TextColors.RED),
RESET('r', TextColors.RESET),
STRIKETHROUGH('m', TextStyles.STRIKETHROUGH),
UNDERLINE('n', TextStyles.UNDERLINE),
WHITE('f', TextColors.WHITE),
YELLOW('e', TextColors.YELLOW);
private static HashMap<Character, ChatColor> map = new HashMap<Character, ChatColor>();
private static boolean defaults = false;
private final Character minecraft;
private final TextColor color;
private final TextStyle[] style;
ChatColor(Character minecraft, TextColor color) {
this(minecraft, color, TextStyles.RESET);
}
ChatColor(Character minecraft, TextStyle... style) {
this(minecraft, null, style);
}
ChatColor(Character minecraft, TextColor color, TextStyle... style) {
this.minecraft = minecraft;
this.color = color;
this.style = style;
}
/**
* Get this color as a Minecraft Color Code
*
* @return Minecraft Color Code
*/
public String asMinecraftCode() {
return new String(new char[]{'\u00A7', minecraft});
}
/**
* Get the Sponge API equivalent of this value
*
* @return Sponge API Color (may be null for modifiers)
*/
public TextColor asTextColor() {
return color;
}
/**
* Get the styles this color applies
*
* @return Sponge API Styles
*/
public TextStyle[] getStyles() {
return style;
}
@Override
public String toString() {
return asMinecraftCode();
}
/**
* Parse Minecraft color codes starting with character
*
* @param character Character
* @param str String to parse
* @return Minecraft colored string
*/
public static String parseColor(char character, String str) {
for (ChatColor color : Arrays.asList(ChatColor.values())) {
str = str.replace(new String(new char[]{character, color.minecraft}), color.asMinecraftCode());
}
return str;
}
/**
* Convert Minecraft color codes to Sponge Text
*
* @param str Minecraft colored string
* @return Sponge Text
*/
public static Text convertColor(String str) {
return convertColor('\u00A7', str);
}
/**
* Convert Minecraft color codes starting with character to Sponge Text
*
* @param character Character
* @param str String to parse
* @return Sponge Text
*/
public static Text convertColor(char character, String str) {
if (!defaults) {
for (ChatColor color : ChatColor.values()) map.put(color.minecraft, color);
defaults = true;
}
if (str.contains(Character.toString(character))) {
LinkedList<String> pieces = new LinkedList<String>(Arrays.asList(str.split(Pattern.quote(Character.toString(character)))));
Collections.reverse(pieces);
Text result = null;
int i = pieces.size();
for (String piece : pieces) {
i--;
Text.Builder current;
if (i > 0 && piece.length() > 0) {
if (map.keySet().contains(piece.toCharArray()[0])) {
current = Text.builder(piece.substring(1));
ChatColor color = map.get(piece.toCharArray()[0]);
current.style(color.getStyles());
if (color.asTextColor() != null) current.color(color.asTextColor());
} else current = Text.builder(character + piece);
} else current = Text.builder(piece);
if (result != null) {
current.append(result);
}
result = current.build();
}
if (result != null) return result;
}
return Text.of(str);
}
/**
* Removes all Minecraft color codes from a string
*
* @param str String to parse
* @return String without color
*/
public static String stripColor(String str) {
for (ChatColor color : Arrays.asList(ChatColor.values())) {
str = str.replace(color.asMinecraftCode(), "");
}
return str;
}
}

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Client.Sponge.Library.Config;
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
import net.ME1312.SubServers.Client.Sponge.Library.Util;
import org.yaml.snakeyaml.Yaml;
@ -244,7 +245,7 @@ public class YAMLValue {
*/
public String asColoredString(char color) {
if (Util.isNull(color)) throw new NullPointerException();
if (obj != null) return asString().replaceAll(Pattern.quote(new String(new char[]{color})) + "([0-9A-Fa-fK-Ok-oRr])", "\u00A7$1");
if (obj != null) return ChatColor.parseColor(color, asString());
else return null;
}
@ -259,7 +260,7 @@ public class YAMLValue {
if (Util.isNull(color)) throw new NullPointerException();
List<String> values = new ArrayList<String>();
for (String value : asStringList()) {
values.add(value.replaceAll(Pattern.quote(new String(new char[]{color})) + "([0-9A-Fa-fK-Ok-oRr])", "\u00A7$1"));
values.add(ChatColor.parseColor(color, value));
}
return values;
} else return null;

View File

@ -272,6 +272,15 @@ public class Host {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Host
*
* @return Raw Host
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -138,6 +138,15 @@ public class Proxy {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Proxy
*
* @return Raw Proxy
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -141,6 +141,15 @@ public class Server {
return timestamp;
}
/**
* Get the raw representation of the Server
*
* @return Raw Server
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -13,6 +13,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.*;
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private Host host = null;
/**
@ -40,6 +41,13 @@ public class SubServer extends Server {
return obj instanceof SubServer && super.equals(obj);
}
@Override
public void refresh() {
host = null;
incompatibilities = null;
super.refresh();
}
/**
* Starts the Server
*
@ -234,6 +242,15 @@ public class SubServer extends Server {
return raw.getBoolean("running");
}
/**
* Grabs the Host of the Server
*
* @return The Host Name
*/
public String getHost() {
return raw.getRawString("host");
}
/**
* Grabs the Host of the Server
*
@ -348,6 +365,40 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible-list"));
}
/**
* Get all listed incompatibilities for this Server
*
* @param callback Incompatibility List
*/
public void getIncompatibilities(Callback<List<SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
Runnable run = () -> {
try {
callback.run(incompatibilities);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
};
if (incompatibilities == null) {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatableNames.add(subserver.toLowerCase());
SubAPI.getInstance().getSubServers(subservers -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (SubServer subserver : subservers.values())
if (incompatableNames.contains(subserver.getName().toLowerCase()))
incompatibilities.add(subserver);
this.incompatibilities = incompatibilities;
run.run();
});
} else {
run.run();
}
}
/**
* Get incompatibility issues this server currently has
*
@ -357,6 +408,24 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible"));
}
/**
* Get incompatibility issues this server currently has
*
* @param callback Current Incompatibility List
*/
public void getCurrentIncompatibilities(Callback<List<SubServer>> callback) {
getIncompatibilities(incompatibilities -> {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatableNames.add(subserver.toLowerCase());
LinkedList<SubServer> current = new LinkedList<SubServer>();
for (SubServer subserver : incompatibilities)
if (incompatableNames.contains(subserver.getName().toLowerCase()))
current.add(subserver);
callback.run(current);
});
}
/**
* If the Server is Temporary
*

View File

@ -2,13 +2,11 @@ package net.ME1312.SubServers.Client.Sponge;
import com.google.gson.Gson;
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
import net.ME1312.SubServers.Client.Sponge.Library.Util;
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
import net.ME1312.SubServers.Client.Sponge.Network.API.Proxy;
import net.ME1312.SubServers.Client.Sponge.Network.API.Server;
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
import net.ME1312.SubServers.Client.Sponge.Network.API.*;
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
import org.spongepowered.api.Platform;
import org.spongepowered.api.Sponge;
@ -68,7 +66,7 @@ public final class SubCommand implements CommandExecutor {
.child(CommandSpec.builder()
.description(Text.of("The SubServers Command - Info"))
.executor(new INFO())
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("SubServer"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("extra"))))
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("Type"))), GenericArguments.optional(GenericArguments.string(Text.of("Name"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("extra"))))
.build(), "info", "status")
.child(CommandSpec.builder()
.description(Text.of("The SubServers Command - Start"))
@ -117,7 +115,7 @@ public final class SubCommand implements CommandExecutor {
if (canRun(sender)) {
Optional<String> subcommand = args.getOne(Text.of("subcommand"));
if (subcommand.isPresent()) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", subcommand.get())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Subcommand").replace("$str$", subcommand.get())));
return CommandResult.builder().successCount(0).build();
} else {
if (sender.hasPermission("subservers.interface") && sender instanceof Player && plugin.gui != null) {
@ -128,7 +126,7 @@ public final class SubCommand implements CommandExecutor {
return CommandResult.builder().successCount(1).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -139,7 +137,7 @@ public final class SubCommand implements CommandExecutor {
sender.sendMessages(printHelp());
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -153,7 +151,7 @@ public final class SubCommand implements CommandExecutor {
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null);
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version").replace("$str$", "SubServers.Client.Sponge")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Version").replace("$str$", "SubServers.Client.Sponge")));
sender.sendMessage(Text.builder(" " + System.getProperty("os.name") + ' ' + System.getProperty("os.version")).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" Java " + System.getProperty("java.version")).color(TextColors.WHITE).append(Text.of(",")).build());
sender.sendMessage(Text.builder(" " + container.getName() + ' ' + container.getVersion().get()).color(TextColors.WHITE).append(Text.of(",")).build());
@ -175,15 +173,15 @@ public final class SubCommand implements CommandExecutor {
}
}
if (updcount == 0) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version.Latest")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Version.Latest")));
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version.Outdated").replace("$name$", "SubServers.Client.Sponge").replace("$str$", updversion.toString()).replace("$int$", Integer.toString(updcount))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Version.Outdated").replace("$name$", "SubServers.Client.Sponge").replace("$str$", updversion.toString()).replace("$int$", Integer.toString(updcount))));
}
} catch (Exception e) {}
}).submit(plugin);
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -195,15 +193,15 @@ public final class SubCommand implements CommandExecutor {
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> {
int i = 0;
boolean sent = false;
Text div = Text.of(plugin.api.getLang("SubServers", "Command.List.Divider"));
Text div = ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Divider"));
if (groups.keySet().size() > 0) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Group-Header")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Group-Header")));
for (String group : groups.keySet()) {
Text.Builder msg = Text.builder(group).color(TextColors.GOLD).onHover(TextActions.showText(
Text.builder(group + '\n').color(TextColors.GOLD).append(
Text.of(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(groups.get(group).size())))
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(groups.get(group).size())))
).build())
).onClick(TextActions.runCommand("/subservers open Server 1 " + group)).append(Text.of(plugin.api.getLang("SubServers", "Command.List.Header")));
).onClick(TextActions.runCommand("/subservers open Server 1 " + group)).append(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Header")));
for (Server server : groups.get(group)) {
Text.Builder message = Text.builder(server.getDisplayName());
@ -217,8 +215,8 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n'),
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'),
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
);
} else if (((SubServer) server).isRunning()) {
message.color(TextColors.GREEN);
@ -227,7 +225,7 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())) + '\n')
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())) + '\n')
);
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
message.color(TextColors.YELLOW);
@ -236,7 +234,7 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"))
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Offline"))
);
} else {
message.color(TextColors.RED);
@ -250,10 +248,10 @@ public final class SubCommand implements CommandExecutor {
if (list.length() != 0) list += ", ";
list += other;
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n")));
}
if (!((SubServer) server).isEnabled()) {
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
}
}
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
@ -269,8 +267,8 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External") + '\n'),
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
);
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
@ -283,15 +281,15 @@ public final class SubCommand implements CommandExecutor {
msg.append(message.build());
i++;
}
if (i == 0) msg.append(Text.of(plugin.api.getLang("SubServers", "Command.List.Empty")));
if (i == 0) msg.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Empty")));
sender.sendMessages(Text.builder(" ").append(msg.build()).build());
i = 0;
sent = true;
}
if (!sent) sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
if (!sent) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
sent = false;
}
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Host-Header")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Host-Header")));
for (Host host : hosts.values()) {
Text.Builder msg = Text.builder(host.getDisplayName());
Text.Builder hover = Text.builder(host.getDisplayName() + '\n');
@ -301,21 +299,21 @@ public final class SubCommand implements CommandExecutor {
if (!host.getName().equals(host.getDisplayName())) {
hover.append(Text.builder(host.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size()))));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size()))));
} else {
msg.color(TextColors.RED);
hover.color(TextColors.RED);
if (!host.getName().equals(host.getDisplayName())) {
hover.append(Text.builder(host.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Disabled")));
}
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
hover.append(Text.builder('\n' + host.getAddress().getHostAddress()).color(TextColors.WHITE).build());
}
msg.onClick(TextActions.runCommand("/subservers open Host/ " + host.getName()));
msg.onHover(TextActions.showText(hover.build()));
msg.append(Text.of(plugin.api.getLang("SubServers", "Command.List.Header")));
msg.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Header")));
for (SubServer subserver : host.getSubServers().values()) {
Text.Builder message = Text.builder(subserver.getDisplayName());
@ -327,8 +325,8 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n'),
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())))
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'),
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())))
);
} else if (subserver.isRunning()) {
message.color(TextColors.GREEN);
@ -336,14 +334,14 @@ public final class SubCommand implements CommandExecutor {
if (!subserver.getName().equals(subserver.getDisplayName())) {
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size()))));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size()))));
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
message.color(TextColors.YELLOW);
hover.color(TextColors.YELLOW);
if (!subserver.getName().equals(subserver.getDisplayName())) {
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Offline")));
} else {
message.color(TextColors.RED);
hover.color(TextColors.RED);
@ -356,10 +354,10 @@ public final class SubCommand implements CommandExecutor {
if (list.length() != 0) list += ", ";
list += other;
}
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n")));
}
if (!subserver.isEnabled()) {
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled")));
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
}
}
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
@ -373,13 +371,13 @@ public final class SubCommand implements CommandExecutor {
msg.append(message.build());
i++;
}
if (i == 0) msg.append(Text.of(plugin.api.getLang("SubServers", "Command.List.Empty")));
if (i == 0) msg.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Empty")));
sender.sendMessage(Text.builder(" ").append(msg.build()).build());
i = 0;
sent = true;
}
if (!sent) sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Server-Header")));
if (!sent) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Server-Header")));
Text.Builder msg = Text.builder();
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
Text.Builder message = Text.builder(server.getDisplayName());
@ -390,8 +388,8 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
}
hover.append(
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External") + '\n'),
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size()))));
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size()))));
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
} else {
@ -402,10 +400,10 @@ public final class SubCommand implements CommandExecutor {
msg.append(message.build());
i++;
}
if (i == 0) sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
if (i == 0) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
else sender.sendMessage(Text.builder(" ").append(msg.build()).build());
if (proxies.keySet().size() > 0) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Proxy-Header")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.List.Proxy-Header")));
msg = Text.builder();
Text.Builder message = Text.builder("(master)");
Text.Builder hover = Text.builder("(master)");
@ -414,10 +412,10 @@ public final class SubCommand implements CommandExecutor {
if (proxymaster != null) {
hover.append(
Text.builder('\n' + proxymaster.getName()).color(TextColors.GRAY).build(),
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")),
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())))
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")),
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())))
);
} else hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")));
} else hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")));
message.onHover(TextActions.showText(hover.build()));
msg.append(message.build());
for (Proxy proxy : proxies.values()) {
@ -429,7 +427,7 @@ public final class SubCommand implements CommandExecutor {
if (!proxy.getName().equals(proxy.getDisplayName())) {
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
}
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
} else if (proxy.getSubData() != null) {
message.color(TextColors.AQUA);
hover.color(TextColors.AQUA);
@ -437,7 +435,7 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
}
if (proxymaster != null) {
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData")));
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData")));
}
} else if (proxy.isRedis()) {
message.color(TextColors.WHITE);
@ -446,8 +444,8 @@ public final class SubCommand implements CommandExecutor {
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
}
hover.append(
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")),
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())))
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")),
ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())))
);
} else {
message.color(TextColors.RED);
@ -455,7 +453,7 @@ public final class SubCommand implements CommandExecutor {
if (!proxy.getName().equals(proxy.getDisplayName())) {
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
}
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Disconnected")));
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Disconnected")));
}
message.onHover(TextActions.showText(hover.build()));
msg.append(div, message.build());
@ -465,7 +463,7 @@ public final class SubCommand implements CommandExecutor {
})))));
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -474,55 +472,141 @@ public final class SubCommand implements CommandExecutor {
public final class INFO implements CommandExecutor {
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
Optional<String> subserver = args.getOne(Text.of("SubServer"));
if (subserver.isPresent()) {
plugin.api.getServer(subserver.get(), server -> {
if (server == null) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Unknown")));
} else if (!(server instanceof SubServer)) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Invalid")));
} else ((SubServer) server).getHost(host -> {
if (host == null) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Invalid")));
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", server.getDisplayName())));
if (!server.getName().equals(server.getDisplayName()))
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name")).append(Text.builder(server.getName()).color(TextColors.AQUA).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host")).append(Text.builder(host.getName()).color(TextColors.AQUA).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).append(Text.builder((((SubServer) server).isEnabled())?"yes":"no").color((((SubServer) server).isEnabled())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable")).append(Text.builder((((SubServer) server).isEditable())?"yes":"no").color((((SubServer) server).isEditable())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
if (server.getGroups().size() > 0) {
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group")));
for (String group : server.getGroups())
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", "\u00A76" + group)));
}
if (((SubServer) server).isTemporary()) sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary")).append(Text.builder("yes").color(TextColors.GREEN).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging")).append(Text.builder((((SubServer) server).isLogging())?"yes":"no").color((((SubServer) server).isLogging())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).append(Text.builder(server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.AQUA).build()).build());
} else {
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
}
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart")).append(Text.builder((((SubServer) server).willAutoRestart())?"yes":"no").color((((SubServer) server).willAutoRestart())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden")).append(Text.builder((server.isHidden())?"yes":"no").color((server.isHidden())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
if (((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities")));
for (String other : ((SubServer) server).getIncompatibilities())
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", '\u00A7' + ((current.contains(other.toLowerCase()))?'4':'c') + other)));
}
Optional<String> t = args.getOne(Text.of("Type"));
Optional<String> n = args.getOne(Text.of("Name"));
if (!n.isPresent()) {
Optional<String> tmp = n;
n = t;
t = tmp;
}
if (n.isPresent()) {
String type = (t.isPresent())?t.get():null;
String name = n.get();
Runnable getServer = () -> plugin.api.getServer(name, server -> {
if (server != null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", ((server instanceof SubServer)?"Sub":"") + "Server")).toBuilder().append(Text.builder(server.getDisplayName()).color(TextColors.WHITE).build()).build());
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(server.getName()).color(TextColors.WHITE).build()).build());
if (server instanceof SubServer) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((((SubServer) server).isEnabled())?"yes":"no").color((((SubServer) server).isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
if (!((SubServer) server).isEditable()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable")).toBuilder().append(Text.builder("no").color(TextColors.RED).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host")).toBuilder().append(Text.builder(((SubServer) server).getHost()).color(TextColors.WHITE ).build()).build());
}
});
if (server.getGroups().size() > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":""))).toBuilder().append(Text.builder((server.getGroups().size() > 1)?"":server.getGroups().get(0)).color(TextColors.WHITE).build()).build());
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(group).color(TextColors.WHITE).build()).build());
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build()).build());
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).toBuilder().append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
if (server instanceof SubServer) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).toBuilder().append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.RED).build()).build());
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((server.getSubData() != null)?"yes":"no").color((server.getSubData() != null)?TextColors.GREEN:TextColors.RED).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(server.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
}
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD")).toBuilder().append(Text.builder(server.getMotd().replaceAll("\\u00A7[0-9a-fA-Fk-oK-ORr]", "")).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(server.getSignature()).color(TextColors.AQUA).build()).build());
if (server instanceof SubServer) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging")).toBuilder().append(Text.builder((((SubServer) server).isLogging())?"yes":"no").color((((SubServer) server).isLogging())?TextColors.GREEN:TextColors.RED).build()).build());
if (((SubServer) server).isTemporary()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary")).toBuilder().append(Text.builder("yes").color(TextColors.GREEN).build()).build());
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart")).toBuilder().append(Text.builder((((SubServer) server).willAutoRestart())?"enabled":"disabled").color((((SubServer) server).willAutoRestart())?TextColors.GREEN:TextColors.RED).build()).build());
}
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Restricted")).toBuilder().append(Text.builder((server.isRestricted())?"yes":"no").color((server.isRestricted())?TextColors.GREEN:TextColors.RED).build()).build());
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Format").replace("$str$", "Incompatibilities")));
for (String other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(other).color((current.contains(other.toLowerCase()))?TextColors.WHITE:TextColors.GRAY).build()).build());
}
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden")).toBuilder().append(Text.builder((server.isHidden())?"yes":"no").color((server.isHidden())?TextColors.GREEN:TextColors.RED).build()).build());
} else {
if (type == null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown")));
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown-Server")));
}
}
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Group")).toBuilder().append(Text.builder(name).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers")).toBuilder().append(Text.builder((group.size() <= 0)?"(none)":Integer.toString(group.size())).color((group.size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
for (Server server : group) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')')).color(TextColors.WHITE).build()).build());
} else {
if (type == null) {
getServer.run();
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown-Group")));
}
}
});
Runnable getHost = () -> plugin.api.getHost(name, host -> {
if (host != null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Host")).toBuilder().append(Text.builder(host.getDisplayName()).color(TextColors.WHITE).build()).build());
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(host.getName()).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((host.isEnabled())?"yes":"no").color((host.isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(host.getAddress().getHostAddress()).color(TextColors.WHITE).build()).build());
if (host.getSubData() != null) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder("yes").color(TextColors.GREEN).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers")).toBuilder().append(Text.builder((host.getSubServers().keySet().size() <= 0)?"(none)":Integer.toString(host.getSubServers().keySet().size())).color((host.getSubServers().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')')).color((subserver.isEnabled())?TextColors.WHITE:TextColors.GRAY).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates")).toBuilder().append(Text.builder((host.getCreator().getTemplates().keySet().size() <= 0)?"(none)":Integer.toString(host.getCreator().getTemplates().keySet().size())).color((host.getCreator().getTemplates().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')')).color((template.isEnabled())?TextColors.WHITE:TextColors.GRAY).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(host.getSignature()).color(TextColors.AQUA).build()).build());
} else {
if (type == null) {
getGroup.run();
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown-Host")));
}
}
});
Runnable getProxy = () -> plugin.api.getProxy(name, proxy -> {
if (proxy != null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy")).toBuilder().append(Text.builder(proxy.getDisplayName()).color(TextColors.WHITE).build()).build());
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(proxy.getName()).color(TextColors.WHITE ).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData() != null)?"yes":"no").color((proxy.getSubData() != null)?TextColors.GREEN:TextColors.RED).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") ).toBuilder().append(Text.builder(((proxy.isRedis())?"":"un") + "available").color((proxy.isRedis())?TextColors.GREEN:TextColors.RED).build()).build());
if (proxy.isRedis()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(proxy.getSignature()).color(TextColors.AQUA).build()).build());
} else {
if (type == null) {
getHost.run();
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown-Proxy")));
}
}
});
if (type == null) {
getProxy.run();
} else {
switch (type.toLowerCase()) {
case "p":
case "proxy":
getProxy.run();
break;
case "h":
case "host":
getHost.run();
break;
case "g":
case "group":
getGroup.run();
break;
case "s":
case "server":
case "subserver":
getServer.run();
break;
default:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Info.Unknown-Type")));
}
}
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub info <SubServer>")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub info [proxy|host|group|server] <Name>")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -537,44 +621,44 @@ public final class SubCommand implements CommandExecutor {
plugin.subdata.sendPacket(new PacketStartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), data -> {
switch (data.getInt("r")) {
case 3:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Unknown")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Unknown")));
break;
case 4:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Invalid")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Invalid")));
break;
case 5:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Host-Disabled")));
break;
case 6:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Disabled")));
break;
case 7:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Running")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Running")));
break;
case 8:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1])));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1])));
break;
case 0:
case 1:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start")));
break;
default:
plugin.logger.warn("PacketStartServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ") responded with: " + data.getString("m"));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start")));
break;
}
}));
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + subserver.get().toLowerCase())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + subserver.get().toLowerCase())));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub start <SubServer>")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub start <SubServer>")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -589,35 +673,35 @@ public final class SubCommand implements CommandExecutor {
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player) ? ((Player) sender).getUniqueId():null, subserver.get(), false, data -> {
switch (data.getInt("r")) {
case 3:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Stop.Unknown")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Unknown")));
break;
case 4:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Stop.Invalid")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Invalid")));
break;
case 5:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Stop.Not-Running")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Not-Running")));
break;
case 0:
case 1:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Stop")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop")));
break;
default:
plugin.logger.warn("PacketStopServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", false) responded with: " + data.getString("m"));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Stop")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop")));
break;
}
}));
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + subserver.get().toLowerCase())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + subserver.get().toLowerCase())));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub stop <SubServer>")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub stop <SubServer>")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -632,35 +716,35 @@ public final class SubCommand implements CommandExecutor {
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), true, data -> {
switch (data.getInt("r")) {
case 3:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Terminate.Unknown")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Unknown")));
break;
case 4:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Terminate.Invalid")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Invalid")));
break;
case 5:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Terminate.Not-Running")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Not-Running")));
break;
case 0:
case 1:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Terminate")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate")));
break;
default:
plugin.logger.warn("PacketStopServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", true) responded with: " + data.getString("m"));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Terminate")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate")));
break;
}
}));
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + subserver.get().toLowerCase())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + subserver.get().toLowerCase())));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub terminate <SubServer>")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub terminate <SubServer>")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -676,35 +760,35 @@ public final class SubCommand implements CommandExecutor {
plugin.subdata.sendPacket(new PacketCommandServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), command.get(), data -> {
switch (data.getInt("r")) {
case 3:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Command.Unknown")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Unknown")));
break;
case 4:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Command.Invalid")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Invalid")));
break;
case 5:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Command.Not-Running")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Not-Running")));
break;
case 0:
case 1:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command")));
break;
default:
plugin.logger.warn("PacketCommandServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", /" + command.get() + ") responded with: " + data.getString("m"));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Command")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command")));
break;
}
}));
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + subserver.get().toLowerCase())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + subserver.get().toLowerCase())));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub command <SubServer> <Command> [Args...]")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub command <SubServer> <Command> [Args...]")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -721,49 +805,49 @@ public final class SubCommand implements CommandExecutor {
if (name.isPresent() && host.isPresent() && template.isPresent() && version.isPresent() && port.isPresent()) {
if (sender.hasPermission("subservers.host.create." + host.get().toLowerCase())) {
if (Util.isException(() -> Integer.parseInt(port.get()))) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
return CommandResult.builder().successCount(0).build();
} else {
plugin.subdata.sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, name.get(), host.get(), template.get(), new Version(version.get()), Integer.parseInt(port.get()), data -> {
switch (data.getInt("r")) {
case 3:
case 4:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Exists")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Exists")));
break;
case 5:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Host")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Unknown-Host")));
break;
case 6:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Template")));
break;
case 7:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Version")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Version")));
break;
case 8:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
break;
case 0:
case 1:
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator")));
break;
default:
plugin.logger.warn("PacketCreateServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + name.get() + ", " + host.get() + ", " + template.get() + ", " + version.get() + ", " + port.get() + ") responded with: " + data.getString("m"));
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator")));
break;
}
}));
return CommandResult.builder().successCount(1).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + host.get().toLowerCase())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + host.get().toLowerCase())));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")));
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -821,12 +905,12 @@ public final class SubCommand implements CommandExecutor {
return CommandResult.builder().successCount(0).build();
}
} else {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.interface")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.interface")));
return CommandResult.builder().successCount(0).build();
}
} else return CommandResult.builder().successCount(0).build();
} else {
sender.sendMessage(Text.of(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"))));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
return CommandResult.builder().successCount(0).build();
}
}
@ -834,16 +918,16 @@ public final class SubCommand implements CommandExecutor {
private Text[] printHelp() {
return new Text[]{
Text.of(plugin.api.getLang("SubServers", "Command.Help.Header")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.Help").replace("$str$", "/sub help")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.List").replace("$str$", "/sub list")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.Version").replace("$str$", "/sub version")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.Info").replace("$str$", "/sub info <SubServer>")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.SubServer.Start").replace("$str$", "/sub start <SubServer>")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.SubServer.Stop").replace("$str$", "/sub stop <SubServer>")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <SubServer>")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.SubServer.Command").replace("$str$", "/sub cmd <SubServer> <Command> [Args...]")),
Text.of(plugin.api.getLang("SubServers", "Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Header")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Help").replace("$str$", "/sub help")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.List").replace("$str$", "/sub list")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Version").replace("$str$", "/sub version")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Info").replace("$str$", "/sub info [proxy|host|group|server] <Name>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Start").replace("$str$", "/sub start <SubServer>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Stop").replace("$str$", "/sub stop <SubServer>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <SubServer>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <SubServer> <Command> [Args...]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")),
};
}
}

View File

@ -196,11 +196,16 @@ public class SubCreator {
history.add(template);
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
if (host.templates.keySet().contains(other.toLowerCase())) {
YAMLSection config = build(thread, dir, other, host.templates.get(other.toLowerCase()), version, address, history);
if (config == null) {
throw new SubCreatorException();
if (host.templates.get(other.toLowerCase()).isEnabled()) {
YAMLSection config = build(thread, dir, other, host.templates.get(other.toLowerCase()), version, address, history);
if (config == null) {
throw new SubCreatorException();
} else {
server.setAll(config);
}
} else {
server.setAll(config);
thread.name().logger.warn.println("Skipping disabled template: " + other);
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Skipping disabled template: " + other));
}
} else {
thread.name().logger.warn.println("Skipping missing template: " + other);

View File

@ -272,6 +272,15 @@ public class Host {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Host
*
* @return Raw Host
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -138,6 +138,15 @@ public class Proxy {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Proxy
*
* @return Raw Proxy
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -141,6 +141,15 @@ public class Server {
return timestamp;
}
/**
* Get the raw representation of the Server
*
* @return Raw Server
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -15,6 +15,7 @@ import java.util.List;
import java.util.UUID;
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private Host host = null;
/**
@ -42,6 +43,13 @@ public class SubServer extends Server {
return obj instanceof SubServer && super.equals(obj);
}
@Override
public void refresh() {
host = null;
incompatibilities = null;
super.refresh();
}
/**
* Starts the Server
*
@ -236,6 +244,15 @@ public class SubServer extends Server {
return raw.getBoolean("running");
}
/**
* Grabs the Host of the Server
*
* @return The Host Name
*/
public String getHost() {
return raw.getRawString("host");
}
/**
* Grabs the Host of the Server
*
@ -350,6 +367,40 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible-list"));
}
/**
* Get all listed incompatibilities for this Server
*
* @param callback Incompatibility List
*/
public void getIncompatibilities(Callback<List<SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
Runnable run = () -> {
try {
callback.run(incompatibilities);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
};
if (incompatibilities == null) {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatableNames.add(subserver.toLowerCase());
SubAPI.getInstance().getSubServers(subservers -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (SubServer subserver : subservers.values())
if (incompatableNames.contains(subserver.getName().toLowerCase()))
incompatibilities.add(subserver);
this.incompatibilities = incompatibilities;
run.run();
});
} else {
run.run();
}
}
/**
* Get incompatibility issues this server currently has
*
@ -359,6 +410,24 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible"));
}
/**
* Get incompatibility issues this server currently has
*
* @param callback Current Incompatibility List
*/
public void getCurrentIncompatibilities(Callback<List<SubServer>> callback) {
getIncompatibilities(incompatibilities -> {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatableNames.add(subserver.toLowerCase());
LinkedList<SubServer> current = new LinkedList<SubServer>();
for (SubServer subserver : incompatibilities)
if (incompatableNames.contains(subserver.getName().toLowerCase()))
current.add(subserver);
callback.run(current);
});
}
/**
* If the Server is Temporary
*

View File

@ -6,10 +6,7 @@ import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.TextColor;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.API.Host;
import net.ME1312.SubServers.Host.Network.API.Proxy;
import net.ME1312.SubServers.Host.Network.API.Server;
import net.ME1312.SubServers.Host.Network.API.SubServer;
import net.ME1312.SubServers.Host.Network.API.*;
import net.ME1312.SubServers.Host.Network.Packet.*;
import org.json.JSONObject;
@ -207,56 +204,142 @@ public class SubCommand {
@Override
public void command(String handle, String[] args) {
if (args.length > 0) {
host.api.getServer(args[0], server -> {
ExHost h = host;
if (server == null) {
h.log.message.println("There is no server with that name");
} else if (!(server instanceof SubServer)) {
h.log.message.println("That Server is not a SubServer");
} else ((SubServer) server).getHost(host -> {
if (host == null) {
h.log.message.println("That Server is not a SubServer");
} else {
h.log.message.println("Info on " + server.getDisplayName() + ':');
if (!server.getName().equals(server.getDisplayName())) h.log.message.println(" - Real Name: " + server.getName());
h.log.message.println(" - Host: " + host.getName());
h.log.message.println(" - Enabled: " + ((((SubServer) server).isEnabled())?"yes":"no"));
h.log.message.println(" - Editable: " + ((((SubServer) server).isEditable())?"yes":"no"));
if (server.getGroups().size() > 0) {
h.log.message.println(" - Group:");
for (String group : server.getGroups())
h.log.message.println(" - " + group);
}
if (((SubServer) server).isTemporary()) h.log.message.println(" - Temporary: yes");
h.log.message.println(" - Running: " + ((((SubServer) server).isRunning())?"yes":"no"));
h.log.message.println(" - Logging: " + ((((SubServer) server).isLogging())?"yes":"no"));
h.log.message.println(" - Address: " + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
h.log.message.println(" - Auto Restart: " + ((((SubServer) server).willAutoRestart())?"yes":"no"));
h.log.message.println(" - Hidden: " + ((server.isHidden())?"yes":"no"));
if (((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
h.log.message.println(" - Incompatibilities:");
for (String other : ((SubServer) server).getIncompatibilities())
h.log.message.println(" - " + other + ((current.contains(other))?"*":""));
}
h.log.message.println(" - Signature: " + server.getSignature());
String type = (args.length > 1)?args[0]:null;
String name = args[(type != null)?1:0];
Runnable getServer = () -> host.api.getServer(name, server -> {
if (server != null) {
host.log.message.println("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + TextColor.WHITE + server.getDisplayName());
if (!server.getName().equals(server.getDisplayName())) host.log.message.println(" -> System Name: " + TextColor.WHITE + server.getName());
if (server instanceof SubServer) {
host.log.message.println(" -> Enabled: " + ((((SubServer) server).isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
if (!((SubServer) server).isEditable()) host.log.message.println(" -> Editable: " + TextColor.RED + "no");
host.log.message.println(" -> Host: " + TextColor.WHITE + ((SubServer) server).getHost());
}
});
if (server.getGroups().size() > 0) host.log.message.println(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + TextColor.WHITE + server.getGroups().get(0)));
if (server.getGroups().size() > 1) for (String group : server.getGroups()) host.log.message.println(" - " + TextColor.WHITE + group);
host.log.message.println(" -> Address: " + TextColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
if (server instanceof SubServer) host.log.message.println(" -> Running: " + ((((SubServer) server).isRunning())?TextColor.GREEN+"yes":TextColor.RED+"no"));
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
host.log.message.println(" -> Connected: " + ((server.getSubData() != null)?TextColor.GREEN+"yes":TextColor.RED+"no"));
host.log.message.println(" -> Players: " + TextColor.AQUA + server.getPlayers().size() + " online");
}
host.log.message.println(" -> MOTD: " + TextColor.WHITE + TextColor.stripColor(server.getMotd()));
host.log.message.println(" -> Signature: " + TextColor.AQUA + server.getSignature());
if (server instanceof SubServer) {
host.log.message.println(" -> Logging: " + ((((SubServer) server).isLogging())?TextColor.GREEN+"yes":TextColor.RED+"no"));
if (((SubServer) server).isTemporary()) host.log.message.println(" -> Temporary: " + TextColor.GREEN + "yes");
else host.log.message.println(" -> Auto Restart: " + ((((SubServer) server).willAutoRestart())?TextColor.GREEN+"enabled":TextColor.RED+"disabled"));
}
host.log.message.println(" -> Restricted: " + ((server.isRestricted())?TextColor.GREEN+"yes":TextColor.RED+"no"));
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
host.log.message.println(" -> Incompatibilities:");
for (String other : ((SubServer) server).getIncompatibilities()) host.log.message.println(" - " + ((current.contains(other.toLowerCase()))?TextColor.WHITE:TextColor.GRAY) + other);
}
host.log.message.println(" -> Hidden: " + ((server.isHidden())?TextColor.GREEN+"yes":TextColor.RED+"no"));
} else {
if (type == null) {
host.log.message.println("SubServers > There is no object with that name");
} else {
host.log.message.println("SubServers > There is no server with that name");
}
}
});
Runnable getGroup = () -> host.api.getGroup(name, group -> {
if (group != null) {
host.log.message.println("SubServers > Info on Group: " + TextColor.WHITE + name);
host.log.message.println(" -> Servers: " + ((group.size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + group.size()));
for (Server server : group) host.log.message.println(" - " + TextColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
} else {
if (type == null) {
getServer.run();
} else {
host.log.message.println("SubServers > There is no group with that name");
}
}
});
ExHost h = host;
Runnable getHost = () -> host.api.getHost(name, host -> {
if (host != null) {
h.log.message.println("SubServers > Info on Host: " + TextColor.WHITE + host.getDisplayName());
if (!host.getName().equals(host.getDisplayName())) h.log.message.println(" -> System Name: " + TextColor.WHITE + host.getName());
h.log.message.println(" -> Enabled: " + ((host.isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
h.log.message.println(" -> Address: " + TextColor.WHITE + host.getAddress().getHostAddress());
if (host.getSubData() != null) h.log.message.println(" -> Connected: " + TextColor.GREEN + "yes");
h.log.message.println(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getSubServers().keySet().size()));
for (SubServer subserver : host.getSubServers().values()) h.log.message.println(" - " + ((subserver.isEnabled())?TextColor.WHITE:TextColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
h.log.message.println(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) h.log.message.println(" - " + ((template.isEnabled())?TextColor.WHITE:TextColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
h.log.message.println(" -> Signature: " + TextColor.AQUA + host.getSignature());
} else {
if (type == null) {
getGroup.run();
} else {
h.log.message.println("SubServers > There is no host with that name");
}
}
});
Runnable getProxy = () -> host.api.getProxy(name, proxy -> {
if (proxy != null) {
host.log.message.println("SubServers > Info on Proxy: " + TextColor.WHITE + proxy.getDisplayName());
if (!proxy.getName().equals(proxy.getDisplayName())) host.log.message.println(" -> System Name: " + TextColor.WHITE + proxy.getName());
host.log.message.println(" -> Connected: " + ((proxy.getSubData() != null)?TextColor.GREEN+"yes":TextColor.RED+"no"));
host.log.message.println(" -> Redis: " + ((proxy.isRedis())?TextColor.GREEN:TextColor.RED+"un") + "available");
if (proxy.isRedis()) host.log.message.println(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
host.log.message.println(" -> Signature: " + TextColor.AQUA + proxy.getSignature());
} else {
if (type == null) {
getHost.run();
} else {
host.log.message.println("SubServers > There is no proxy with that name");
}
}
});
if (type == null) {
getProxy.run();
} else {
switch (type.toLowerCase()) {
case "p":
case "proxy":
getProxy.run();
break;
case "h":
case "host":
getHost.run();
break;
case "g":
case "group":
getGroup.run();
break;
case "s":
case "server":
case "subserver":
getServer.run();
break;
default:
host.log.message.println("SubServers > There is no object type with that name");
}
}
} else {
host.log.message.println("Usage: /" + handle + " <SubServer>");
host.log.message.println("SubServers > Usage: " + handle + " " + args[1].toLowerCase() + " [proxy|host|group|server] <Name>");
}
}
}.usage("<SubServer>").description("Gets information about a SubServer").help(
}.usage("[proxy|host|group|server]", "<Name>").description("Gets information about an Object").help(
"This command will print a list of information about",
"the specified SubServer.",
"the specified Object.",
"",
"The <SubServer> argument is required, and should be the name of",
"the SubServer you want to obtain information about.",
"If the [proxy|host|group|server] option is provided,",
"it will only include objects of the type specified in the search.",
"",
"Example:",
" /info ExampleServer"
"The <Name> argument is required, and should be the name of",
"the Object you want to obtain information about.",
"",
"Examples:",
" /info ExampleServer",
" /info server ExampleServer"
).register("info", "status");
new Command(null) {
@Override

View File

@ -272,6 +272,15 @@ public class Host {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Host
*
* @return Raw Host
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -138,6 +138,15 @@ public class Proxy {
return raw.getSection("extra").clone();
}
/**
* Get the raw representation of the Proxy
*
* @return Raw Proxy
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -141,6 +141,15 @@ public class Server {
return timestamp;
}
/**
* Get the raw representation of the Server
*
* @return Raw Server
*/
public YAMLSection getRaw() {
return raw.clone();
}
@Override
@SuppressWarnings("unchecked")
public String toString() {

View File

@ -14,6 +14,7 @@ import java.util.List;
import java.util.UUID;
public class SubServer extends Server {
private List<SubServer> incompatibilities = null;
private Host host = null;
/**
@ -41,6 +42,13 @@ public class SubServer extends Server {
return obj instanceof SubServer && super.equals(obj);
}
@Override
public void refresh() {
host = null;
incompatibilities = null;
super.refresh();
}
/**
* Starts the Server
*
@ -235,6 +243,15 @@ public class SubServer extends Server {
return raw.getBoolean("running");
}
/**
* Grabs the Host of the Server
*
* @return The Host Name
*/
public String getHost() {
return raw.getRawString("host");
}
/**
* Grabs the Host of the Server
*
@ -349,6 +366,40 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible-list"));
}
/**
* Get all listed incompatibilities for this Server
*
* @param callback Incompatibility List
*/
public void getIncompatibilities(Callback<List<SubServer>> callback) {
if (Util.isNull(callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
Runnable run = () -> {
try {
callback.run(incompatibilities);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
ew.printStackTrace();
}
};
if (incompatibilities == null) {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible-list")) incompatableNames.add(subserver.toLowerCase());
SubAPI.getInstance().getSubServers(subservers -> {
LinkedList<SubServer> incompatibilities = new LinkedList<SubServer>();
for (SubServer subserver : subservers.values())
if (incompatableNames.contains(subserver.getName().toLowerCase()))
incompatibilities.add(subserver);
this.incompatibilities = incompatibilities;
run.run();
});
} else {
run.run();
}
}
/**
* Get incompatibility issues this server currently has
*
@ -358,6 +409,24 @@ public class SubServer extends Server {
return new LinkedList<String>(raw.getRawStringList("incompatible"));
}
/**
* Get incompatibility issues this server currently has
*
* @param callback Current Incompatibility List
*/
public void getCurrentIncompatibilities(Callback<List<SubServer>> callback) {
getIncompatibilities(incompatibilities -> {
LinkedList<String> incompatableNames = new LinkedList<String>();
for (String subserver : raw.getRawStringList("incompatible")) incompatableNames.add(subserver.toLowerCase());
LinkedList<SubServer> current = new LinkedList<SubServer>();
for (SubServer subserver : incompatibilities)
if (incompatableNames.contains(subserver.getName().toLowerCase()))
current.add(subserver);
callback.run(current);
});
}
/**
* If the Server is Temporary
*

View File

@ -6,10 +6,7 @@ import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
import net.ME1312.SubServers.Sync.Library.NamedContainer;
import net.ME1312.SubServers.Sync.Library.Util;
import net.ME1312.SubServers.Sync.Library.Version.Version;
import net.ME1312.SubServers.Sync.Network.API.Host;
import net.ME1312.SubServers.Sync.Network.API.Proxy;
import net.ME1312.SubServers.Sync.Network.API.Server;
import net.ME1312.SubServers.Sync.Network.API.SubServer;
import net.ME1312.SubServers.Sync.Network.API.*;
import net.ME1312.SubServers.Sync.Network.Packet.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
@ -29,7 +26,10 @@ import java.util.concurrent.TimeUnit;
@SuppressWarnings("deprecation")
public final class SubCommand extends CommandX {
private NamedContainer<Long, TreeMap<String, List<String>>> templateCache = new NamedContainer<Long, TreeMap<String, List<String>>>(0L, new TreeMap<String, List<String>>());
private LinkedList<String> proxyCache = new LinkedList<String>();
private TreeMap<String, List<String>> hostCache = new TreeMap<String, List<String>>();
private LinkedList<String> groupCache = new LinkedList<String>();
private long cacheDate = 0;
private SubPlugin plugin;
private String label;
@ -184,43 +184,126 @@ public final class SubCommand extends CommandX {
})))));
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
if (args.length > 1) {
plugin.subdata.sendPacket(new PacketDownloadServerInfo(args[1].toLowerCase(), data -> {
switch (data.getRawString("type").toLowerCase()) {
case "invalid":
String type = (args.length > 2)?args[1]:null;
String name = args[(type != null)?2:1];
Runnable getServer = () -> plugin.api.getServer(name, server -> {
if (server != null) {
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + ChatColor.WHITE + server.getDisplayName());
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + server.getName());
if (server instanceof SubServer) {
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + ChatColor.RED + "no");
sender.sendMessage(" -> Host: " + ChatColor.WHITE + ((SubServer) server).getHost());
}
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + ChatColor.WHITE + server.getGroups().get(0)));
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + ChatColor.WHITE + group);
sender.sendMessage(" -> Address: " + ChatColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
sender.sendMessage(" -> Connected: " + ((server.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Players: " + ChatColor.AQUA + server.getPlayers().size() + " online");
}
sender.sendMessage(" -> MOTD: " + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + server.getSignature());
if (server instanceof SubServer) {
sender.sendMessage(" -> Logging: " + ((((SubServer) server).isLogging())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (((SubServer) server).isTemporary()) sender.sendMessage(" -> Temporary: " + ChatColor.GREEN + "yes");
else sender.sendMessage(" -> Auto Restart: " + ((((SubServer) server).willAutoRestart())?ChatColor.GREEN+"enabled":ChatColor.RED+"disabled"));
}
sender.sendMessage(" -> Restricted: " + ((server.isRestricted())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
List<String> current = new ArrayList<String>();
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
sender.sendMessage(" -> Incompatibilities:");
for (String other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(" - " + ((current.contains(other.toLowerCase()))?ChatColor.WHITE:ChatColor.GRAY) + other);
}
sender.sendMessage(" -> Hidden: " + ((server.isHidden())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
} else {
if (type == null) {
sender.sendMessage("SubServers > There is no object with that name");
} else {
sender.sendMessage("SubServers > There is no server with that name");
}
}
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage("SubServers > Info on Group: " + ChatColor.WHITE + name);
sender.sendMessage(" -> Servers: " + ((group.size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.size()));
for (Server server : group) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
} else {
if (type == null) {
getServer.run();
} else {
sender.sendMessage("SubServers > There is no group with that name");
}
}
});
Runnable getHost = () -> plugin.api.getHost(name, host -> {
if (host != null) {
sender.sendMessage("SubServers > Info on Host: " + ChatColor.WHITE + host.getDisplayName());
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + host.getName());
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Address: " + ChatColor.WHITE + host.getAddress().getHostAddress());
if (host.getSubData() != null) sender.sendMessage(" -> Connected: " + ChatColor.GREEN + "yes");
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(" - " + ((template.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + host.getSignature());
} else {
if (type == null) {
getGroup.run();
} else {
sender.sendMessage("SubServers > There is no host with that name");
}
}
});
Runnable getProxy = () -> plugin.api.getProxy(name, proxy -> {
if (proxy != null) {
sender.sendMessage("SubServers > Info on Proxy: " + ChatColor.WHITE + proxy.getDisplayName());
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
sender.sendMessage(" -> Connected: " + ((proxy.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
} else {
if (type == null) {
getHost.run();
} else {
sender.sendMessage("SubServers > There is no proxy with that name");
}
}
});
if (type == null) {
getProxy.run();
} else {
switch (type.toLowerCase()) {
case "p":
case "proxy":
getProxy.run();
break;
case "h":
case "host":
getHost.run();
break;
case "g":
case "group":
getGroup.run();
break;
case "s":
case "server":
case "subserver":
sender.sendMessage("SubServers > Info on " + data.getSection("server").getRawString("display") + ':');
if (!data.getSection("server").getRawString("name").equals(data.getSection("server").getRawString("display"))) sender.sendMessage(" - Real Name: " + data.getSection("server").getRawString("name"));
sender.sendMessage(" - Host: " + data.getSection("server").getRawString("host"));
sender.sendMessage(" - Enabled: " + ((data.getSection("server").getBoolean("enabled"))?"yes":"no"));
sender.sendMessage(" - Editable: " + ((data.getSection("server").getBoolean("editable"))?"yes":"no"));
if (data.getSection("server").getList("group").size() > 0) {
sender.sendMessage(" - Group:");
for (int i = 0; i < data.getSection("server").getList("group").size(); i++)
sender.sendMessage(" - " + data.getSection("server").getList("group").get(i).asRawString());
}
if (data.getSection("server").getBoolean("temp")) sender.sendMessage(" - Temporary: yes");
sender.sendMessage(" - Running: " + ((data.getSection("server").getBoolean("running"))?"yes":"no"));
sender.sendMessage(" - Logging: " + ((data.getSection("server").getBoolean("log"))?"yes":"no"));
sender.sendMessage(" - Address: " + data.getSection("server").getRawString("address"));
sender.sendMessage(" - Auto Restart: " + ((data.getSection("server").getBoolean("auto-restart"))?"yes":"no"));
sender.sendMessage(" - Hidden: " + ((data.getSection("server").getBoolean("hidden"))?"yes":"no"));
if (data.getSection("server").getList("incompatible-list").size() > 0) {
List<String> current = new ArrayList<String>();
for (int i = 0; i < data.getSection("server").getList("incompatible").size(); i++) current.add(data.getSection("server").getList("incompatible").get(i).asRawString().toLowerCase());
sender.sendMessage(" - Incompatibilities:");
for (int i = 0; i < data.getSection("server").getList("incompatible-list").size(); i++)
sender.sendMessage(" - " + data.getSection("server").getList("incompatible-list").get(i).asRawString() + ((current.contains(data.getSection("server").getList("incompatible-list").get(i).asRawString().toLowerCase()))?"*":""));
}
sender.sendMessage(" - Signature: " + data.getSection("server").getRawString("signature"));
getServer.run();
break;
default:
sender.sendMessage("SubSevrers > That Server is not a SubServer");
sender.sendMessage("SubServers > There is no object type with that name");
}
}));
}
} else {
sender.sendMessage("SubServers > Usage: " + label + " " + args[1].toLowerCase() + " <SubServer>");
sender.sendMessage("SubServers > Usage: " + label + " " + args[1].toLowerCase() + " [proxy|host|group|server] <Name>");
}
} else if (args[0].equalsIgnoreCase("start")) {
if (args.length > 1) {
@ -401,12 +484,12 @@ public final class SubCommand extends CommandX {
" Help: /sub help",
" List: /sub list",
" Version: /sub version",
" Server Info: /sub info <SubServer>",
" Info: /sub info [proxy|host|group|server] <Name>",
" Start Server: /sub start <SubServer>",
" Stop Server: /sub stop <SubServer>",
" Terminate Server: /sub kill <SubServer>",
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
" Create Server: /sub create <Name> <Host> <Type> <Version> <Port> [RAM]",
" Create Server: /sub create <Name> <Host> <Template> <Version> <Port>",
"",
" To see BungeeCord Supplied Commands, please visit:",
" https://www.spigotmc.org/wiki/bungeecord-commands/"
@ -434,8 +517,105 @@ public final class SubCommand extends CommandX {
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
}
} else {
if (args[0].equals("info") || args[0].equals("status") ||
args[0].equals("start") ||
if (args[0].equals("info") || args[0].equals("status")) {
if (args.length == 2) {
updateCache();
List<String> list = new ArrayList<String>();
List<String> subcommands = new ArrayList<String>();
subcommands.add("proxy");
subcommands.add("host");
subcommands.add("group");
subcommands.add("server");
if (last.length() == 0) {
list.addAll(subcommands);
for (String proxy : proxyCache) if (!list.contains(proxy)) list.add(proxy);
for (String host : hostCache.keySet()) if (!list.contains(host)) list.add(host);
for (String group : groupCache) if (!list.contains(group)) list.add(group);
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) if (!list.contains(server.getName())) list.add(server.getName());
} else {
for (String command : subcommands) {
if (!list.contains(command) && command.toLowerCase().startsWith(last))
list.add(last + command.substring(last.length()));
}
for (String proxy : proxyCache) {
if (!list.contains(proxy) && proxy.toLowerCase().startsWith(last))
list.add(last + proxy.substring(last.length()));
}
for (String host : hostCache.keySet()) {
if (!list.contains(host) && host.toLowerCase().startsWith(last))
list.add(last + host.substring(last.length()));
}
for (String group : groupCache) {
if (!list.contains(group) && group.toLowerCase().startsWith(last))
list.add(last + group.substring(last.length()));
}
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
if (!list.contains(server.getName()) && server.getName().toLowerCase().startsWith(last))
list.add(last + server.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else if (args.length == 3) {
updateCache();
List<String> list = new ArrayList<String>();
if (last.length() == 0) {
switch (args[1].toLowerCase()) {
case "p":
case "proxy":
list.addAll(proxyCache);
break;
case "h":
case "host":
list.addAll(hostCache.keySet());
break;
case "g":
case "group":
list.addAll(groupCache);
break;
case "s":
case "server":
case "subserver":
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) list.add(server.getName());
break;
}
} else {
switch (args[1].toLowerCase()) {
case "p":
case "proxy":
for (String proxy : proxyCache) {
if (proxy.toLowerCase().startsWith(last))
list.add(last + proxy.substring(last.length()));
}
break;
case "h":
case "host":
for (String host : hostCache.keySet()) {
if (host.toLowerCase().startsWith(last))
list.add(last + host.substring(last.length()));
}
break;
case "g":
case "group":
for (String group : groupCache) {
if (group.toLowerCase().startsWith(last))
list.add(last + group.substring(last.length()));
}
break;
case "s":
case "server":
case "subserver":
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
if (server.getName().toLowerCase().startsWith(last))
list.add(last + server.getName().substring(last.length()));
}
break;
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
}
} else if (args[0].equals("start") ||
args[0].equals("stop") ||
args[0].equals("kill") || args[0].equals("terminate")) {
List<String> list = new ArrayList<String>();
@ -472,27 +652,27 @@ public final class SubCommand extends CommandX {
if (args.length == 2) {
return new NamedContainer<>(null, Collections.singletonList("<Name>"));
} else if (args.length == 3) {
updateTemplateCache();
updateCache();
List<String> list = new ArrayList<String>();
if (templateCache.name() <= 0) {
if (cacheDate <= 0) {
list.add("<Host>");
} else if (last.length() == 0) {
list.addAll(templateCache.get().keySet());
list.addAll(hostCache.keySet());
} else {
for (String host : templateCache.get().keySet()) {
for (String host : hostCache.keySet()) {
if (host.toLowerCase().startsWith(last)) list.add(last + host.substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", args[0]):null, list);
} else if (args.length == 4) {
updateTemplateCache();
updateCache();
List<String> list = new ArrayList<String>();
if (templateCache.name() <= 0 || !templateCache.get().keySet().contains(args[2].toLowerCase())) {
if (cacheDate <= 0 || !hostCache.keySet().contains(args[2].toLowerCase())) {
list.add("<Template>");
} else if (last.length() == 0) {
list.addAll(templateCache.get().get(args[2].toLowerCase()));
list.addAll(hostCache.get(args[2].toLowerCase()));
} else {
for (String template : templateCache.get().get(args[2].toLowerCase())) {
for (String template : hostCache.get(args[2].toLowerCase())) {
if (template.toLowerCase().startsWith(last)) list.add(last + template.substring(last.length()));
}
}
@ -520,9 +700,13 @@ public final class SubCommand extends CommandX {
}
}
private void updateTemplateCache() {
if (Calendar.getInstance().getTime().getTime() - templateCache.name() >= TimeUnit.MINUTES.toMillis(5)) {
templateCache.rename(Calendar.getInstance().getTime().getTime());
private void updateCache() {
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(5)) {
cacheDate = Calendar.getInstance().getTime().getTime();
plugin.api.getProxies(proxies -> {
proxyCache = new LinkedList<String>(proxies.keySet());
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getHosts(hosts -> {
TreeMap<String, List<String>> cache = new TreeMap<String, List<String>>();
for (Host host : hosts.values()) {
@ -530,8 +714,12 @@ public final class SubCommand extends CommandX {
templates.addAll(host.getCreator().getTemplates().keySet());
cache.put(host.getName().toLowerCase(), templates);
}
templateCache.set(cache);
templateCache.rename(Calendar.getInstance().getTime().getTime());
hostCache = cache;
cacheDate = Calendar.getInstance().getTime().getTime();
});
plugin.api.getGroups(groups -> {
groupCache = new LinkedList<String>(groups.keySet());
cacheDate = Calendar.getInstance().getTime().getTime();
});
}