Search in sources :

Example 1 with ObjectMap

use of net.ME1312.Galaxi.Library.Map.ObjectMap in project SubServers-2 by ME1312.

the class SubCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args) {
    if (plugin.api.getSubDataNetwork()[0] == null || plugin.api.getSubDataNetwork()[0].isClosed()) {
        new IllegalStateException("SubData is not connected").printStackTrace();
        if (!(sender instanceof ConsoleCommandSender))
            sender.sendMessage(ChatColor.RED + "An exception has occurred while running this command");
    } else if (plugin.lang == null) {
        new IllegalStateException("There are no lang options available at this time").printStackTrace();
        if (!(sender instanceof ConsoleCommandSender))
            sender.sendMessage(ChatColor.RED + "An exception has occurred while running this command");
    } else {
        label = "/" + label;
        if (sender.hasPermission("subservers.command")) {
            if (args.length > 0) {
                if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
                    sender.sendMessage(printHelp(sender, label));
                } else if (args[0].equalsIgnoreCase("version") || args[0].equalsIgnoreCase("ver")) {
                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version").replace("$str$", "SubServers.Client.Bukkit"));
                    sender.sendMessage(ChatColor.WHITE + "  " + Platform.getSystemName() + ' ' + Platform.getSystemVersion() + ((Platform.getSystemBuild() != null) ? " (" + Platform.getSystemBuild() + ')' : "") + ((!Platform.getSystemArchitecture().equals("unknown")) ? " [" + Platform.getSystemArchitecture() + ']' : "") + ChatColor.RESET + ',');
                    sender.sendMessage(ChatColor.WHITE + "  Java " + Platform.getJavaVersion() + ((!Platform.getJavaArchitecture().equals("unknown")) ? " [" + Platform.getJavaArchitecture() + ']' : "") + ChatColor.RESET + ',');
                    sender.sendMessage(ChatColor.WHITE + "  " + Bukkit.getName() + ' ' + Bukkit.getVersion() + ChatColor.RESET + ',');
                    sender.sendMessage(ChatColor.WHITE + "  SubServers.Client.Bukkit v" + plugin.version.toExtendedString() + ((plugin.api.getPluginBuild() != null) ? " (" + plugin.api.getPluginBuild() + ')' : ""));
                    sender.sendMessage("");
                    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
                        try {
                            YAMLSection tags = new YAMLSection(plugin.parseJSON("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
                            List<Version> versions = new LinkedList<Version>();
                            Version updversion = plugin.version;
                            int updcount = 0;
                            for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
                            Collections.sort(versions);
                            for (Version version : versions) {
                                if (version.compareTo(updversion) > 0) {
                                    updversion = version;
                                    updcount++;
                                }
                            }
                            if (updcount == 0) {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Latest"));
                            } else {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Outdated").replace("$name$", "SubServers.Client.Bukkit").replace("$str$", updversion.toString()).replace("$int$", Integer.toString(updcount)));
                            }
                        } catch (Throwable e) {
                        }
                    });
                } else if (args[0].equalsIgnoreCase("list")) {
                    if (Try.all.get(() -> Class.forName("net.md_5.bungee.api.chat.BaseComponent") != null, false) && sender instanceof Player) {
                        new net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.BungeeChat(plugin).listCommand(sender, label);
                    } else {
                        final String fLabel = label;
                        plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getProxies(proxies -> {
                            int i = 0;
                            boolean sent = false;
                            String div = plugin.api.getLang("SubServers", "Command.List.Divider");
                            if (groups.keySet().size() > 0) {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Group-Header"));
                                for (String group : groups.keySet()) {
                                    String message = "  ";
                                    message += ChatColor.GOLD + group + plugin.api.getLang("SubServers", "Command.List.Header");
                                    for (Server server : groups.get(group)) {
                                        if (i != 0)
                                            message += div;
                                        if (!(server instanceof SubServer)) {
                                            message += ChatColor.WHITE;
                                        } else if (((SubServer) server).isRunning()) {
                                            if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
                                                message += ChatColor.AQUA;
                                            } else {
                                                message += ChatColor.GREEN;
                                            }
                                        } else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
                                            message += ChatColor.YELLOW;
                                        } else {
                                            message += ChatColor.RED;
                                        }
                                        message += server.getDisplayName() + ((server.getName().equals(server.getDisplayName())) ? "" : " [" + server.getName() + ']');
                                        i++;
                                    }
                                    if (i == 0)
                                        message += plugin.api.getLang("SubServers", "Command.List.Empty");
                                    sender.sendMessage(message);
                                    i = 0;
                                    sent = true;
                                }
                                if (!sent)
                                    sender.sendMessage("  " + plugin.api.getLang("SubServers", "Command.List.Empty"));
                                sent = false;
                            }
                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Host-Header"));
                            for (Host host : hosts.values()) {
                                String message = "  ";
                                if (host.isAvailable() && host.isEnabled()) {
                                    message += ChatColor.AQUA;
                                } else {
                                    message += ChatColor.RED;
                                }
                                message += host.getDisplayName();
                                if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
                                    message += " [" + ((host.getName().equals(host.getDisplayName())) ? "" : host.getName() + ChatColor.stripColor(div)) + host.getAddress() + "]";
                                } else if (!host.getName().equals(host.getDisplayName())) {
                                    message += " [" + host.getName() + "]";
                                }
                                message += plugin.api.getLang("SubServers", "Command.List.Header");
                                for (SubServer subserver : host.getSubServers().values()) {
                                    if (i != 0)
                                        message += div;
                                    if (subserver.isRunning()) {
                                        if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
                                            message += ChatColor.AQUA;
                                        } else {
                                            message += ChatColor.GREEN;
                                        }
                                    } else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
                                        message += ChatColor.YELLOW;
                                    } else {
                                        message += ChatColor.RED;
                                    }
                                    message += subserver.getDisplayName() + " [" + ((subserver.getName().equals(subserver.getDisplayName())) ? "" : subserver.getName() + ChatColor.stripColor(div)) + subserver.getAddress().getPort() + "]";
                                    i++;
                                }
                                if (i == 0)
                                    message += plugin.api.getLang("SubServers", "Command.List.Empty");
                                sender.sendMessage(message);
                                i = 0;
                                sent = true;
                            }
                            if (!sent)
                                sender.sendMessage("  " + plugin.api.getLang("SubServers", "Command.List.Empty"));
                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Server-Header"));
                            String message = "  ";
                            for (Server server : servers.values()) if (!(server instanceof SubServer)) {
                                if (i != 0)
                                    message += div;
                                message += ChatColor.WHITE + server.getDisplayName() + " [" + ((server.getName().equals(server.getDisplayName())) ? "" : server.getName() + ChatColor.stripColor(div)) + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) ? server.getAddress().getAddress().getHostAddress() + ':' : "") + server.getAddress().getPort() + "]";
                                i++;
                            }
                            if (i == 0)
                                sender.sendMessage("  " + plugin.api.getLang("SubServers", "Command.List.Empty"));
                            else
                                sender.sendMessage(message);
                            if (proxies.keySet().size() > 0) {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Proxy-Header"));
                                message = "  (master)";
                                for (Proxy proxy : proxies.values()) {
                                    message += div;
                                    if (proxy.getSubData()[0] != null) {
                                        message += ChatColor.AQUA;
                                    } else {
                                        message += ChatColor.RED;
                                    }
                                    message += proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName())) ? "" : " [" + proxy.getName() + ']');
                                }
                                sender.sendMessage(message);
                            }
                        }))));
                    }
                } else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
                    if (args.length > 1) {
                        String type = (args.length > 2) ? args[1] : null;
                        String name = args[(type != null) ? 2 : 1];
                        Runnable getPlayer = () -> plugin.api.getRemotePlayer(name, player -> {
                            if (player != null) {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "player") + ChatColor.WHITE + player.getName());
                                if (player.getProxyName() != null)
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Proxy") + ChatColor.WHITE + player.getProxyName());
                                if (player.getServerName() != null)
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Server") + ChatColor.WHITE + player.getServerName());
                                if (player.getAddress() != null && plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort());
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "UUID") + ChatColor.AQUA + player.getUniqueId());
                            } else {
                                if (type == null) {
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown"));
                                } else {
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown-Player"));
                                }
                            }
                        });
                        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$", "Available") + ((((SubServer) server).isAvailable()) ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
                                    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());
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Template") + ChatColor.WHITE + ((SubServer) server).getTemplate());
                                }
                                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().getMap("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$", ((((SubServer) server).isOnline()) ? "Online" : "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()[0] != null) ? ChatColor.GREEN + "yes" + ((server.getSubData().length > 1) ? ChatColor.AQUA + " +" + (server.getSubData().length - 1) + " subchannel" + ((server.getSubData().length == 2) ? "" : "s") : "") : ChatColor.RED + "no"));
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + server.getRemotePlayers().size() + " online");
                                }
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD") + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
                                if (server instanceof SubServer) {
                                    if (((SubServer) server).getStopAction() != SubServer.StopAction.NONE)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Stop Action") + ChatColor.WHITE + ((SubServer) server).getStopAction().toString());
                                    if (((SubServer) server).isStopping())
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Stopping") + ChatColor.GREEN + "yes");
                                }
                                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"));
                                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) {
                                    getPlayer.run();
                                } 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 + group.key());
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers") + ((group.value().size() <= 0) ? ChatColor.GRAY + "(none)" : ChatColor.AQUA.toString() + group.value().size()));
                                for (Server server : group.value()) 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$", "Available") + ((host.isAvailable()) ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((host.isEnabled()) ? ChatColor.GREEN + "yes" : ChatColor.RED + "no"));
                                if (plugin.config.get().getMap("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().length > 0)
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((host.getSubData()[0] != null) ? ChatColor.GREEN + "yes" + ((host.getSubData().length > 1) ? ChatColor.AQUA + " +" + (host.getSubData().length - 1) + " subchannel" + ((host.getSubData().length == 2) ? "" : "s") : "") : ChatColor.RED + "no"));
                                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());
                                if (!proxy.isMaster())
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData()[0] != null) ? ChatColor.GREEN + "yes" + ((proxy.getSubData().length > 1) ? ChatColor.AQUA + " +" + (proxy.getSubData().length - 1) + " subchannel" + ((proxy.getSubData().length == 2) ? "" : "s") : "") : ChatColor.RED + "no"));
                                else if (!proxy.getDisplayName().toLowerCase().contains("master"))
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Type") + ChatColor.WHITE + "Master");
                                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;
                                case "u":
                                case "user":
                                case "player":
                                    getPlayer.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() + " [proxy|host|group|server|player] <Name>"));
                    }
                } else if (args[0].equalsIgnoreCase("start")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, new String[] { "subservers.subserver.%.*", "subservers.subserver.%.start" }, select -> {
                            if (select.subservers.length > 0) {
                                Container<Integer> success = new Container<Integer>(0);
                                Container<Integer> running = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (running.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running").replace("$int$", running.value.toString()));
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start").replace("$int$", success.value.toString()));
                                });
                                for (SubServer server : select.subservers) {
                                    merge.reserve();
                                    server.start((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> {
                                        switch(response) {
                                            case 3:
                                            case 4:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Disappeared").replace("$str$", server.getName()));
                                                break;
                                            case 5:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Unavailable").replace("$str$", server.getName()));
                                                break;
                                            case 6:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled").replace("$str$", server.getName()));
                                                break;
                                            case 7:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Unavailable").replace("$str$", server.getName()));
                                                break;
                                            case 8:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled").replace("$str$", server.getName()));
                                                break;
                                            case 9:
                                                running.value++;
                                                break;
                                            case 10:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Incompatible").replace("$str$", server.getName()));
                                                break;
                                            case 0:
                                                success.value++;
                                                break;
                                        }
                                        merge.release();
                                    });
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers>"));
                    }
                } else if (args[0].equalsIgnoreCase("restart")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, new String[][] { { "subservers.subserver.%.*", "subservers.subserver.%.start" }, { "subservers.subserver.%.*", "subservers.subserver.%.stop" } }, select -> {
                            if (select.subservers.length > 0) {
                                // Step 5: Start the stopped Servers once more
                                final UUID player = (sender instanceof Player) ? ((Player) sender).getUniqueId() : null;
                                Consumer<SubServer> starter = server -> server.start(player, response -> {
                                    switch(response) {
                                        case 3:
                                        case 4:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", server.getName()));
                                            break;
                                        case 5:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Host-Unavailable").replace("$str$", server.getName()));
                                            break;
                                        case 6:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Host-Disabled").replace("$str$", server.getName()));
                                            break;
                                        case 7:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Unavailable").replace("$str$", server.getName()));
                                            break;
                                        case 8:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Disabled").replace("$str$", server.getName()));
                                            break;
                                        case 10:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Incompatible").replace("$str$", server.getName()));
                                            break;
                                        case 9:
                                        case 0:
                                            // success!
                                            break;
                                    }
                                });
                                // Step 4: Listen for stopped Servers
                                final HashMap<String, SubServer> listening = new HashMap<String, SubServer>();
                                PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() {

                                    @Override
                                    public void accept(ObjectMap<String> json) {
                                        try {
                                            if (listening.size() > 0) {
                                                PacketInExRunEvent.callback("SubStoppedEvent", this);
                                                String name = json.getString("server").toLowerCase();
                                                if (listening.containsKey(name)) {
                                                    Bukkit.getScheduler().runTaskLater(plugin, () -> {
                                                        starter.accept(listening.get(name));
                                                        listening.remove(name);
                                                    }, 5);
                                                }
                                            }
                                        } catch (Exception e) {
                                        }
                                    }
                                });
                                // Step 3: Receive command Responses
                                Container<Integer> success = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart").replace("$int$", success.value.toString()));
                                });
                                Consumer<Pair<Integer, SubServer>> stopper = data -> {
                                    if (data.key() != 0)
                                        listening.remove(data.value().getName().toLowerCase());
                                    switch(data.key()) {
                                        case 3:
                                        case 4:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", data.value().getName()));
                                            break;
                                        case 5:
                                            starter.accept(data.value());
                                        case 0:
                                            success.value++;
                                            break;
                                    }
                                    merge.release();
                                };
                                // Step 1: Detect Self
                                SubServer self = null;
                                for (SubServer server : select.subservers) {
                                    if (server.getName().equalsIgnoreCase(plugin.api.getName())) {
                                        self = server;
                                        break;
                                    }
                                }
                                // Step 2: Restart Servers
                                for (SubServer server : select.subservers) {
                                    merge.reserve();
                                    if (self == null) {
                                        listening.put(server.getName().toLowerCase(), server);
                                        server.stop(player, response -> stopper.accept(new ContainedPair<>(response, server)));
                                    } else if (self != server) {
                                        ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, server.getName(), data -> stopper.accept(new ContainedPair<>(data.getInt(0x0001), server))));
                                    }
                                }
                                if (self != null) {
                                    final SubServer fself = self;
                                    ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, self.getName(), data -> stopper.accept(new ContainedPair<>(data.getInt(0x0001), fself))));
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers>"));
                    }
                } else if (args[0].equalsIgnoreCase("stop")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, new String[] { "subservers.subserver.%.*", "subservers.subserver.%.stop" }, select -> {
                            if (select.subservers.length > 0) {
                                Container<Integer> success = new Container<Integer>(0);
                                Container<Integer> running = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (running.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Not-Running").replace("$int$", running.value.toString()));
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop").replace("$int$", success.value.toString()));
                                });
                                Consumer<Pair<Integer, SubServer>> stopper = data -> {
                                    switch(data.key()) {
                                        case 3:
                                        case 4:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Disappeared").replace("$str$", data.value().getName()));
                                            break;
                                        case 5:
                                            running.value++;
                                            break;
                                        case 0:
                                            success.value++;
                                            break;
                                    }
                                    merge.release();
                                };
                                SubServer self = null;
                                for (SubServer server : select.subservers) {
                                    if (server.getName().equalsIgnoreCase(plugin.api.getName())) {
                                        self = server;
                                        break;
                                    }
                                }
                                for (SubServer server : select.subservers) {
                                    merge.reserve();
                                    if (self != server)
                                        server.stop((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.accept(new ContainedPair<>(response, server)));
                                }
                                if (self != null) {
                                    final SubServer fself = self;
                                    fself.stop((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.accept(new ContainedPair<>(response, fself)));
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers>"));
                    }
                } else if (args[0].equalsIgnoreCase("kill") || args[0].equalsIgnoreCase("terminate")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, new String[] { "subservers.subserver.%.*", "subservers.subserver.%.terminate" }, select -> {
                            if (select.subservers.length > 0) {
                                Container<Integer> success = new Container<Integer>(0);
                                Container<Integer> running = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (running.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Not-Running").replace("$int$", running.value.toString()));
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate").replace("$int$", success.value.toString()));
                                });
                                Consumer<Pair<Integer, SubServer>> stopper = data -> {
                                    switch(data.key()) {
                                        case 3:
                                        case 4:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Disappeared").replace("$str$", data.value().getName()));
                                            break;
                                        case 5:
                                            running.value++;
                                            break;
                                        case 0:
                                            success.value++;
                                            break;
                                    }
                                    merge.release();
                                };
                                SubServer self = null;
                                for (SubServer server : select.subservers) {
                                    if (server.getName().equalsIgnoreCase(plugin.api.getName())) {
                                        self = server;
                                        break;
                                    }
                                }
                                for (SubServer server : select.subservers) {
                                    merge.reserve();
                                    if (self != server)
                                        server.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.accept(new ContainedPair<>(response, server)));
                                }
                                if (self != null) {
                                    final SubServer fself = self;
                                    fself.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.accept(new ContainedPair<>(response, fself)));
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers>"));
                    }
                } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, false, new String[] { "subservers.subserver.%.*", "subservers.subserver.%.command" }, select -> {
                            if (select.servers.length > 0) {
                                if (select.args.length > 2) {
                                    StringBuilder builder = new StringBuilder(select.args[2]);
                                    for (int i = 3; i < select.args.length; i++) {
                                        builder.append(' ');
                                        builder.append(select.args[i]);
                                    }
                                    Container<Integer> success = new Container<Integer>(0);
                                    Container<Integer> running = new Container<Integer>(0);
                                    AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                        if (running.value > 0)
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString()));
                                        if (success.value > 0)
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString()));
                                    });
                                    for (Server server : select.servers) {
                                        merge.reserve();
                                        server.command((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, builder.toString(), response -> {
                                            switch(response) {
                                                case 3:
                                                case 4:
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Disappeared").replace("$str$", server.getName()));
                                                    break;
                                                case 5:
                                                    running.value++;
                                                    break;
                                                case 0:
                                                    success.value++;
                                                    break;
                                            }
                                            merge.release();
                                        });
                                    }
                                } else {
                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.No-Command"));
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Servers> <Command> [Args...]"));
                    }
                } else if (args[0].equalsIgnoreCase("create")) {
                    if (args.length > 3) {
                        if (permits(args[2], sender, "subservers.host.%.*", "subservers.host.%.create")) {
                            if (args.length > 5 && !Try.all.run(() -> Integer.parseInt(args[5]))) {
                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"));
                            } else {
                                ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketCreateServer((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, args[1], args[2], args[3], (args.length > 4) ? new Version(args[4]) : null, (args.length > 5) ? Integer.parseInt(args[5]) : null, data -> {
                                    switch(data.getInt(0x0001)) {
                                        case 3:
                                        case 4:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Exists"));
                                            break;
                                        case 5:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Host"));
                                            break;
                                        case 6:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Host-Unavailable"));
                                            break;
                                        case 7:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Host-Disabled"));
                                            break;
                                        case 8:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Template"));
                                            break;
                                        case 9:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Template-Disabled"));
                                            break;
                                        case 10:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Version-Required"));
                                            break;
                                        case 11:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"));
                                            break;
                                        case 0:
                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator").replace("$str$", args[1]));
                                            break;
                                    }
                                }));
                            }
                        } else {
                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.host." + args[2].toLowerCase() + ".create"));
                        }
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]"));
                    }
                } else if (args[0].equalsIgnoreCase("update") || args[0].equalsIgnoreCase("upgrade")) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, new String[] { "subservers.subserver.%.*", "subservers.subserver.%.update" }, select -> {
                            if (select.subservers.length > 0) {
                                String template = (select.args.length > 3) ? select.args[2].toLowerCase() : null;
                                Version version = (select.args.length > 2) ? new Version(select.args[(template == null) ? 2 : 3]) : null;
                                boolean ts = template == null;
                                Container<Integer> success = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString()));
                                });
                                for (SubServer server : select.subservers) {
                                    merge.reserve();
                                    ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, server.getName(), template, version, data -> {
                                        switch(data.getInt(0x0001)) {
                                            case 3:
                                            case 4:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Disappeared").replace("$str$", server.getName()));
                                                break;
                                            case 5:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Host-Unavailable").replace("$str$", server.getName()));
                                                break;
                                            case 6:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Host-Disabled").replace("$str$", server.getName()));
                                                break;
                                            case 7:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Server-Unavailable").replace("$str$", server.getName()));
                                                break;
                                            case 8:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Running").replace("$str$", server.getName()));
                                                break;
                                            case 9:
                                                if (ts)
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName()));
                                                else
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Template"));
                                                break;
                                            case 10:
                                                if (ts)
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName()));
                                                else
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Template-Disabled"));
                                                break;
                                            case 11:
                                                if (ts)
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName()));
                                                else
                                                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Template-Invalid"));
                                                break;
                                            case 12:
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Version-Required").replace("$str$", server.getName()));
                                                break;
                                            case 0:
                                                success.value++;
                                                break;
                                        }
                                        merge.release();
                                    }));
                                }
                            }
                        });
                    } else {
                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers> [[Template] <Version>]"));
                    }
                } else if ((args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) && plugin.config.get().getMap("Settings").getBoolean("Allow-Deletion", false)) {
                    if (args.length > 1) {
                        selectServers(sender, args, 1, true, "subservers.subserver.%.delete", select -> {
                            if (select.subservers.length > 0) {
                                Container<Integer> success = new Container<Integer>(0);
                                AsyncConsolidator merge = new AsyncConsolidator(() -> {
                                    if (success.value > 0)
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Delete").replace("$int$", success.value.toString()));
                                });
                                for (SubServer server : select.subservers) {
                                    if (server.isRunning()) {
                                        sender.sendMessage(plugin.api.getLang("SubServers", "Command.Delete.Running").replace("$str$", server.getName()));
                                    } else {
                                        server.getHost(host -> {
                                            if (host == null) {
                                                sender.sendMessage(plugin.api.getLang("SubServers", "Command.Delete.Disappeared").replace("$str$", server.getName()));
                                            } else {
                                                merge.reserve();
                                                host.recycleSubServer(server.getName(), response -> {
                                                    switch(response) {
                                                        case 3:
                                                        case 4:
                                                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Delete.Disappeared").replace("$str$", server.getName()));
                                                            break;
                                                        case 0:
                                                            success.value++;
                                                            break;
                                                    }
                                                    merge.release();
                                                });
                                            }
                                        });
                                    }
                                }
                            }
                        });
                    } else {
                        sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Subservers>");
                    }
                } else if (args[0].equalsIgnoreCase("restore")) {
                // TODO
                } else if (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport")) {
                    executeTeleport(sender, label, args);
                } else if ((args[0].equalsIgnoreCase("view") || args[0].equalsIgnoreCase("open")) && sender instanceof Player) {
                    if (plugin.gui != null) {
                        if (sender.hasPermission("subservers.interface")) {
                            try {
                                plugin.gui.getRenderer((Player) sender).clearHistory();
                                switch(args[1].toLowerCase()) {
                                    case "host":
                                        if (args.length > 2)
                                            plugin.gui.getRenderer((Player) sender).hostMenu(Integer.parseInt(args[2]));
                                        else
                                            plugin.gui.getRenderer((Player) sender).hostMenu(1);
                                        break;
                                    case "host/":
                                        plugin.gui.getRenderer((Player) sender).hostAdmin(args[2]);
                                        break;
                                    case "host/creator":
                                        if (permits(args[2], sender, "subservers.host.%.*", "subservers.host.%.create"))
                                            plugin.gui.getRenderer((Player) sender).hostCreator(new UIRenderer.CreatorOptions(args[2]));
                                        else
                                            throw new IllegalStateException("Player does not meet the requirements to render this page");
                                        break;
                                    case "host/plugin":
                                        if (args.length > 3)
                                            plugin.gui.getRenderer((Player) sender).hostPlugin(Integer.parseInt(args[3]), args[2]);
                                        else
                                            plugin.gui.getRenderer((Player) sender).hostPlugin(1, args[2]);
                                        break;
                                    case "group":
                                        if (args.length > 2)
                                            plugin.gui.getRenderer((Player) sender).groupMenu(Integer.parseInt(args[2]));
                                        else
                                            plugin.gui.getRenderer((Player) sender).groupMenu(1);
                                        break;
                                    case "server":
                                    case "subserver":
                                        if (args.length > 4)
                                            plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), args[4], null);
                                        else if (args.length > 3)
                                            plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, args[3]);
                                        else if (args.length > 2)
                                            plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, null);
                                        else
                                            plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null);
                                        break;
                                    case "server/":
                                    case "subserver/":
                                        plugin.gui.getRenderer((Player) sender).serverAdmin(args[2]);
                                        break;
                                    case "server/plugin":
                                    case "subserver/plugin":
                                        if (args.length > 3)
                                            plugin.gui.getRenderer((Player) sender).serverPlugin(Integer.parseInt(args[3]), args[2]);
                                        else
                                            plugin.gui.getRenderer((Player) sender).serverPlugin(1, args[2]);
                                        break;
                                }
                            } catch (Throwable e) {
                            /*
                                    List<String> list = new LinkedList<String>();
                                    list.addAll(Arrays.asList(args));
                                    list.remove(0);
                                    new InvocationTargetException(e, "Could not render page with arguments: " + list.toString()).printStackTrace(); */
                            }
                        } else {
                            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.interface"));
                        }
                    }
                } else {
                    sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]));
                }
            } else {
                if (plugin.gui != null && sender instanceof Player && sender.hasPermission("subservers.interface")) {
                    plugin.gui.getRenderer((Player) sender).newUI();
                } else {
                    sender.sendMessage(printHelp(sender, label));
                }
            }
        } else if (args.length > 0 && (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport"))) {
            executeTeleport(sender, label, args);
        } else if (plugin.gui != null && sender instanceof Player && sender.hasPermission("subservers.interface")) {
            plugin.gui.getRenderer((Player) sender).newUI();
        } else {
            sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command"));
        }
    }
    return true;
}
Also used : YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) Platform(net.ME1312.Galaxi.Library.Platform) java.util(java.util) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) URL(java.net.URL) Player(org.bukkit.entity.Player) SubDataClient(net.ME1312.SubData.Client.SubDataClient) API(net.ME1312.SubServers.Client.Common.Network.API) Charset(java.nio.charset.Charset) AsyncConsolidator(net.ME1312.Galaxi.Library.AsyncConsolidator) Util(net.ME1312.Galaxi.Library.Util) Version(net.ME1312.Galaxi.Library.Version.Version) Try(net.ME1312.Galaxi.Library.Try) PacketRestartServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketRestartServer) PacketCreateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketCreateServer) Bukkit(org.bukkit.Bukkit) CommandSender(org.bukkit.command.CommandSender) Value(net.ME1312.Galaxi.Library.Container.Value) UIRenderer(net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer) PacketUpdateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketUpdateServer) ObjectPermission.permits(net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permits) InputStreamReader(java.io.InputStreamReader) InvocationTargetException(java.lang.reflect.InvocationTargetException) YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) Consumer(java.util.function.Consumer) Container(net.ME1312.Galaxi.Library.Container.Container) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) PacketInExRunEvent(net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketInExRunEvent) ContainedPair(net.ME1312.Galaxi.Library.Container.ContainedPair) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) BufferedReader(java.io.BufferedReader) Pair(net.ME1312.Galaxi.Library.Container.Pair) PacketRestartServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketRestartServer) PacketCreateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketCreateServer) PacketUpdateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketUpdateServer) Container(net.ME1312.Galaxi.Library.Container.Container) Consumer(java.util.function.Consumer) Version(net.ME1312.Galaxi.Library.Version.Version) SubDataClient(net.ME1312.SubData.Client.SubDataClient) Player(org.bukkit.entity.Player) SubDataClient(net.ME1312.SubData.Client.SubDataClient) UIRenderer(net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer) URL(java.net.URL) AsyncConsolidator(net.ME1312.Galaxi.Library.AsyncConsolidator) PacketCreateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketCreateServer) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) PacketRestartServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketRestartServer) ContainedPair(net.ME1312.Galaxi.Library.Container.ContainedPair) ContainedPair(net.ME1312.Galaxi.Library.Container.ContainedPair) Pair(net.ME1312.Galaxi.Library.Container.Pair) InputStreamReader(java.io.InputStreamReader) PacketUpdateServer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketUpdateServer) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvocationTargetException(java.lang.reflect.InvocationTargetException) BufferedReader(java.io.BufferedReader)

Example 2 with ObjectMap

use of net.ME1312.Galaxi.Library.Map.ObjectMap in project SubServers-2 by ME1312.

the class SubPlugin method onEnable.

/**
 * Enable Plugin
 */
@Override
public void onEnable() {
    try {
        Bukkit.getLogger().info("SubServers > Loading SubServers.Client.Bukkit v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion() + ")");
        dir = new File(getDataFolder().getParentFile(), "SubServers-Client");
        if (getDataFolder().exists()) {
            Files.move(getDataFolder().toPath(), dir.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } else
            dir.mkdirs();
        ConfigUpdater.updateConfig(new File(dir, "config.yml"));
        config = new YAMLConfig(new File(dir, "config.yml"));
        if (new File(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
            FileReader reader = new FileReader(new File(new File(System.getProperty("user.dir")), "subdata.json"));
            config.get().getMap("Settings").set("SubData", new YAMLSection(parseJSON(Util.readAll(reader))));
            config.save();
            reader.close();
            new File(new File(System.getProperty("user.dir")), "subdata.json").delete();
        }
        if (new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").exists()) {
            if (new File(dir, "subdata.rsa.key").exists())
                new File(dir, "subdata.rsa.key").delete();
            Files.move(new File(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new File(dir, "subdata.rsa.key").toPath());
        }
        getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
        reload(false);
        subprotocol = SubProtocol.get();
        subprotocol.registerCipher("DHE", DHE.get(128));
        subprotocol.registerCipher("DHE-128", DHE.get(128));
        subprotocol.registerCipher("DHE-192", DHE.get(192));
        subprotocol.registerCipher("DHE-256", DHE.get(256));
        api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", System.getenv("name"));
        server_address = config.get().getMap("Settings").getString("Connect-Address", System.getenv("address"));
        if (config.get().getMap("Settings").getMap("SubData").getString("Password", "").length() > 0) {
            subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getString("Password")));
            Bukkit.getLogger().info("SubData > AES Encryption Available");
        }
        if (new File(dir, "subdata.rsa.key").exists()) {
            try {
                subprotocol.registerCipher("RSA", new RSA(new File(dir, "subdata.rsa.key")));
                Bukkit.getLogger().info("SubData > RSA Encryption Available");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        reconnect = true;
        Bukkit.getLogger().info("SubData > ");
        Bukkit.getLogger().info("SubData > Connecting to /" + config.get().getMap("Settings").getMap("SubData").getString("Address", "127.0.0.1:4391"));
        connect(null);
        gui = new DefaultUIHandler(this);
        if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
            Bukkit.getPluginManager().registerEvents(new SubSigns(this, new File(dir, "signs.dat")), this);
            CommandMap cmd = Util.reflect(Bukkit.getServer().getClass().getDeclaredField("commandMap"), Bukkit.getServer());
            cmd.register("subservers", new SubCommand(this, "subservers"));
            cmd.register("subservers", new SubCommand(this, "subserver"));
            cmd.register("subservers", new SubCommand(this, "sub"));
        }
        if (api.access.value > NO_INTEGRATIONS.value) {
            if (config.get().getMap("Settings").getBoolean("PlaceholderAPI-Ready", false))
                phi.start();
            if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null)
                new PlaceholderImpl(this).register();
        }
        new Metrics(this, 2334);
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
            try {
                YAMLSection tags = new YAMLSection(parseJSON("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}'));
                List<Version> versions = new LinkedList<Version>();
                Version updversion = version;
                int updcount = 0;
                for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
                Collections.sort(versions);
                for (Version version : versions) {
                    if (version.compareTo(updversion) > 0) {
                        updversion = version;
                        updcount++;
                    }
                }
                if (updcount > 0)
                    Bukkit.getLogger().info("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
            } catch (Throwable e) {
            }
        }, 0, TimeUnit.DAYS.toSeconds(2) * 20);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) RSA(net.ME1312.SubData.Client.Encryption.RSA) YAMLConfig(net.ME1312.Galaxi.Library.Config.YAMLConfig) DefaultUIHandler(net.ME1312.SubServers.Client.Bukkit.Graphic.DefaultUIHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) URL(java.net.URL) AES(net.ME1312.SubData.Client.Encryption.AES) Metrics(net.ME1312.SubServers.Client.Bukkit.Library.Metrics) Version(net.ME1312.Galaxi.Library.Version.Version) PlaceholderImpl(net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.PlaceholderImpl) CommandMap(org.bukkit.command.CommandMap)

Example 3 with ObjectMap

use of net.ME1312.Galaxi.Library.Map.ObjectMap in project SubServers-2 by ME1312.

the class ConfigUpdater method updateConfig.

/**
 * Update SubServers' config.yml
 *
 * @param file File to bring up-to-date
 */
public static void updateConfig(File file) throws IOException {
    YAMLConfig config = new YAMLConfig(file);
    YAMLSection existing = config.get().clone();
    YAMLSection updated = existing.clone();
    YAMLSection rewritten = new YAMLSection();
    Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
    Version now = SubAPI.getInstance().getPluginBuild();
    int i = 0;
    if (now == null)
        now = UNSIGNED;
    if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
        i++;
        Bukkit.getLogger().info("SubServers > Created ./plugins/SubServers-Client-Bukkit/config.yml");
    } else {
        if (was.compareTo(new Version("19w17a")) <= 0) {
            if (existing.getMap("Settings", new YAMLSection()).contains("Ingame-Access"))
                updated.getMap("Settings").safeSet("API-Only-Mode", !existing.getMap("Settings").getBoolean("Ingame-Access"));
            existing = updated.clone();
            i++;
        }
        if (i > 0)
            Bukkit.getLogger().info("SubServers > Updated ./plugins/SubServers-Client-Bukkit/config.yml (" + i + " pass" + ((i != 1) ? "es" : "") + ")");
    }
    if (i > 0) {
        YAMLSection settings = new YAMLSection();
        settings.set("Version", ((now.compareTo(was) <= 0) ? was : now).toString());
        settings.set("API-Only-Mode", updated.getMap("Settings", new YAMLSection()).getBoolean("API-Only-Mode", false));
        settings.set("Allow-Deletion", updated.getMap("Settings", new YAMLSection()).getBoolean("Allow-Deletion", false));
        settings.set("Show-Addresses", updated.getMap("Settings", new YAMLSection()).getBoolean("Show-Addresses", false));
        settings.set("Use-Title-Messages", updated.getMap("Settings", new YAMLSection()).getBoolean("Use-Title-Messages", true));
        settings.set("PlaceholderAPI-Ready", updated.getMap("Settings", new YAMLSection()).getBoolean("PlaceholderAPI-Ready", false));
        if (updated.getMap("Settings", new YAMLSection()).contains("PlaceholderAPI-Cache-Interval"))
            settings.set("PlaceholderAPI-Cache-Interval", updated.getMap("Settings").getInt("PlaceholderAPI-Cache-Interval"));
        if (updated.getMap("Settings", new YAMLSection()).contains("Connect-Address"))
            settings.set("Connect-Address", updated.getMap("Settings").getString("Connect-Address"));
        YAMLSection subdata = new YAMLSection();
        if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Name"))
            subdata.set("Name", updated.getMap("Settings").getMap("SubData").getString("Name"));
        subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getString("Address", "127.0.0.1:4391"));
        if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password"))
            subdata.set("Password", updated.getMap("Settings").getMap("SubData").getString("Password"));
        if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Reconnect"))
            subdata.set("Reconnect", updated.getMap("Settings").getMap("SubData").getInt("Reconnect"));
        settings.set("SubData", subdata);
        rewritten.set("Settings", settings);
        config.set(rewritten);
        config.save();
    }
}
Also used : YAMLSection(net.ME1312.Galaxi.Library.Config.YAMLSection) Version(net.ME1312.Galaxi.Library.Version.Version) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) YAMLConfig(net.ME1312.Galaxi.Library.Config.YAMLConfig)

Example 4 with ObjectMap

use of net.ME1312.Galaxi.Library.Map.ObjectMap in project SubServers-2 by ME1312.

the class SubProxy method post.

private void post() {
    if (!config.get().getMap("Settings").getStringList("Disabled-Overrides", Collections.emptyList()).contains("/server"))
        getPluginManager().registerCommand(plugin, new SubCommand.BungeeServer(this, "server"));
    if (!config.get().getMap("Settings").getStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
        getPluginManager().registerCommand(plugin, new SubCommand.BungeeList(this, "glist"));
    getPluginManager().registerCommand(plugin, new SubCommand(this, "subservers"));
    getPluginManager().registerCommand(plugin, new SubCommand(this, "subserver"));
    getPluginManager().registerCommand(plugin, new SubCommand(this, "sub"));
    if (getReconnectHandler() != null && getReconnectHandler().getClass().equals(SmartFallback.class))
        // Re-initialize Smart Fallback
        setReconnectHandler(new SmartFallback(config.get().getMap("Settings").getMap("Smart-Fallback", new ObjectMap<>())));
    if (plugin != null)
        new Metrics(plugin, 1406).appendAppData();
    new Timer("SubServers.Bungee::Routine_Update_Check").schedule(new TimerTask() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            try {
                ObjectMap<String> tags = new ObjectMap<String>(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
                List<Version> versions = new LinkedList<Version>();
                Version updversion = version;
                int updcount = 0;
                for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
                Collections.sort(versions);
                for (Version version : versions) {
                    if (version.compareTo(updversion) > 0) {
                        updversion = version;
                        updcount++;
                    }
                }
                if (updcount > 0)
                    Logger.get("SubServers").info("SubServers.Bungee v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
            } catch (Exception e) {
            }
        }
    }, 0, TimeUnit.DAYS.toMillis(2));
    int rpec_i = config.get().getMap("Settings").getInt("RPEC-Check-Interval", 300);
    int rpec_s = rpec_i - new Random().nextInt((rpec_i / 3) + 1);
    new Timer("SubServers.Bungee::RemotePlayer_Error_Checking").schedule(new TimerTask() {

        @Override
        public void run() {
            synchronized (rPlayers) {
                ArrayList<RemotePlayer> add = new ArrayList<RemotePlayer>();
                for (ProxiedPlayer player : getPlayers()) {
                    if (!rPlayers.containsKey(player.getUniqueId())) {
                        // Add players that don't exist
                        RemotePlayer p = new RemotePlayer(player);
                        rPlayerLinkP.put(player.getUniqueId(), p.getProxy());
                        rPlayers.put(player.getUniqueId(), p);
                        if (p.getServer() != null)
                            rPlayerLinkS.put(player.getUniqueId(), p.getServer());
                        add.add(p);
                    }
                }
                ArrayList<RemotePlayer> remove = new ArrayList<RemotePlayer>();
                for (UUID player : Util.getBackwards(rPlayerLinkP, mProxy)) {
                    // Remove players that shouldn't exist
                    if (getPlayer(player) == null) {
                        remove.add(rPlayers.get(player));
                        rPlayerLinkS.remove(player);
                        rPlayerLinkP.remove(player);
                        rPlayers.remove(player);
                    }
                }
                // Compile change data for external proxies
                LinkedList<PacketExSyncPlayer> packets = new LinkedList<PacketExSyncPlayer>();
                if (add.size() > 0)
                    packets.add(new PacketExSyncPlayer(mProxy.getName(), true, add.toArray(new RemotePlayer[0])));
                if (remove.size() > 0)
                    packets.add(new PacketExSyncPlayer(mProxy.getName(), false, remove.toArray(new RemotePlayer[0])));
                if (packets.size() > 0) {
                    PacketExSyncPlayer[] packet = packets.toArray(new PacketExSyncPlayer[0]);
                    for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
                        ((SubDataClient) proxy.getSubData()[0]).sendPacket(packet);
                    }
                }
            }
        }
    }, TimeUnit.SECONDS.toMillis(rpec_s), TimeUnit.SECONDS.toMillis(rpec_i));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Gson(com.google.gson.Gson) URL(java.net.URL) Metrics(net.ME1312.SubServers.Bungee.Library.Metrics) SecureRandom(java.security.SecureRandom) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) Version(net.ME1312.Galaxi.Library.Version.Version) SmartFallback(net.ME1312.SubServers.Bungee.Library.Fallback.SmartFallback) PacketExSyncPlayer(net.ME1312.SubServers.Bungee.Network.Packet.PacketExSyncPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidServerException(net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException) InvalidHostException(net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException) SubDataClient(net.ME1312.SubData.Server.SubDataClient)

Example 5 with ObjectMap

use of net.ME1312.Galaxi.Library.Map.ObjectMap in project SubServers-2 by ME1312.

the class PacketRestartServer method receive.

@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
    UUID tracker = (data.contains(0x0000) ? data.getUUID(0x0000) : null);
    try {
        String name = data.getString(0x0001);
        UUID player = (data.contains(0x0002) ? data.getUUID(0x0002) : null);
        Runnable starter = () -> {
            Map<String, Server> servers = plugin.api.getServers();
            if (!servers.containsKey(name.toLowerCase())) {
            } else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
            } else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
            } else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
            } else if (!((SubServer) servers.get(name.toLowerCase())).isAvailable()) {
            } else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
            } else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
            } else if (((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities().size() != 0) {
            } else {
                ((SubServer) servers.get(name.toLowerCase())).start(player);
            }
        };
        Map<String, Server> servers = plugin.api.getServers();
        if (!servers.containsKey(name.toLowerCase())) {
            client.sendPacket(new PacketRestartServer(3, tracker));
        } else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
            client.sendPacket(new PacketRestartServer(4, tracker));
        } else {
            client.sendPacket(new PacketRestartServer(0, tracker));
            if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
                new Thread(() -> {
                    try {
                        ((SubServer) servers.get(name.toLowerCase())).stop();
                        ((SubServer) servers.get(name.toLowerCase())).waitFor();
                        Thread.sleep(100);
                        starter.run();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }, "SubServers.Bungee::Server_Restart_Packet_Handler(" + servers.get(name.toLowerCase()).getName() + ')').start();
            } else {
                starter.run();
            }
        }
    } catch (Throwable e) {
        client.sendPacket(new PacketRestartServer(2, tracker));
        e.printStackTrace();
    }
}
Also used : SubServer(net.ME1312.SubServers.Bungee.Host.SubServer) Server(net.ME1312.SubServers.Bungee.Host.Server) SubServer(net.ME1312.SubServers.Bungee.Host.SubServer) UUID(java.util.UUID) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) Map(java.util.Map)

Aggregations

ObjectMap (net.ME1312.Galaxi.Library.Map.ObjectMap)52 Version (net.ME1312.Galaxi.Library.Version.Version)26 UUID (java.util.UUID)24 SubDataClient (net.ME1312.SubData.Client.SubDataClient)22 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 Try (net.ME1312.Galaxi.Library.Try)14 YAMLConfig (net.ME1312.Galaxi.Library.Config.YAMLConfig)13 YAMLSection (net.ME1312.Galaxi.Library.Config.YAMLSection)13 Util (net.ME1312.Galaxi.Library.Util)13 java.util (java.util)12 Server (net.ME1312.SubServers.Bungee.Host.Server)12 SubServer (net.ME1312.SubServers.Bungee.Host.SubServer)12 Pair (net.ME1312.Galaxi.Library.Container.Pair)11 SubDataClient (net.ME1312.SubData.Server.SubDataClient)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 Consumer (java.util.function.Consumer)10 URL (java.net.URL)9 Logger (java.util.logging.Logger)9 Container (net.ME1312.Galaxi.Library.Container.Container)9