Search in sources :

Example 16 with ServerGroup

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

the class CloudConfig method getServerGroups.

public java.util.Map<String, ServerGroup> getServerGroups() {
    /*
        Collection<ServerGroup> collection = serviceDocument.getObject("serverGroups", new TypeToken<Collection<ServerGroup>>() {
        }.getType());
        return MapWrapper.collectionCatcherHashMap(collection, new Catcher<String, ServerGroup>() {
            @Override
            public String doCatch(ServerGroup key)
            {
                return key.getName();
            }
        });
        */
    Map<String, ServerGroup> groups = NetworkUtils.newConcurrentHashMap();
    if (serviceDocument.contains("serverGroups")) {
        Collection<ServerGroup> collection = serviceDocument.getObject("serverGroups", new TypeToken<Collection<ServerGroup>>() {
        }.getType());
        for (ServerGroup serverGroup : collection) createGroup(serverGroup);
        serviceDocument.remove("serverGroups");
        serviceDocument.saveAsConfig(servicePath);
    }
    File groupsDirectory = new File("groups");
    Document entry;
    if (groupsDirectory.isDirectory())
        for (File file : groupsDirectory.listFiles()) {
            if (file.getName().endsWith(".json"))
                try {
                    entry = Document.$loadDocument(file);
                    ServerGroup serverGroup = entry.getObject("group", ServerGroup.TYPE);
                    groups.put(serverGroup.getName(), serverGroup);
                } catch (Throwable ex) {
                    System.out.println("Cannot load servergroup file [" + file.getName() + "]");
                }
        }
    return groups;
}
Also used : ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken) Document(de.dytanic.cloudnet.lib.utility.document.Document) File(java.io.File)

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