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;
}
}
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;
}
}
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);
}
}
}
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();
}
});
}
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"));
}
Aggregations