Search in sources :

Example 1 with Acceptable

use of de.dytanic.cloudnet.lib.utility.Acceptable in project CloudNet by Dytanic.

the class CloudProxy method fallbackOnEnabledKick.

public String fallbackOnEnabledKick(ProxiedPlayer cloudPlayer, String group, String kickedFrom) {
    for (ServerFallback serverFallback : CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getFallbacks()) {
        if (serverFallback.getGroup().equals(CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))
            continue;
        if (serverFallback.getPermission() != null) {
            if (!cloudPlayer.hasPermission(serverFallback.getPermission()))
                continue;
            List<String> servers = CloudProxy.getInstance().getServers(serverFallback.getGroup());
            servers.remove(kickedFrom);
            if (servers.size() != 0) {
                return servers.get(NetworkUtils.RANDOM.nextInt(servers.size()));
            }
        }
    }
    {
        List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

            @Override
            public boolean isAccepted(ServerInfo value) {
                return value.getServiceId().getGroup().equalsIgnoreCase(group);
            }
        }).keySet());
        liste.remove(kickedFrom);
        if (liste.size() != 0) {
            return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
        }
    }
    String fallback = getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback();
    List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

        @Override
        public boolean isAccepted(ServerInfo value) {
            return value.getServiceId().getGroup().equalsIgnoreCase(fallback);
        }
    }).keySet());
    liste.remove(kickedFrom);
    if (liste.size() == 0)
        return null;
    else
        return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable) ServerFallback(de.dytanic.cloudnet.lib.proxylayout.ServerFallback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) TabList(de.dytanic.cloudnet.lib.proxylayout.TabList) List(java.util.List)

Example 2 with Acceptable

use of de.dytanic.cloudnet.lib.utility.Acceptable in project CloudNet by Dytanic.

the class CommandCloud method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (args.length > 2) {
        if (args[0].equalsIgnoreCase("cmds") && commandSender.hasPermission("cloudnet.command.cloud.commandserver")) {
            if (CloudProxy.getInstance().getCachedServers().containsKey(args[1])) {
                StringBuilder builder = new StringBuilder();
                for (short i = 2; i < args.length; i++) builder.append(args[i]).append(NetworkUtils.SPACE_STRING);
                CloudAPI.getInstance().sendConsoleMessage(DefaultType.BUKKIT, args[1], builder.substring(0, builder.length() - 1));
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                return;
            }
        }
        if (args[0].equalsIgnoreCase("cmdp") && commandSender.hasPermission("cloudnet.command.cloud.commandproxy")) {
            StringBuilder builder = new StringBuilder();
            for (short i = 2; i < args.length; i++) builder.append(args[i]).append(NetworkUtils.SPACE_STRING);
            CloudAPI.getInstance().sendConsoleMessage(DefaultType.BUNGEE_CORD, args[1], builder.substring(0, builder.length() - 1));
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
            return;
        }
    }
    switch(args.length) {
        case 1:
            if (args[0].equalsIgnoreCase("help")) {
                commandSender.sendMessages(NetworkUtils.SPACE_STRING, CloudAPI.getInstance().getPrefix() + "All command arguments", "§7/cloud toggle autoslot", "§7/cloud toggle maintenance", "§7/cloud toggle maintenance <time>", "§7/cloud setMaxPlayers <maxonlinecount>", "§7/cloud whitelist <add : remove> <name>", "§7/cloud start <group> <count>", "§7/cloud start <group> <template>", "§7/cloud startcs <name> <memory> <priorityStop>", "§7/cloud cmds (command server) <server> <command>", "§7/cloud cmdp (command proxy) <proxy> <command>", "§7/cloud stop <serverId>", "§7/cloud stopGroup <group>", "§7/cloud ustopGroup <group>", "§7/cloud listProxys", "§7/cloud listOnline", "§7/cloud listServers", "§7/cloud log <server>", "§7/cloud listGroups", "§7/cloud rl", "§7/cloud rlconfig", "§7/cloud list", "§7/cloud maintenance <group>", "§7/cloud copy <server>", "§7/cloud copy <server> <directory>", "§7/cloud version", "§7/cloud statistics", NetworkUtils.SPACE_STRING);
                return;
            }
            if (args[0].equalsIgnoreCase("rl") && commandSender.hasPermission("cloudnet.command.cloud.reload")) {
                CloudAPI.getInstance().sendCloudCommand("reload all");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                return;
            }
            if (args[0].equalsIgnoreCase("statistics") && commandSender.hasPermission("cloudnet.ommand.cloud.statistics")) {
                Document document = CloudAPI.getInstance().getStatistics();
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "Statistics");
                for (String key : document.keys()) if (!Database.UNIQUE_NAME_KEY.equalsIgnoreCase(key))
                    commandSender.sendMessage("§3" + key + "§8| §e " + document.get(key).toString());
                return;
            }
            if (args[0].equalsIgnoreCase("version") && commandSender.hasPermission("cloudnet.command.cloud.version")) {
                commandSender.sendMessage("CloudNet " + NetworkUtils.class.getPackage().getSpecificationVersion() + " #" + NetworkUtils.class.getPackage().getImplementationVersion() + " by Dytanic");
                return;
            }
            if (args[0].equalsIgnoreCase("rlconfig") && commandSender.hasPermission("cloudnet.command.cloud.reloadconfig")) {
                CloudAPI.getInstance().sendCloudCommand("reload config");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                return;
            }
            if (args[0].equalsIgnoreCase("list") && commandSender.hasPermission("cloudnet.command.cloud.list")) {
                commandSender.sendMessage(NetworkUtils.SPACE_STRING);
                int maxMemory = 0;
                int usedMemory = 0;
                Map<String, Collection<ServerInfo>> groupSorted = new LinkedHashMap<>();
                for (WrapperInfo cnsInfo : CloudAPI.getInstance().getWrappers()) {
                    commandSender.sendMessage("§8[§7" + cnsInfo.getServerId() + "§8/§7" + cnsInfo.getHostName() + "§8] §7Cores: " + cnsInfo.getAvailableProcessors());
                    maxMemory = maxMemory + cnsInfo.getMemory();
                }
                commandSender.sendMessage(NetworkUtils.SPACE_STRING);
                for (ProxyInfo simpleProxyInfo : CloudAPI.getInstance().getProxys()) {
                    commandSender.sendMessage("§8[§c" + simpleProxyInfo.getServiceId().getServerId() + "§8] §8(§e" + simpleProxyInfo.getOnlineCount() + "§8) : §7" + simpleProxyInfo.getMemory() + "MB");
                    usedMemory = usedMemory + simpleProxyInfo.getMemory();
                }
                commandSender.sendMessage(NetworkUtils.SPACE_STRING);
                for (ServerInfo simpleProxyInfo : CloudAPI.getInstance().getServers()) {
                    if (simpleProxyInfo.getServiceId().getGroup() != null) {
                        if (!groupSorted.containsKey(simpleProxyInfo.getServiceId().getGroup()))
                            groupSorted.put(simpleProxyInfo.getServiceId().getGroup(), new ArrayList<>());
                        groupSorted.get(simpleProxyInfo.getServiceId().getGroup()).add(simpleProxyInfo);
                        continue;
                    }
                    TextComponent textComponent = new TextComponent(TextComponent.fromLegacyText("§8[§c" + simpleProxyInfo.getServiceId().getServerId() + "§8] §8(§e" + simpleProxyInfo.getOnlineCount() + "§8) §e" + simpleProxyInfo.getServerState().name() + " §8: §7" + simpleProxyInfo.getMemory() + "MB"));
                    textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/server " + simpleProxyInfo.getServiceId().getServerId()));
                    commandSender.sendMessage(textComponent);
                    usedMemory = usedMemory + simpleProxyInfo.getMemory();
                }
                commandSender.sendMessage(NetworkUtils.SPACE_STRING);
                for (Map.Entry<String, Collection<ServerInfo>> entry : groupSorted.entrySet()) {
                    commandSender.sendMessage("§7Group: §e" + entry.getKey());
                    for (ServerInfo serverInfo : entry.getValue()) {
                        TextComponent textComponent = new TextComponent(TextComponent.fromLegacyText("§8[§c" + serverInfo.getServiceId().getServerId() + "§8] §8(§e" + serverInfo.getOnlineCount() + "§8) §e" + serverInfo.getServerState().name() + " §8: §7" + serverInfo.getMemory() + "MB"));
                        textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/server " + serverInfo.getServiceId().getServerId()));
                        commandSender.sendMessage(textComponent);
                        usedMemory = usedMemory + serverInfo.getMemory();
                    }
                    commandSender.sendMessage(NetworkUtils.SPACE_STRING);
                }
                commandSender.sendMessage("§7Memory in use: " + usedMemory + "§8/§7" + maxMemory + "MB");
            }
            if (args[0].equalsIgnoreCase("listProxys") && commandSender.hasPermission("cloudnet.command.listproxys")) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "Proxys:");
                for (ProxyInfo proxy : CloudAPI.getInstance().getProxys()) {
                    commandSender.sendMessage("§7- " + (proxy.isOnline() ? "§e" : "§c") + proxy.getServiceId().getServerId() + " §8(§e" + proxy.getOnlineCount() + "§8) ");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("listServers") && commandSender.hasPermission("cloudnet.command.cloud.listservers")) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "Server:");
                for (ServerInfo server : CloudProxy.getInstance().getCachedServers().values()) {
                    TextComponent textComponent = new TextComponent(TextComponent.fromLegacyText("§7- " + (server.isOnline() ? "§e" : "§c") + server.getServiceId().getServerId() + "§8(" + server.getOnlineCount() + "§8) §7State: " + server.getServerState()));
                    textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/server " + server.getServiceId().getServerId()));
                    commandSender.sendMessage(textComponent);
                }
                return;
            }
            if (args[0].equalsIgnoreCase("listOnline") && commandSender.hasPermission("cloudnet.command.cloud.listonline")) {
                for (CloudPlayer playerWhereAmI : CloudAPI.getInstance().getOnlinePlayers()) {
                    commandSender.sendMessage("§7- §e" + playerWhereAmI.getName() + " §7on §e" + playerWhereAmI.getServer() + NetworkUtils.SLASH_STRING + playerWhereAmI.getProxy());
                }
                return;
            }
            if (args[0].equalsIgnoreCase("listGroups") && commandSender.hasPermission("cloudnet.command.cloud.listgroups")) {
                StringBuilder builder = new StringBuilder();
                for (SimpleServerGroup group : CloudAPI.getInstance().getCloudNetwork().getServerGroups().values()) {
                    builder.append((!group.isMaintenance() ? "§e" : "§c")).append(group.getName()).append("§7, ");
                }
                commandSender.sendMessage("§7The following server groups are registered:");
                commandSender.sendMessage(builder.substring(0));
                return;
            }
            break;
        case 2:
            if (args[0].equalsIgnoreCase("toggle")) {
                switch(args[1].toLowerCase()) {
                    case "autoslot":
                        {
                            if (commandSender.hasPermission("cloudnet.command.cloud.autoslot")) {
                                ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                                proxyGroup.getProxyConfig().setAutoSlot(new AutoSlot(proxyGroup.getProxyConfig().getAutoSlot().getDynamicSlotSize(), !proxyGroup.getProxyConfig().getAutoSlot().isEnabled()));
                                CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The autoslot state was updated.");
                            }
                        }
                        return;
                    case "maintenance":
                        {
                            if (commandSender.hasPermission("cloudnet.command.cloud.maintenance")) {
                                ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                                proxyGroup.getProxyConfig().setMaintenance(!proxyGroup.getProxyConfig().isMaintenance());
                                CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The maintenance state was updated.");
                            }
                            return;
                        }
                }
                return;
            }
            if (args[0].equalsIgnoreCase("log") && commandSender.hasPermission("cloudnet.command.cloud.log")) {
                if (CloudProxy.getInstance().getCachedServers().containsKey(args[1]) || CollectionWrapper.filter(CloudAPI.getInstance().getProxys(), new Acceptable<ProxyInfo>() {

                    @Override
                    public boolean isAccepted(ProxyInfo proxyInfo) {
                        return proxyInfo.getServiceId().getServerId().equalsIgnoreCase(args[1]);
                    }
                }) != null) {
                    String url = CloudAPI.getInstance().createServerLogUrl(args[1]);
                    TextComponent textComponent = new TextComponent(TextComponent.fromLegacyText("§n§l§b" + url));
                    textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
                    commandSender.sendMessage(new TextComponent(TextComponent.fromLegacyText(CloudAPI.getInstance().getPrefix() + "You can review the log at: ")), textComponent);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The log is dynamic and will be deleted on 10 minutes");
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The server doesn't exist.");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("setMaxPlayers") && commandSender.hasPermission("cloudnet.command.cloud.setmaxplayers")) {
                if (checkAsNumber(args[1])) {
                    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                    proxyGroup.getProxyConfig().setMaxPlayers(Integer.parseInt(args[1]));
                    CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The maximum onlinecount was updated.");
                } else {
                    commandSender.sendMessage("§7The second argument is not a number.");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("start") && commandSender.hasPermission("cloudnet.command.cloud.start")) {
                if (CloudAPI.getInstance().getCloudNetwork().getServerGroups().containsKey(args[1])) {
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), new ServerConfig(false, "extra", new Document(), System.currentTimeMillis()), true);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else if (CloudAPI.getInstance().getCloudNetwork().getProxyGroups().containsKey(args[1])) {
                    CloudAPI.getInstance().startProxy(CloudAPI.getInstance().getProxyGroupData(args[1]));
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist.");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("maintenance") && commandSender.hasPermission("cloudnet.command.cloud.maintenancegroup")) {
                if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                    serverGroup.setMaintenance(!serverGroup.isMaintenance());
                    CloudAPI.getInstance().updateServerGroup(serverGroup);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist.");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("stop") && commandSender.hasPermission("cloudnet.command.cloud.stop")) {
                if (CloudProxy.getInstance().getCachedServers().containsKey(args[1])) {
                    CloudAPI.getInstance().stopServer(args[1]);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else if (CollectionWrapper.filter(CloudAPI.getInstance().getProxys(), new Acceptable<ProxyInfo>() {

                    @Override
                    public boolean isAccepted(ProxyInfo proxyInfo) {
                        return proxyInfo.getServiceId().getServerId().equalsIgnoreCase(args[1]);
                    }
                }) != null) {
                    CloudAPI.getInstance().stopProxy(args[1]);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The specified server isn't online.");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("stopGroup") && commandSender.hasPermission("cloudnet.command.cloud.stopgroup")) {
                if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                    List<String> servers = CloudProxy.getInstance().getServers(args[1]);
                    for (String server : servers) CloudAPI.getInstance().stopServer(server);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    return;
                }
                if (CloudAPI.getInstance().getProxyGroupMap().containsKey(args[1])) {
                    Collection<ProxyInfo> servers = CloudAPI.getInstance().getProxys();
                    for (ProxyInfo proxyInfo : servers) if (proxyInfo.getServiceId().getGroup().equalsIgnoreCase(args[1]))
                        CloudAPI.getInstance().stopProxy(proxyInfo.getServiceId().getServerId());
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    return;
                }
                return;
            }
            if (args[0].equalsIgnoreCase("ustopGroup") && commandSender.hasPermission("cloudnet.command.cloud.useless-stopgroup")) {
                if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                    Collection<ServerInfo> servers = CollectionWrapper.filterMany(CloudProxy.getInstance().getCachedServers().values(), new Acceptable<ServerInfo>() {

                        @Override
                        public boolean isAccepted(ServerInfo serverInfo) {
                            return serverInfo.getServiceId().getGroup() != null && serverInfo.getServiceId().getGroup().equalsIgnoreCase(args[1]);
                        }
                    });
                    for (ServerInfo server : servers) if (server.getOnlineCount() == 0)
                        CloudAPI.getInstance().stopServer(server.getServiceId().getServerId());
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    return;
                }
                if (CloudAPI.getInstance().getProxyGroupMap().containsKey(args[1])) {
                    Collection<ProxyInfo> servers = CloudAPI.getInstance().getProxys();
                    for (ProxyInfo proxyInfo : servers) if (proxyInfo.getServiceId().getGroup().equalsIgnoreCase(args[1]) && proxyInfo.getOnlineCount() == 0)
                        CloudAPI.getInstance().stopProxy(proxyInfo.getServiceId().getServerId());
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    return;
                }
                return;
            }
            if (args[0].equalsIgnoreCase("copy") && commandSender.hasPermission("cloudnet.command.cloud.copy")) {
                CloudAPI.getInstance().sendCloudCommand("copy " + args[1]);
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                return;
            }
            break;
        case 3:
            if (args[0].equalsIgnoreCase("copy")) {
                if (!CloudProxy.getInstance().getCachedServers().containsKey(args[1])) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The server doesn't exists");
                    return;
                }
                CloudAPI.getInstance().copyDirectory(CloudProxy.getInstance().getCachedServers().get(args[1]), args[2]);
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The wrapper tried to copy the directory...");
                return;
            }
            if (args[0].equalsIgnoreCase("toggle")) {
                switch(args[1].toLowerCase()) {
                    case "maintenance":
                        {
                            if (commandSender.hasPermission("cloudnet.command.cloud.maintenance")) {
                                if (!NetworkUtils.checkIsNumber(args[2]))
                                    return;
                                ProxyServer.getInstance().getScheduler().schedule(CloudProxy.getInstance().getPlugin(), new Runnable() {

                                    @Override
                                    public void run() {
                                        ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                                        proxyGroup.getProxyConfig().setMaintenance(!proxyGroup.getProxyConfig().isMaintenance());
                                        CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The maintenance state was updated.");
                                    }
                                }, Integer.parseInt(args[2]), TimeUnit.SECONDS);
                                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The maintenance will be changed in " + args[2] + " seconds");
                            }
                            return;
                        }
                }
                return;
            }
            if (args[0].equalsIgnoreCase("start") && commandSender.hasPermission("cloudnet.command.cloud.start")) {
                if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                    if (checkAsNumber(args[2])) {
                        for (short i = 0; i < Integer.parseInt(args[2]); i++) {
                            CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), new ServerConfig(false, "extra", new Document(), System.currentTimeMillis()), true);
                        }
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    } else {
                        ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                        if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                            @Override
                            public boolean isAccepted(Template value) {
                                return value.getName().equalsIgnoreCase(args[2]);
                            }
                        }) != null) {
                            CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), new ServerConfig(false, "extra", new Document(), System.currentTimeMillis()), true, CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                                @Override
                                public boolean isAccepted(Template value) {
                                    return value.getName().equalsIgnoreCase(args[2]);
                                }
                            }));
                            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                        }
                    }
                } else if (CloudAPI.getInstance().getProxyGroupMap().containsKey(args[1])) {
                    if (checkAsNumber(args[2])) {
                        for (short i = 0; i < Integer.parseInt(args[2]); i++) {
                            CloudAPI.getInstance().startProxy(CloudAPI.getInstance().getProxyGroupData(args[1]));
                        }
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    } else {
                        CloudAPI.getInstance().startProxy(CloudAPI.getInstance().getProxyGroupData(args[1]));
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                    }
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist.");
                }
            } else if (args[0].equalsIgnoreCase("whitelist") && commandSender.hasPermission("cloudnet.command.cloud.whitelist")) {
                if (args[1].equalsIgnoreCase("add")) {
                    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                    if (proxyGroup.getProxyConfig().getWhitelist().contains(args[2])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + " The user " + args[2] + " is already on the whitelist.");
                        return;
                    }
                    proxyGroup.getProxyConfig().getWhitelist().add(args[2]);
                    CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + " You added " + args[2] + " to the whitelist of the maintenance mode.");
                } else if (args[1].equalsIgnoreCase("remove")) {
                    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
                    proxyGroup.getProxyConfig().getWhitelist().remove(args[2]);
                    CloudAPI.getInstance().updateProxyGroup(proxyGroup);
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + " You removed " + args[2] + " from the whitelist of the maintenance mode.");
                }
            }
            break;
        case 4:
            if (args[0].equalsIgnoreCase("startcs") && commandSender.hasPermission("cloudnet.command.cloud.startcs")) {
                if (NetworkUtils.checkIsNumber(args[2]) && Integer.parseInt(args[2]) > 128) {
                    CloudAPI.getInstance().startCloudServer(args[1], Integer.parseInt(args[2]), args[3].equalsIgnoreCase("true"));
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The information was sent to the cloud");
                } else {
                    commandSender.sendMessage("Invalid arguments!");
                }
            }
            break;
        default:
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "Use /cloud help");
            break;
    }
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Document(de.dytanic.cloudnet.lib.utility.document.Document) Template(de.dytanic.cloudnet.lib.server.template.Template) ProxyInfo(de.dytanic.cloudnet.lib.server.info.ProxyInfo) ServerConfig(de.dytanic.cloudnet.lib.server.ServerConfig) WrapperInfo(de.dytanic.cloudnet.lib.network.WrapperInfo) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup) TextComponent(net.md_5.bungee.api.chat.TextComponent) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) AutoSlot(de.dytanic.cloudnet.lib.proxylayout.AutoSlot) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable)

Example 3 with Acceptable

use of de.dytanic.cloudnet.lib.utility.Acceptable in project CloudNet by Dytanic.

the class CommandCloudServer method onCommand.

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
    if (!(commandSender instanceof Player))
        return false;
    Player player = (Player) commandSender;
    if (args.length > 5) {
        if (args[0].equalsIgnoreCase("createMob")) {
            if (MobSelector.getInstance() == null) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                return false;
            }
            try {
                EntityType entityType = EntityType.valueOf(args[1].toUpperCase());
                if (!entityType.isAlive() || !entityType.isSpawnable())
                    return false;
                if (CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {

                    @Override
                    public boolean isAccepted(MobSelector.MobImpl value) {
                        return value.getMob().getName().equalsIgnoreCase(args[2]);
                    }
                }) == null) {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (short i = 6; i < args.length; i++) {
                        stringBuilder.append(args[i]).append(NetworkUtils.SPACE_STRING);
                    }
                    if (stringBuilder.length() > 32) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The display cannot be longe then 32 characters");
                        return false;
                    }
                    ServerMob serverMob = new ServerMob(UUID.randomUUID(), stringBuilder.substring(0, stringBuilder.length() - 1), args[2], entityType.name(), args[3], NetworkUtils.checkIsNumber(args[4]) ? (Integer.parseInt(args[4]) != 0 ? Integer.parseInt(args[4]) : 138) : 138, args[5].equalsIgnoreCase("true"), MobSelector.getInstance().toPosition(CloudAPI.getInstance().getGroup(), player.getLocation()), "§8#§c%group% &bPlayers online §8|§7 %group_online% of %max_players%", new Document());
                    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutAddMob(serverMob));
                    player.sendMessage(CloudAPI.getInstance().getPrefix() + "The mob will be created, please wait...");
                } else {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The mob with the name " + args[2] + " already exists!");
                    return false;
                }
            } catch (Exception ex) {
                for (EntityType entityType : EntityType.values()) commandSender.sendMessage("- " + entityType.name());
            }
        }
    }
    if (args.length > 2) {
        if (args[0].equalsIgnoreCase("editMobLine")) {
            if (MobSelector.getInstance() == null) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                return false;
            }
            MobSelector.MobImpl mob = CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {

                @Override
                public boolean isAccepted(MobSelector.MobImpl value) {
                    return value.getMob().getName().equalsIgnoreCase(args[1]);
                }
            });
            if (mob != null) {
                StringBuilder stringBuilder = new StringBuilder();
                for (short i = 2; i < args.length; i++) stringBuilder.append(args[i]).append(NetworkUtils.SPACE_STRING);
                mob.getMob().setDisplayMessage(stringBuilder.substring(0, stringBuilder.length() - 1));
                CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutAddMob(mob.getMob()));
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "You set the mobline for \"" + args[1] + "\" the line \"" + stringBuilder.substring(0, stringBuilder.length() - 1) + "\"");
                return false;
            }
        }
        if (args[0].equalsIgnoreCase("setDisplay")) {
            MobSelector.MobImpl mob = CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {

                @Override
                public boolean isAccepted(MobSelector.MobImpl value) {
                    return value.getMob().getName().equalsIgnoreCase(args[1]);
                }
            });
            if (mob != null) {
                StringBuilder stringBuilder = new StringBuilder();
                for (short i = 2; i < args.length; i++) stringBuilder.append(args[i]).append(NetworkUtils.SPACE_STRING);
                mob.getMob().setDisplay(stringBuilder.substring(0, stringBuilder.length() - 1));
                CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutAddMob(mob.getMob()));
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "You set the display for \"" + args[1] + "\" the line \"" + stringBuilder.substring(0, stringBuilder.length() - 1) + "\"");
                return false;
            }
        }
    }
    switch(args.length) {
        case 2:
            if (args[0].equalsIgnoreCase("createSign")) {
                if (SignSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"SignSelector\" isn't enabled!");
                    return false;
                }
                Block block = player.getTargetBlock((HashSet<Material>) null, 15);
                if (block.getState() instanceof org.bukkit.block.Sign)
                    if (!SignSelector.getInstance().containsPosition(block.getLocation())) {
                        if (CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                            Sign sign = new Sign(args[1], SignSelector.getInstance().toPosition(block.getLocation()));
                            CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutAddSign(sign));
                            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The sign was successfully created!");
                        } else
                            commandSender.sendMessage("The group doesn't exist");
                    } else
                        commandSender.sendMessage("The sign already exists!");
                return false;
            }
            if (args[0].equalsIgnoreCase("removeSigns")) {
                if (SignSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"SignSelector\" isn't enabled!");
                    return false;
                }
                for (Sign sign : SignSelector.getInstance().getSigns().values()) if (sign.getTargetGroup() != null && sign.getTargetGroup().equalsIgnoreCase(args[1]))
                    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutRemoveSign(sign));
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "§7You deleted all signs from the group \"§6" + args[1] + "§7\"");
            }
            if (args[0].equalsIgnoreCase("removeMob")) {
                if (MobSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                    return false;
                }
                MobSelector.MobImpl mob = CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {

                    @Override
                    public boolean isAccepted(MobSelector.MobImpl value) {
                        return value.getMob().getName().equalsIgnoreCase(args[1]);
                    }
                });
                if (mob != null) {
                    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutRemoveMob(mob.getMob()));
                    player.sendMessage(CloudAPI.getInstance().getPrefix() + "The mob has been removed");
                } else
                    player.sendMessage(CloudAPI.getInstance().getPrefix() + "The Mob doesn't exist on this group");
            }
            break;
        case 1:
            if (args[0].equalsIgnoreCase("removeSign")) {
                if (SignSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"SignSelector\" isn't enabled!");
                    return false;
                }
                Block block = player.getTargetBlock((HashSet<Byte>) null, 15);
                if (block.getState() instanceof org.bukkit.block.Sign) {
                    if (SignSelector.getInstance().containsPosition(block.getLocation())) {
                        Sign sign = SignSelector.getInstance().getSignByPosition(block.getLocation());
                        if (sign != null) {
                            CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutRemoveSign(sign));
                            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The sign has been removed");
                        }
                    }
                }
            }
            if (args[0].equalsIgnoreCase("listMobs")) {
                if (MobSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                    return false;
                }
                CollectionWrapper.iterator(MobSelector.getInstance().getMobs().values(), new Runnabled<MobSelector.MobImpl>() {

                    @Override
                    public void run(MobSelector.MobImpl obj) {
                        commandSender.sendMessage("- " + obj.getMob().getName());
                    }
                });
            }
            if (args[0].equalsIgnoreCase("moblist")) {
                if (MobSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                    return false;
                }
                for (EntityType entityType : EntityType.values()) {
                    if (entityType.isAlive() && entityType.isSpawnable())
                        commandSender.sendMessage("- " + entityType.name());
                }
            }
            break;
        case 3:
            if (args[0].equalsIgnoreCase("setItem")) {
                if (MobSelector.getInstance() == null) {
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The Module \"MobSelector\" isn't enabled!");
                    return false;
                }
                MobSelector.MobImpl mob = CollectionWrapper.filter(MobSelector.getInstance().getMobs().values(), new Acceptable<MobSelector.MobImpl>() {

                    @Override
                    public boolean isAccepted(MobSelector.MobImpl value) {
                        return value.getMob().getName().equalsIgnoreCase(args[1]);
                    }
                });
                if (mob != null) {
                    int itemId = NetworkUtils.checkIsNumber(args[2]) ? Integer.parseInt(args[2]) : 138;
                    mob.getMob().setItemId(itemId);
                    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutAddMob(mob.getMob()));
                    commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "You set the item for \"" + args[1] + "\" the itemId \"" + itemId + "\"");
                    return false;
                }
            }
            break;
        default:
            if (SignSelector.getInstance() != null) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver createSign <targetGroup>");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver removeSign");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver removeSigns <targetGroup>");
            }
            if (MobSelector.getInstance() != null) {
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver createMob <entityType> <name> <targetGroup> <itemId> <autoJoin> <displayName>");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver removeMob <name>");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver listMobs");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver moblist");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver setDisplay <name> <display>");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver setItem <name> <itemId>");
                commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cloudserver editMobLine <name> <display>");
            }
            break;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) PacketOutRemoveMob(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutRemoveMob) Material(org.bukkit.Material) MobSelector(de.dytanic.cloudnet.bridge.internal.serverselectors.MobSelector) PacketOutAddSign(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutAddSign) Document(de.dytanic.cloudnet.lib.utility.document.Document) PacketOutRemoveSign(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutRemoveSign) EntityType(org.bukkit.entity.EntityType) ServerMob(de.dytanic.cloudnet.lib.serverselectors.mob.ServerMob) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable) PacketOutAddMob(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutAddMob) Block(org.bukkit.block.Block) Sign(de.dytanic.cloudnet.lib.serverselectors.sign.Sign) PacketOutAddSign(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutAddSign) PacketOutRemoveSign(de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutRemoveSign)

Example 4 with Acceptable

use of de.dytanic.cloudnet.lib.utility.Acceptable in project CloudNet by Dytanic.

the class ConfigSignLayout method loadLayout.

public de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig loadLayout() {
    Document document = Document.loadDocument(path);
    if (!document.getDocument("layout_config").contains("knockbackOnSmallDistance")) {
        Document document1 = document.getDocument("layout_config").append("knockbackOnSmallDistance", false);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    if (!document.getDocument("layout_config").contains("distance")) {
        Document document1 = document.getDocument("layout_config").append("distance", 1D);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    if (!document.getDocument("layout_config").contains("strength")) {
        Document document1 = document.getDocument("layout_config").append("strength", 0.8D);
        document.append("layout_config", document1);
        document.saveAsConfig(path);
    }
    SignLayoutConfig signLayoutConfig = document.getObject("layout_config", new TypeToken<de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig>() {
    }.getType());
    boolean injectable = false;
    for (SignGroupLayouts groupLayouts : signLayoutConfig.getGroupLayouts()) {
        {
            SignLayout signLayout = CollectionWrapper.filter(groupLayouts.getLayouts(), new Acceptable<SignLayout>() {

                @Override
                public boolean isAccepted(SignLayout signLayout) {
                    return signLayout.getName().equalsIgnoreCase("empty");
                }
            });
            if (signLayout == null) {
                groupLayouts.getLayouts().add(new SignLayout("empty", new String[] { "%server%", "&6%state%", "%online_players%/%max_players%", "%motd%" }, 159, 1));
                injectable = true;
            }
        }
    }
    if (injectable) {
        document.append("layout_config", signLayoutConfig).saveAsConfig(path);
    }
    return signLayoutConfig;
}
Also used : SignLayout(de.dytanic.cloudnet.lib.serverselectors.sign.SignLayout) SignLayoutConfig(de.dytanic.cloudnet.lib.serverselectors.sign.SignLayoutConfig) TypeToken(com.google.gson.reflect.TypeToken) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable) SignGroupLayouts(de.dytanic.cloudnet.lib.serverselectors.sign.SignGroupLayouts) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Aggregations

Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)4 Document (de.dytanic.cloudnet.lib.utility.document.Document)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 TypeToken (com.google.gson.reflect.TypeToken)1 MobSelector (de.dytanic.cloudnet.bridge.internal.serverselectors.MobSelector)1 PacketOutAddMob (de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutAddMob)1 PacketOutAddSign (de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutAddSign)1 PacketOutRemoveMob (de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutRemoveMob)1 PacketOutRemoveSign (de.dytanic.cloudnet.bridge.internal.serverselectors.packet.out.PacketOutRemoveSign)1 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)1 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)1 AutoSlot (de.dytanic.cloudnet.lib.proxylayout.AutoSlot)1 ServerFallback (de.dytanic.cloudnet.lib.proxylayout.ServerFallback)1 TabList (de.dytanic.cloudnet.lib.proxylayout.TabList)1 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)1 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)1 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)1 SimpleServerGroup (de.dytanic.cloudnet.lib.server.SimpleServerGroup)1 ProxyInfo (de.dytanic.cloudnet.lib.server.info.ProxyInfo)1 Template (de.dytanic.cloudnet.lib.server.template.Template)1