use of net.md_5.bungee.api.connection.Server in project CloudNet by Dytanic.
the class GameServer method bootstrap.
@Override
public boolean bootstrap() throws Exception {
serverProcess.setServerStage(ServerStage.DOWNLOAD);
long startupTime = System.currentTimeMillis();
for (ServerInstallablePlugin url : serverProcess.getMeta().getDownloadablePlugins()) {
switch(url.getPluginResourceType()) {
case URL:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
try {
URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
case MASTER:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
try {
URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
urlConnection.setRequestProperty("-Xmessage", "plugin");
urlConnection.setRequestProperty("-Xvalue", url.getName());
urlConnection.connect();
System.out.println("Downloading " + url.getName() + ".jar");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
System.out.println("Download was completed successfully!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
default:
break;
}
}
for (ServerInstallablePlugin url : serverProcess.getMeta().getTemplate().getInstallablePlugins()) {
switch(url.getPluginResourceType()) {
case URL:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
try {
URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
case MASTER:
{
if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
try {
URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
urlConnection.setRequestProperty("-Xmessage", "plugin");
urlConnection.setRequestProperty("-Xvalue", url.getName());
urlConnection.connect();
System.out.println("Downloading " + url.getName() + ".jar");
Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
System.out.println("Download was completed successfully!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
break;
default:
break;
}
}
if (serverGroup.getTemplates().size() == 0 && serverProcess.getMeta().getUrl() == null)
return false;
if (serverGroup.getGroupMode().equals(ServerGroupMode.STATIC)) {
if (!Files.exists(dir))
if (!a())
return false;
} else if (!a())
return false;
for (ServerInstallablePlugin plugin : serverProcess.getMeta().getDownloadablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
for (ServerInstallablePlugin plugin : serverProcess.getMeta().getTemplate().getInstallablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
serverProcess.setServerStage(ServerStage.COPY);
if (serverGroup.getServerType().equals(ServerGroupType.BUKKIT))
if (!Files.exists(Paths.get(path + "/spigot.jar")))
FileCopy.copyFileToDirectory(new File("local/spigot.jar"), new File(path));
if (serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
if (!Files.exists(Paths.get(path + "/config")))
Files.createDirectories(Paths.get(path + "/config"));
if (!Files.exists(Paths.get(path + "/config/glowstone.yml")))
FileCopy.insertData("files/glowstone.yml", path + "/config/glowstone.yml");
}
if (!Files.exists(Paths.get(path + "/server.properties")))
FileCopy.insertData("files/server.properties", path + "/server.properties");
if (!Files.exists(Paths.get(path + "/bukkit.yml")))
FileCopy.insertData("files/bukkit.yml", path + "/bukkit.yml");
if (!serverProcess.getMeta().isOnlineMode())
if (!Files.exists(Paths.get(path + "/spigot.yml")))
FileCopy.insertData("files/spigot.yml", path + "/spigot.yml");
Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
FileCopy.copyFilesInDirectory(new File("local/global"), new File(path));
String motd = "Default Motd";
int maxPlayers = 0;
if (!serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
Properties properties = new Properties();
try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/server.properties")))) {
properties.load(inputStreamReader);
}
Enumeration enumeration = this.serverProcess.getMeta().getServerProperties().keys();
while (enumeration.hasMoreElements()) {
String x = enumeration.nextElement().toString();
properties.setProperty(x, this.serverProcess.getMeta().getServerProperties().getProperty(x));
}
properties.setProperty("server-ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
properties.setProperty("server-port", serverProcess.getMeta().getPort() + NetworkUtils.EMPTY_STRING);
properties.setProperty("online-mode", serverProcess.getMeta().isOnlineMode() + NetworkUtils.EMPTY_STRING);
// properties.setProperty("server-name", serverProcess.getMeta().getServiceId().getServerId());
motd = properties.getProperty("motd");
maxPlayers = Integer.parseInt(properties.getProperty("max-players"));
try (OutputStream outputStream = Files.newOutputStream(Paths.get(path + "/server.properties"))) {
properties.store(outputStream, "CloudNet-Wrapper EDIT");
}
} else {
try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(inputStreamReader);
Configuration section = configuration.getSection("server");
section.set("ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
section.set("port", serverProcess.getMeta().getPort());
maxPlayers = section.getInt("max-players");
motd = section.getString("motd");
configuration.set("server", section);
configuration.set("console.use-jline", false);
try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, outputStreamWriter);
}
}
}
this.serverInfo = new ServerInfo(serverProcess.getMeta().getServiceId(), CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP(), this.getServerProcess().getMeta().getPort(), false, new ArrayList<>(), serverProcess.getMeta().getMemory(), motd, 0, maxPlayers, ServerState.OFFLINE, this.serverProcess.getMeta().getServerConfig(), serverProcess.getMeta().getTemplate());
if (!Files.exists(Paths.get(path + "/CLOUD"))) {
Files.createDirectory(Paths.get(path + "/CLOUD"));
}
new Document().append("serviceId", serverProcess.getMeta().getServiceId()).append("serverProcess", serverProcess.getMeta()).append("serverInfo", serverInfo).append("ssl", CloudNetWrapper.getInstance().getOptionSet().has("ssl")).append("memory", serverProcess.getMeta().getMemory()).saveAsConfig(Paths.get(path + "/CLOUD/config.json"));
new Document().append("connection", new ConnectableAddress(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost(), CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetPort())).saveAsConfig(Paths.get(path + "/CLOUD/connection.json"));
CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutAddServer(this.serverInfo, this.serverProcess.getMeta()));
System.out.println("Server " + toString() + " started in [" + (System.currentTimeMillis() - startupTime) + " milliseconds]");
this.startupTimeStamp = System.currentTimeMillis();
startProcess();
serverProcess.setServerStage(ServerStage.PROCESS);
CloudNetWrapper.getInstance().getServers().put(this.serverProcess.getMeta().getServiceId().getServerId(), this);
serverProcess.setServerStage(ServerStage.NET_INIT);
return true;
}
use of net.md_5.bungee.api.connection.Server in project CloudNet by Dytanic.
the class ProxiedListener method initTabHeaderFooter.
private void initTabHeaderFooter(ProxiedPlayer proxiedPlayer) {
TabList tabList = CloudProxy.getInstance().getProxyGroup().getProxyConfig().getTabList();
proxiedPlayer.setTabHeader(new TextComponent(ChatColor.translateAlternateColorCodes('&', tabList.getHeader().replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%server%", (proxiedPlayer.getServer() != null ? proxiedPlayer.getServer().getInfo().getName() : CloudProxy.getInstance().getProxyGroup().getName())).replace("%online_players%", CloudAPI.getInstance().getOnlineCount() + NetworkUtils.EMPTY_STRING).replace("%max_players%", CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers() + NetworkUtils.EMPTY_STRING).replace("%group%", (proxiedPlayer.getServer() != null && CloudProxy.getInstance().getCachedServers().containsKey(proxiedPlayer.getServer().getInfo().getName()) ? CloudProxy.getInstance().getCachedServers().get(proxiedPlayer.getServer().getInfo().getName()).getServiceId().getGroup() : "Hub")).replace("%proxy_group%", CloudProxy.getInstance().getProxyGroup().getName()))), new TextComponent(ChatColor.translateAlternateColorCodes('&', tabList.getFooter().replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%server%", (proxiedPlayer.getServer() != null ? proxiedPlayer.getServer().getInfo().getName() : CloudProxy.getInstance().getProxyGroup().getName())).replace("%online_players%", CloudAPI.getInstance().getOnlineCount() + NetworkUtils.EMPTY_STRING).replace("%max_players%", CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers() + NetworkUtils.EMPTY_STRING).replace("%group%", (proxiedPlayer.getServer() != null && CloudProxy.getInstance().getCachedServers().containsKey(proxiedPlayer.getServer().getInfo().getName()) ? CloudProxy.getInstance().getCachedServers().get(proxiedPlayer.getServer().getInfo().getName()).getServiceId().getGroup() : "Hub")).replace("%proxy_group%", CloudProxy.getInstance().getProxyGroup().getName()))));
}
use of net.md_5.bungee.api.connection.Server 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;
}
}
use of net.md_5.bungee.api.connection.Server in project solinia3-core by mixxit.
the class CommandCharacter method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player))
return false;
Player player = (Player) sender;
try {
ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
if (args.length == 0) {
player.sendMessage("Your Characters: ");
String main = "ALT";
if (solplayer.isMain()) {
main = "MAIN";
}
player.sendMessage("- " + ChatColor.LIGHT_PURPLE + solplayer.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - " + ChatColor.GREEN + "ACTIVE" + ChatColor.RESET);
for (ISoliniaPlayer character : StateManager.getInstance().getPlayerManager().getCharactersByPlayerUUID(player.getUniqueId())) {
if (character.getCharacterId().equals(solplayer.getCharacterId()))
continue;
if (character.isMain()) {
main = "MAIN";
} else {
main = "ALT";
}
TextComponent tc = new TextComponent();
tc.setText("- " + ChatColor.LIGHT_PURPLE + character.getFullNameWithTitle() + ChatColor.RESET + " " + main + " - ");
String details = ChatColor.GOLD + character.getFullNameWithTitle() + " Level: " + character.getLevel() + ChatColor.RESET;
TextComponent tc2 = new TextComponent();
String changetext = "/character load " + character.getCharacterId().toString();
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
tc2.setText(ChatColor.RED + "Already changed this session" + ChatColor.RESET);
} else {
tc2.setText(ChatColor.AQUA + "[Click to Switch]" + ChatColor.RESET);
tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, changetext));
}
tc.addExtra(tc2);
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
sender.spigot().sendMessage(tc);
}
player.sendMessage("Note, new characters may not be visible for up to 15 minutes");
player.sendMessage("Use '/character new' to create a new character");
} else {
switch(args[0].toUpperCase()) {
case "NEW":
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
return true;
}
ISoliniaPlayer newPlayer = StateManager.getInstance().getPlayerManager().createNewPlayerAlt(plugin, player);
if (newPlayer != null) {
player.sendMessage("Your character has been stored and a new character created");
player.sendMessage("Please check you have not dropped any items due to your character change");
} else {
player.sendMessage("Problem creating your new character");
}
break;
case "LOAD":
if (args.length < 2) {
player.sendMessage("You must provide the character UUID");
return true;
}
if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(player.getUniqueId()) != null) {
player.sendMessage("You can only change your character once per server session. Please wait for the next 4 hourly restart");
return true;
}
UUID characterUUID = UUID.fromString(args[1]);
ISoliniaPlayer loadedPlayer = StateManager.getInstance().getPlayerManager().loadPlayerAlt(plugin, player, characterUUID);
if (loadedPlayer != null) {
player.sendMessage("Your character has been stored and your new character loaded");
player.sendMessage("Please check you have not dropped any items due to your character change");
} else {
player.sendMessage("Problem loading requested character");
}
break;
default:
player.sendMessage("Unknown character subcommand");
break;
}
}
} catch (CoreStateInitException e) {
}
return true;
}
use of net.md_5.bungee.api.connection.Server in project ServerSelectorX by ServerSelectorX.
the class SelectorMenu method onOptionClick.
@Override
public boolean onOptionClick(OptionClickEvent event) {
int slot = event.getPosition();
Player player = event.getPlayer();
String action = config.getString("menu." + slot + ".action");
if (action == null) {
// If the action is null (so 'slot' is not found in the config) it is probably a wildcard
action = config.getString("menu.-1.action");
if (action == null) {
// If it is still null it must be missing
action = "msg:Action missing";
}
}
if (action.startsWith("url:")) {
// Send url message
String url = action.substring(4);
String message = Colors.parseColors(config.getString("url-message", "&3&lClick here"));
player.spigot().sendMessage(new ComponentBuilder(message).event(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).create());
return true;
} else if (action.startsWith("cmd:")) {
// Execute command
String command = action.substring(4);
// Send command 2 ticks later to let the GUI close first (for commands that open a GUI)
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), () -> {
Bukkit.dispatchCommand(player, Main.PLACEHOLDER_API.parsePlaceholders(player, command));
}, 2);
return true;
} else if (action.startsWith("bungeecmd:")) {
// BungeeCord command
String command = action.substring(10);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.format("sync player bungee %s %s", player.getName(), Main.PLACEHOLDER_API.parsePlaceholders(player, command)));
return true;
} else if (action.startsWith("sel:")) {
// Open selector
String configName = action.substring(4);
FileConfiguration config = Main.getConfigurationManager().getByName(configName);
if (config == null) {
player.sendMessage(ChatColor.RED + "This server selector does not exist.");
return true;
} else {
new SelectorMenu(player, config).open();
return false;
}
} else if (action.startsWith("world:")) {
// Teleport to world
String worldName = action.substring(6);
World world = Bukkit.getWorld(worldName);
if (world == null) {
player.sendMessage(ChatColor.RED + "A world with the name " + worldName + " does not exist.");
return true;
} else {
player.teleport(world.getSpawnLocation());
return true;
}
} else if (action.startsWith("srv:")) {
// Teleport to server
String serverName = action.substring(4);
Main.teleportPlayerToServer(player, serverName);
return true;
} else if (action.startsWith("msg:")) {
// Send message
String message = action.substring(4);
player.sendMessage(Main.PLACEHOLDER_API.parsePlaceholders(player, message));
return true;
} else if (action.equals("close")) {
// Return true = close
return true;
} else {
// Return false = stay open
return false;
}
}
Aggregations