Search in sources :

Example 1 with ServerGroup

use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.

the class CommandReload method onExecuteCommand.

@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
    switch(args.length) {
        case 1:
            if (args[0].equalsIgnoreCase("all")) {
                sender.sendMessage("[RELOAD] Trying to reload CloudNet...");
                try {
                    CloudNet.getInstance().reload();
                    sender.sendMessage("[RELOAD] Reloading was completed successfully!");
                } catch (Exception e) {
                    sender.sendMessage("[RELOAD] Failed to reload CloudNet");
                    e.printStackTrace();
                }
                return;
            }
            if (args[0].equalsIgnoreCase("config")) {
                sender.sendMessage("[RELOAD] Trying to reload config");
                try {
                    CloudNet.getInstance().getConfig().load();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                CloudNet.getInstance().getServerGroups().clear();
                CloudNet.getInstance().getProxyGroups().clear();
                CloudNet.getInstance().getUsers().clear();
                CloudNet.getInstance().getUsers().addAll(CloudNet.getInstance().getConfig().getUsers());
                NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {

                    @Override
                    public boolean isAccepted(ServerGroup value) {
                        System.out.println("Loading ServerGroup: " + value.getName());
                        CloudNet.getInstance().setupGroup(value);
                        return true;
                    }
                });
                NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {

                    public boolean isAccepted(ProxyGroup value) {
                        System.out.println("Loading ProxyGroup: " + value.getName());
                        CloudNet.getInstance().setupProxy(value);
                        return true;
                    }
                });
                CloudNet.getInstance().getNetworkManager().reload();
                CloudNet.getInstance().getNetworkManager().updateAll();
                CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {

                    @Override
                    public void accept(Wrapper wrapper) {
                        wrapper.updateWrapper();
                    }
                });
                sender.sendMessage("[RELOAD] Reloading was completed successfully");
            }
            if (args[0].equalsIgnoreCase("wrapper")) {
                for (Wrapper wrapper : CloudNet.getInstance().getWrappers().values()) {
                    if (wrapper.getChannel() != null)
                        wrapper.writeCommand("reload");
                }
            }
            break;
        default:
            sender.sendMessage("reload ALL | Loads all groups as well as modules, permissions, etc.", "reload CONFIG | Reload the configuration file, and its server groups etc.", "reload WRAPPER | Dispatched on all wrappers the command \"reload\"");
            break;
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup)

Example 2 with ServerGroup

use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.

the class CommandDelete method onExecuteCommand.

@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
    switch(args.length) {
        case 2:
            if (args[0].equalsIgnoreCase("serverGroup")) {
                if (CloudNet.getInstance().getServerGroups().containsKey(args[1])) {
                    ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(args[1]);
                    CloudNet.getInstance().getConfig().deleteGroup(serverGroup);
                    CloudNet.getInstance().getServerGroups().remove(args[1]);
                    CloudNet.getInstance().getNetworkManager().updateAll();
                    for (MinecraftServer minecraftServer : CloudNet.getInstance().getServers(args[1])) {
                        minecraftServer.getWrapper().stopServer(minecraftServer);
                    }
                    sender.sendMessage("The group was successfully deleted");
                } else {
                    sender.sendMessage("The server group doesn't exists");
                }
            }
            break;
        default:
            sender.sendMessage("delete serverGroup <name>");
            break;
    }
}
Also used : ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer)

Example 3 with ServerGroup

use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.

the class CloudPriorityStartupHandler method onHandle.

@Override
public void onHandle(CloudNet cloudNet) {
    double onlineCount = CloudNet.getInstance().getNetworkManager().newCloudNetwork().getOnlineCount();
    for (ServerGroup group : CloudNet.getInstance().getServerGroups().values()) {
        if (group.getPriorityService().getGlobal().getOnlineServers() == 0 || group.getPriorityService().getGlobal().getOnlineCount() == 0 || group.getGroupMode() == ServerGroupMode.STATIC || group.isMaintenance())
            continue;
        double priority = (group.getPriorityService().getGlobal().getOnlineServers() / ((double) group.getPriorityService().getGlobal().getOnlineCount())) * (onlineCount == 0 ? 1.0D : (onlineCount));
        Collection<String> servers = CloudNet.getInstance().getServersAndWaitings(group.getName());
        if (servers.size() == 0 && servers.size() < (priority <= 1 ? 1 : priority)) {
            CloudNet.getInstance().startGameServer(group);
            continue;
        }
        if (servers.size() < (priority <= 1 ? 1 : priority)) {
            CloudNet.getInstance().startGameServer(group, new Document(), true);
        }
    }
}
Also used : ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Example 4 with ServerGroup

use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.

the class PacketInUpdateServerGroup method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    ServerGroup proxyGroup = data.getObject("group", new TypeToken<ServerGroup>() {
    }.getType());
    CloudNet.getInstance().getConfig().createGroup(proxyGroup);
    try {
        CloudNet.getInstance().getConfig().load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    CloudNet.getInstance().getServerGroups().clear();
    CloudNet.getInstance().getProxyGroups().clear();
    NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Loading server group: " + value.getName());
            return true;
        }
    });
    NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Loading proxy group: " + value.getName());
            return true;
        }
    });
    CloudNet.getInstance().getNetworkManager().reload();
    CloudNet.getInstance().getNetworkManager().updateAll0();
    CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {

        @Override
        public void accept(Wrapper wrapper) {
            wrapper.updateWrapper();
        }
    });
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken)

Example 5 with ServerGroup

use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.

the class UtilExample method toDo.

public void toDo() {
    // Returns the OnlineCount
    CloudAPI.getInstance().getOnlineCount();
    /*===========================*/
    // Returns a proxygroup
    ProxyGroup proxyGroup = CloudAPI.getInstance().getProxyGroupData("Bungee");
    proxyGroup.getWrapper().add("Second-Wrapper");
    // update a proxy group
    CloudAPI.getInstance().updateProxyGroup(proxyGroup);
    // Returns from the CloudNet synchronized the server group objective
    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup("Lobby");
    serverGroup.setMaintenance(true);
    // update the server group
    CloudAPI.getInstance().updateServerGroup(serverGroup);
    // Returns a cached server group
    SimpleServerGroup simpleServerGroup = CloudAPI.getInstance().getServerGroupData("Lobby");
    if (simpleServerGroup.isMaintenance()) {
        System.out.println("Is a maintenance group");
    }
    // start a simple game server
    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData("Lobby"));
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup)

Aggregations

ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)16 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)8 TypeToken (com.google.gson.reflect.TypeToken)7 Document (de.dytanic.cloudnet.lib.utility.document.Document)5 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 SimpleServerGroup (de.dytanic.cloudnet.lib.server.SimpleServerGroup)3 Template (de.dytanic.cloudnet.lib.server.template.Template)3 WrapperExternal (de.dytanic.cloudnet.lib.network.WrapperExternal)2 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)2 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)2 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)2 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)2 PriorityStopTask (de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask)2 CloudNetwork (de.dytanic.cloudnet.lib.CloudNetwork)1 CloudServerMeta (de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta)1 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)1 AutoSlot (de.dytanic.cloudnet.lib.proxylayout.AutoSlot)1 ServerProcessMeta (de.dytanic.cloudnet.lib.server.ServerProcessMeta)1 DevService (de.dytanic.cloudnet.lib.server.advanced.DevService)1