mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-01-10 18:07:54 +01:00
Restructure the Download packet group
The Download group of packets was in desperate need for a restructuring. Now, instead of using `DownloadServerList` to list everything, different object types now are downloaded through their own seperate packets. (Improving network efficiency)
This commit is contained in:
parent
86fbb2c2b6
commit
545565512b
@ -1,6 +1,6 @@
|
||||
# ![https://s3.postimg.cc/dikyxlz5v/Sub_Banner.png](https://s3.postimg.cc/dikyxlz5v/Sub_Banner.png)
|
||||
[![Build Status](https://src.me1312.net/jenkins/job/SubServers%20Platform/badge/icon)](https://src.me1312.net/jenkins/job/SubServers%20Platform/)
|
||||
[![Release Verison](https://img.shields.io/github/release/ME1312/SubServers-2/all.svg)](https://github.com/ME1312/SubServers-2/releases) [![Snapshot Verison](https://img.shields.io/badge/dynamic/xml.svg?label=snapshot&url=https%3A%2F%2Fsrc.me1312.net%2Fmaven%2Fnet%2FME1312%2FSubServers%2FSubServers.Bungee%2Fmaven-metadata.xml&query=%2F%2Fversioning%2Frelease&colorB=blue)](https://src.me1312.net/jenkins/job/SubServers%20Platform/)<br><br>
|
||||
[![Release Verison](https://img.shields.io/github/release/ME1312/SubServers-2/all.svg)](https://github.com/ME1312/SubServers-2/releases) [![Snapshot Verison](https://img.shields.io/badge/dynamic/xml.svg?label=snapshot&url=https%3A%2F%2Fsrc.me1312.net%2Fmaven%2Fnet%2FME1312%2FSubServers%2FSubServers.Bungee%2Fmaven-metadata.xml&query=%2F%2Fversioning%2Frelease&colorB=blue)](https://src.me1312.net/jenkins/job/SubServers%20Platform/) [![Discord](https://img.shields.io/discord/307936188134850560.svg)](https://discord.gg/gKWpT2K)<br><br>
|
||||
SubServers 2 is a rewrite of SubServers, the Server Management Platform.<br>
|
||||
> [https://www.spigotmc.org/resources/subservers-bungee.11264/](https://www.spigotmc.org/resources/subservers-bungee.11264/)<br>
|
||||
> [https://www.spigotmc.org/resources/subservers-host.38833/](https://www.spigotmc.org/resources/subservers-host.38833/)<br>
|
||||
|
@ -91,7 +91,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
public boolean isRedis() {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
return plugin.redis && Util.getDespiteException(() -> plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName())) != null, false);
|
||||
return plugin.redis != null && Util.getDespiteException(() -> plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName())) != null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
if (plugin.redis) {
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID player : (Set<UUID>) plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName())))
|
||||
players.add(new NamedContainer<>((String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player)), player));
|
||||
|
@ -92,7 +92,7 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
public Collection<NamedContainer<String, UUID>> getGlobalPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
if (plugin.redis) {
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID player : (Set<UUID>) plugin.redis("getPlayersOnServer", new NamedContainer<>(String.class, getName()))) players.add(new NamedContainer<>((String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player)), player));
|
||||
} catch (Exception e) {}
|
||||
|
@ -80,6 +80,7 @@ Lang:
|
||||
'Interface.Generic.Downloading.Title-Color-Alt': '&3'
|
||||
'Interface.Generic.Downloading.Response': '&eWaiting for response'
|
||||
'Interface.Generic.Invalid-Permission': '&4You need &n$str$'
|
||||
'Interface.Proxy-Menu.Proxy-Player-Count': '&2$int$ Player(s) Online'
|
||||
'Interface.Proxy-Menu.Proxy-Master': '&8Master Proxy'
|
||||
'Interface.Proxy-Menu.Proxy-SubData': '&9SubData Only'
|
||||
'Interface.Proxy-Menu.Proxy-Redis': '&7Redis Only'
|
||||
|
@ -54,11 +54,11 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
try {
|
||||
if (data.getSection("creator").getString("name").contains(" ")) {
|
||||
client.sendPacket(new PacketCreateServer(3, "server names cannot have spaces", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(3, "Server names cannot have spaces", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (plugin.api.getSubServers().keySet().contains(data.getSection("creator").getString("name").toLowerCase()) || SubCreator.isReserved(data.getSection("creator").getString("name"))) {
|
||||
client.sendPacket(new PacketCreateServer(3, "There is already a subserver with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(4, "There is already a subserver with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!plugin.hosts.keySet().contains(data.getSection("creator").getString("host").toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(4, "There is no Host with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(5, "There is no Host with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplates().keySet().contains(data.getSection("creator").getString("template").toLowerCase()) ||
|
||||
!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")).isEnabled()) {
|
||||
client.sendPacket(new PacketCreateServer(6, "There is no template with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
@ -93,6 +93,6 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadGroupInfo(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param group Group (or null for all)
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadGroupInfo(SubPlugin plugin, String group, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
|
||||
YAMLSection groups = new YAMLSection();
|
||||
for (String group : plugin.api.getGroups().keySet()) {
|
||||
if (this.group == null || this.group.length() <= 0 || this.group.equalsIgnoreCase(group)) {
|
||||
YAMLSection servers = new YAMLSection();
|
||||
for (Server server : plugin.api.getGroup(group)) {
|
||||
servers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
}
|
||||
groups.set(group, servers);
|
||||
}
|
||||
}
|
||||
data.set("groups", groups);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadGroupInfo(plugin, (data.contains("group"))?data.getRawString("group"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
@ -1,20 +1,23 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Download Host Info Packet
|
||||
*/
|
||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private Host host;
|
||||
private String host;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
@ -23,6 +26,7 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadHostInfo(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -30,38 +34,39 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param host Host
|
||||
* @param host Host (or null for all)
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadHostInfo(SubPlugin plugin, Host host, String id) {
|
||||
public PacketDownloadHostInfo(SubPlugin plugin, String host, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
YAMLSection info = new YAMLSection();
|
||||
|
||||
if (host != null) {
|
||||
data.set("valid", true);
|
||||
info = new YAMLSection(host.toString());
|
||||
info.remove("type");
|
||||
} else data.set("valid", false);
|
||||
|
||||
data.set("host", info);
|
||||
YAMLSection hosts = new YAMLSection();
|
||||
for (Host host : plugin.api.getHosts().values()) {
|
||||
if (this.host == null || this.host.length() <= 0 || this.host.equalsIgnoreCase(host.getName())) {
|
||||
hosts.set(host.getName(), new YAMLSection(new Gson().fromJson(host.toString(), Map.class)));
|
||||
}
|
||||
}
|
||||
data.set("hosts", hosts);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadHostInfo(plugin, plugin.api.getHost(data.getRawString("host")), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains("host"))?data.getRawString("host"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadPlatformInfo(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadPlatformInfo(SubPlugin plugin, String id) {
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
YAMLSection subservers = new YAMLSection();
|
||||
subservers.set("version", plugin.api.getWrapperVersion().toString());
|
||||
if (plugin.api.getWrapperBuild() != null) subservers.set("build", plugin.api.getWrapperBuild().toString());
|
||||
subservers.set("last-reload", plugin.resetDate);
|
||||
subservers.set("hosts", plugin.api.getHosts().size());
|
||||
subservers.set("subservers", plugin.api.getSubServers().size());
|
||||
data.set("subservers", subservers);
|
||||
YAMLSection bungee = new YAMLSection();
|
||||
bungee.set("version", plugin.api.getProxyVersion().toString());
|
||||
bungee.set("disabled-cmds", plugin.getConfig().getDisabledCommands());
|
||||
bungee.set("player-limit", plugin.getConfig().getPlayerLimit());
|
||||
bungee.set("servers", plugin.api.getServers().size());
|
||||
LinkedList<YAMLSection> listeners = new LinkedList<YAMLSection>();
|
||||
for (ListenerInfo info : plugin.getConfig().getListeners()) {
|
||||
YAMLSection listener = new YAMLSection();
|
||||
listener.set("forced-hosts", info.getForcedHosts());
|
||||
listener.set("motd", info.getMotd());
|
||||
listener.set("priorities", info.getServerPriority());
|
||||
listener.set("player-limit", info.getMaxPlayers());
|
||||
listeners.add(listener);
|
||||
}
|
||||
bungee.set("listeners", listeners);
|
||||
data.set("bungee", bungee);
|
||||
YAMLSection minecraft = new YAMLSection();
|
||||
LinkedList<String> mcversions = new LinkedList<String>();
|
||||
for (Version version : plugin.api.getGameVersion()) mcversions.add(version.toString());
|
||||
minecraft.set("version", mcversions);
|
||||
minecraft.set("players", plugin.api.getGlobalPlayers().size());
|
||||
data.set("minecraft", minecraft);
|
||||
YAMLSection system = new YAMLSection();
|
||||
YAMLSection os = new YAMLSection();
|
||||
os.set("name", System.getProperty("os.name"));
|
||||
os.set("version", System.getProperty("os.version"));
|
||||
system.set("os", os);
|
||||
YAMLSection java = new YAMLSection();
|
||||
java.set("version", System.getProperty("java.version"));
|
||||
system.set("java", java);
|
||||
data.set("system", system);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadPlatformInfo(plugin, (data != null && data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
for (NamedContainer<String, UUID> player : plugin.api.getGlobalPlayers()) {
|
||||
YAMLSection pinfo = new YAMLSection();
|
||||
pinfo.set("name", player.get());
|
||||
if (plugin.redis) {
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
pinfo.set("server", ((ServerInfo) plugin.redis("getServerFor", new NamedContainer<>(UUID.class, player.get()))).getName());
|
||||
} catch (Exception e) {
|
||||
|
@ -1,21 +1,25 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private String proxy;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
@ -24,6 +28,7 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadProxyInfo(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -31,65 +36,40 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
* New PacketDownloadProxyInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param proxy Proxy (or null for all)
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadProxyInfo(SubPlugin plugin, String id) {
|
||||
public PacketDownloadProxyInfo(SubPlugin plugin, String proxy, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.proxy = proxy;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
YAMLSection subservers = new YAMLSection();
|
||||
subservers.set("version", plugin.api.getWrapperVersion().toString());
|
||||
if (plugin.api.getWrapperBuild() != null) subservers.set("build", plugin.api.getWrapperBuild().toString());
|
||||
subservers.set("last-reload", plugin.resetDate);
|
||||
subservers.set("hosts", plugin.api.getHosts().size());
|
||||
subservers.set("subservers", plugin.api.getSubServers().size());
|
||||
data.set("subservers", subservers);
|
||||
YAMLSection bungee = new YAMLSection();
|
||||
bungee.set("version", plugin.api.getProxyVersion().toString());
|
||||
bungee.set("disabled-cmds", plugin.getConfig().getDisabledCommands());
|
||||
bungee.set("player-limit", plugin.getConfig().getPlayerLimit());
|
||||
bungee.set("servers", plugin.api.getServers().size());
|
||||
LinkedList<YAMLSection> listeners = new LinkedList<YAMLSection>();
|
||||
for (ListenerInfo info : plugin.getConfig().getListeners()) {
|
||||
YAMLSection listener = new YAMLSection();
|
||||
listener.set("forced-hosts", info.getForcedHosts());
|
||||
listener.set("motd", info.getMotd());
|
||||
listener.set("priorities", info.getServerPriority());
|
||||
listener.set("player-limit", info.getMaxPlayers());
|
||||
listeners.add(listener);
|
||||
data.set("id", id);
|
||||
|
||||
YAMLSection proxies = new YAMLSection();
|
||||
for (Proxy proxy : plugin.api.getProxies().values()) {
|
||||
if (this.proxy == null || this.proxy.equalsIgnoreCase(proxy.getName())) {
|
||||
proxies.set(proxy.getName(), new YAMLSection(new Gson().fromJson(proxy.toString(), Map.class)));
|
||||
}
|
||||
}
|
||||
bungee.set("listeners", listeners);
|
||||
data.set("bungee", bungee);
|
||||
YAMLSection minecraft = new YAMLSection();
|
||||
LinkedList<String> mcversions = new LinkedList<String>();
|
||||
for (Version version : plugin.api.getGameVersion()) mcversions.add(version.toString());
|
||||
minecraft.set("version", mcversions);
|
||||
minecraft.set("players", plugin.api.getGlobalPlayers().size());
|
||||
data.set("minecraft", minecraft);
|
||||
YAMLSection system = new YAMLSection();
|
||||
YAMLSection os = new YAMLSection();
|
||||
os.set("name", System.getProperty("os.name"));
|
||||
os.set("version", System.getProperty("os.version"));
|
||||
system.set("os", os);
|
||||
YAMLSection java = new YAMLSection();
|
||||
java.set("version", System.getProperty("java.version"));
|
||||
system.set("java", java);
|
||||
data.set("system", system);
|
||||
data.set("proxies", proxies);
|
||||
if ((this.proxy == null || this.proxy.length() <= 0) && plugin.api.getMasterProxy() != null) data.set("master", new YAMLSection(new Gson().fromJson(plugin.api.getMasterProxy().toString(), Map.class)));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadProxyInfo(plugin, (data != null && data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketDownloadProxyInfo(plugin, (data.contains("proxy"))?data.getRawString("proxy"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
@ -18,7 +19,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private Server server;
|
||||
private String server;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
@ -35,40 +36,39 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
* New PacketDownloadServerInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param server Server
|
||||
* @param server Server (or null for all)
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadServerInfo(SubPlugin plugin, Server server, String id) {
|
||||
public PacketDownloadServerInfo(SubPlugin plugin, String server, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("type", (server == null)?"invalid":((server instanceof SubServer)?"subserver":"server"));
|
||||
YAMLSection info = new YAMLSection();
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
|
||||
if (server != null) {
|
||||
info = new YAMLSection(new Gson().fromJson(server.toString(), Map.class));
|
||||
info.remove("type");
|
||||
YAMLSection exServers = new YAMLSection();
|
||||
for (Server server : plugin.api.getServers().values()) {
|
||||
if (this.server == null || this.server.length() <= 0 || this.server.equalsIgnoreCase(server.getName())) {
|
||||
exServers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
}
|
||||
}
|
||||
|
||||
json.set("server", info);
|
||||
return json;
|
||||
data.set("servers", exServers);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadServerInfo(plugin, plugin.api.getServer(data.getRawString("server")), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketDownloadServerInfo(plugin, (data.contains("server"))?data.getRawString("server"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -1,106 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Download Server List Packet
|
||||
*/
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadServerList(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param host Host (or null for all)
|
||||
* @param group Group (or null for all)
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadServerList(SubPlugin plugin, String host, String group, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
|
||||
YAMLSection proxies = new YAMLSection();
|
||||
for (Proxy proxy : plugin.proxies.values()) {
|
||||
proxies.set(proxy.getName(), new YAMLSection(new Gson().fromJson(proxy.toString(), Map.class)));
|
||||
}
|
||||
data.set("proxies", proxies);
|
||||
if (plugin.redis) data.set("master-proxy", Util.getDespiteException(() -> plugin.redis("getServerId"), null));
|
||||
|
||||
YAMLSection exServers = new YAMLSection();
|
||||
for (Server server : plugin.exServers.values()) {
|
||||
exServers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
}
|
||||
data.set("servers", exServers);
|
||||
|
||||
if (this.host == null || !this.host.equals("")) {
|
||||
YAMLSection hosts = new YAMLSection();
|
||||
for (Host host : plugin.api.getHosts().values()) {
|
||||
if (this.host == null || this.host.equalsIgnoreCase(host.getName())) {
|
||||
hosts.set(host.getName(), new YAMLSection(new Gson().fromJson(host.toString(), Map.class)));
|
||||
}
|
||||
}
|
||||
data.set("hosts", hosts);
|
||||
}
|
||||
|
||||
if (this.group == null || !this.group.equals("")) {
|
||||
YAMLSection groups = new YAMLSection();
|
||||
for (String group : plugin.api.getGroups().keySet()) {
|
||||
if (this.group == null || this.group.equalsIgnoreCase(group)) {
|
||||
YAMLSection servers = new YAMLSection();
|
||||
for (Server server : plugin.api.getGroup(group)) {
|
||||
servers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
}
|
||||
groups.set(group, servers);
|
||||
}
|
||||
}
|
||||
data.set("groups", groups);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadServerList(plugin, (data.contains("host"))?data.getRawString("host"):null, (data.contains("group"))?data.getRawString("group"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -66,16 +66,16 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(5, "That SubServer's Host is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(5, "That SubServer is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStartServer(6, "That SubServer is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStartServer(6, "That SubServer is already running", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketStartServer(7, "That SubServer is already running", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (SubServer server : ((SubServer) servers.get(data.getRawString("server").toLowerCase())).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += server.getName();
|
||||
}
|
||||
client.sendPacket(new PacketStartServer(7, "Cannot start SubServer while these servers are running: " + list, (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketStartServer(8, "Cannot start SubServer while these servers are running: " + list, (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).start((data.contains("player"))?UUID.fromString(data.getRawString("player")):null)) {
|
||||
client.sendPacket(new PacketStartServer(0, "Starting SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
@ -91,6 +91,6 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
@ -87,13 +86,14 @@ public final class SubDataServer {
|
||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(plugin), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(plugin), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(plugin), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(plugin), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(plugin), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(plugin), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(plugin), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(plugin), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(plugin), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(plugin), "SubServers", "DownloadServerList");
|
||||
registerPacket(new PacketEditServer(plugin), "SubServers", "EditServer");
|
||||
registerPacket(new PacketExAddServer(), "SubServers", "ExAddServer");
|
||||
registerPacket(new PacketExConfigureHost(plugin), "SubServers", "ExConfigureHost");
|
||||
@ -113,13 +113,14 @@ public final class SubDataServer {
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubServers", "DownloadServerList");
|
||||
registerPacket(PacketEditServer.class, "SubServers", "EditServer");
|
||||
registerPacket(PacketExAddServer.class, "SubServers", "ExAddServer");
|
||||
registerPacket(PacketExConfigureHost.class, "SubServers", "ExConfigureHost");
|
||||
|
@ -528,6 +528,15 @@ public final class SubAPI {
|
||||
return getProxies().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
*
|
||||
* @return Master Proxy
|
||||
*/
|
||||
public Proxy getMasterProxy() {
|
||||
return plugin.redis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get players on this network across all known proxies
|
||||
*
|
||||
@ -536,7 +545,7 @@ public final class SubAPI {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<NamedContainer<String, UUID>> getGlobalPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
if (plugin.redis) {
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
for (UUID player : (Set<UUID>) plugin.redis("getPlayersOnline")) players.add(new NamedContainer<>((String) plugin.redis("getNameFromUuid", new NamedContainer<>(UUID.class, player)), player));
|
||||
} catch (Exception e) {}
|
||||
|
@ -62,7 +62,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public SubServer sudo = null;
|
||||
public static final Version version = Version.fromString("2.13b");
|
||||
|
||||
public boolean redis = false;
|
||||
public Proxy redis = null;
|
||||
public boolean canSudo = false;
|
||||
public final boolean isPatched;
|
||||
public long resetDate = 0;
|
||||
@ -208,9 +208,10 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
* Load SubServers before BungeeCord finishes
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void startListeners() {
|
||||
try {
|
||||
redis = getPluginManager().getPlugin("RedisBungee") != null;
|
||||
if (getPluginManager().getPlugin("RedisBungee") != null) redis = Util.getDespiteException(() -> new Proxy((String) redis("getServerId")), null);
|
||||
reload();
|
||||
|
||||
super.startListeners();
|
||||
@ -271,10 +272,12 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
int proxies = 1;
|
||||
if (redis) {
|
||||
if (redis != null) {
|
||||
try {
|
||||
boolean first = true;
|
||||
String master = (String) redis("getServerId");
|
||||
if (!master.equals(redis.getName())) redis = new Proxy(master);
|
||||
if (!redis.getDisplayName().equals("(master)")) redis.setDisplayName("(master)");
|
||||
for (String name : (List<String>) redis("getAllServers")) {
|
||||
if (!ukeys.contains(name.toLowerCase()) && !master.equals(name)) try {
|
||||
if (first) System.out.println("SubServers > "+((status)?"Rel":"L")+"oading Proxies...");
|
||||
@ -637,7 +640,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object redis(String method, NamedContainer<Class<?>, ?>... args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
if (redis) {
|
||||
if (getPluginManager().getPlugin("RedisBungee") != null) {
|
||||
Object api = getPluginManager().getPlugin("RedisBungee").getClass().getMethod("getApi").invoke(null);
|
||||
Class<?>[] classargs = new Class<?>[args.length];
|
||||
Object[] objargs = new Object[args.length];
|
||||
|
@ -5,6 +5,8 @@ import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Callback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -121,14 +123,8 @@ public class InternalUIHandler implements UIHandler, Listener {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]), 4 * 20);
|
||||
} else {
|
||||
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
boolean match = false;
|
||||
for (String tmphost : data.getSection("hosts").getKeys()) {
|
||||
for (String tmpsubserver : data.getSection("hosts").getSection(tmphost).getSection("servers").getKeys()) {
|
||||
if (tmpsubserver.equalsIgnoreCase(m.getString("message"))) match = true;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
plugin.api.getServer(m.getString("message"), server -> {
|
||||
if (server != null) {
|
||||
gui.setDownloading(null);
|
||||
if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Name.Exists-Title"), 4 * 20))
|
||||
player.sendMessage(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Name.Exists"));
|
||||
@ -137,7 +133,7 @@ public class InternalUIHandler implements UIHandler, Listener {
|
||||
((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]).setName(m.getString("message"));
|
||||
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (ChatColor.stripColor(item).equals(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template")))) {
|
||||
@ -215,22 +211,22 @@ public class InternalUIHandler implements UIHandler, Listener {
|
||||
gui.back();
|
||||
} else {
|
||||
player.closeInventory();
|
||||
final Container<Renderer> plugin = new Container<Renderer>(null);
|
||||
for (Renderer renderer : InternalUIRenderer.hostPlugins.values()) {
|
||||
final Container<Renderer<Host>> plugin = new Container<Renderer<Host>>(null);
|
||||
for (Renderer<Host> renderer : InternalUIRenderer.hostPlugins.values()) {
|
||||
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.set(renderer);
|
||||
}
|
||||
if (plugin.get() == null) {
|
||||
gui.reopen();
|
||||
} else {
|
||||
gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", (String) gui.lastVisitedObjects[0])));
|
||||
this.plugin.subdata.sendPacket(new PacketDownloadHostInfo((String) gui.lastVisitedObjects[0], (json) -> {
|
||||
if (json.getBoolean("valid")) {
|
||||
this.plugin.api.getHost((String) gui.lastVisitedObjects[0], host -> {
|
||||
if (host != null) {
|
||||
gui.setDownloading(null);
|
||||
plugin.get().open(player, json.getSection("host"));
|
||||
plugin.get().open(player, host);
|
||||
} else {
|
||||
gui.back();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -407,22 +403,22 @@ public class InternalUIHandler implements UIHandler, Listener {
|
||||
gui.back();
|
||||
} else {
|
||||
player.closeInventory();
|
||||
Container<Renderer> plugin = new Container<Renderer>(null);
|
||||
for (Renderer renderer : InternalUIRenderer.subserverPlugins.values()) {
|
||||
Container<Renderer<SubServer>> plugin = new Container<Renderer<SubServer>>(null);
|
||||
for (Renderer<SubServer> renderer : InternalUIRenderer.subserverPlugins.values()) {
|
||||
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.set(renderer);
|
||||
}
|
||||
if (plugin.get() == null) {
|
||||
gui.reopen();
|
||||
} else {
|
||||
gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", (String) gui.lastVisitedObjects[0])));
|
||||
this.plugin.subdata.sendPacket(new PacketDownloadServerInfo((String) gui.lastVisitedObjects[0], data -> {
|
||||
if (data.getString("type").equals("subserver")) {
|
||||
this.plugin.api.getSubServer((String) gui.lastVisitedObjects[0], subserver -> {
|
||||
if (subserver != null) {
|
||||
gui.setDownloading(null);
|
||||
plugin.get().open(player, data.getSection("server"));
|
||||
plugin.get().open(player, subserver);
|
||||
} else {
|
||||
gui.back();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubCreator;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -78,14 +80,14 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
|
||||
public void hostMenu(final int page) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Menu.Title")));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, (json) -> {
|
||||
plugin.api.getHosts(hosts -> plugin.api.getGroups(groups -> {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = null;
|
||||
lastPage = page;
|
||||
lastMenu = () -> hostMenu(1);
|
||||
windowHistory.add(() -> hostMenu(page));
|
||||
List<String> hosts = new ArrayList<String>();
|
||||
hosts.addAll(json.getSection("hosts").getKeys());
|
||||
List<Host> index = new LinkedList<Host>();
|
||||
index.addAll(hosts.values());
|
||||
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
@ -97,7 +99,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int i = 0;
|
||||
int min = ((page - 1) * 36);
|
||||
int max = (min + 35);
|
||||
int count = (hosts.size() == 0)?27:((hosts.size() - min >= max)?36:hosts.size() - min);
|
||||
int count = (index.size() == 0)?27:((index.size() - min >= max)?36:index.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Host-Menu.Title"));
|
||||
@ -113,31 +115,31 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
NamedContainer<String, Short> enabled, disabled;
|
||||
|
||||
for (String host : hosts) {
|
||||
if (hosts.indexOf(host) >= min && hosts.indexOf(host) <= max) {
|
||||
for (Host host : index) {
|
||||
if (index.indexOf(host) >= min && index.indexOf(host) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
enabled = (((i & 1) == 0) ? new NamedContainer<>("BLUE_STAINED_GLASS_PANE", (short) 3) : new NamedContainer<>("LIGHT_BLUE_STAINED_GLASS_PANE", (short) 11));
|
||||
disabled = (((i & 1) == 0) ? new NamedContainer<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new NamedContainer<>("RED_STAINED_GLASS_PANE", (short) 14));
|
||||
|
||||
if (json.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
if (host.isEnabled()) {
|
||||
block = createItem("STAINED_GLASS_PANE", enabled.name(), enabled.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + json.getSection("hosts").getSection(host).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + host.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!host.equals(json.getSection("hosts").getSection(host).getString("display")))
|
||||
lore.add(ChatColor.GRAY + host);
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("hosts").getSection(host).getSection("servers").getKeys().size())));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getSection("hosts").getSection(host).getString("address"));
|
||||
if (!host.getName().equals(host.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + host.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size())));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
blockMeta.setLore(lore);
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", disabled.name(), disabled.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.RED + json.getSection("hosts").getSection(host).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.RED + host.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!host.equals(json.getSection("hosts").getSection(host).getString("display")))
|
||||
lore.add(ChatColor.GRAY + host);
|
||||
if (!host.getName().equals(host.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + host.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getSection("hosts").getSection(host).getString("address"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
@ -153,7 +155,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if (hosts.size() == 0) {
|
||||
if (index.size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Host-Menu.No-Hosts"));
|
||||
@ -179,7 +181,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(i++, block);
|
||||
} else i += 2;
|
||||
i++;
|
||||
if (json.getSection("groups").getKeys().size() <= 0) {
|
||||
if (groups.keySet().size() <= 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", (short) 5);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Host-Menu.Server-Menu"));
|
||||
@ -193,7 +195,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
i++;
|
||||
if (hosts.size() - 1 > max) {
|
||||
if (index.size() - 1 > max) {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Generic.Next-Arrow"));
|
||||
@ -207,15 +209,15 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
}));
|
||||
}
|
||||
|
||||
public void hostAdmin(final String host) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").replace("$str$", host)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, (json) -> {
|
||||
windowHistory.add(() -> hostAdmin(host));
|
||||
if (!json.getBoolean("valid")) {
|
||||
public void hostAdmin(final String name) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").replace("$str$", name)));
|
||||
plugin.api.getHost(name, host -> {
|
||||
windowHistory.add(() -> hostAdmin(name));
|
||||
if (host == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = host;
|
||||
lastVisitedObjects[0] = name;
|
||||
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
@ -224,7 +226,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
divMeta.setDisplayName(ChatColor.RESET.toString());
|
||||
div.setItemMeta(divMeta);
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").replace("$str$", json.getSection("host").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.Host-Admin.Title").replace("$str$", host.getDisplayName()));
|
||||
|
||||
int i = 0;
|
||||
while (i < inv.getSize()) {
|
||||
@ -232,12 +234,12 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.create.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.create." + host.toLowerCase()))) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.host.create.*") || Bukkit.getPlayer(player).hasPermission("subservers.host.create." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Creator")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + host.toLowerCase())));
|
||||
} else if (!json.getSection("host").getBoolean("enabled")) {
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + name.toLowerCase())));
|
||||
} else if (!host.isEnabled()) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Creator")));
|
||||
@ -265,7 +267,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
|
||||
if (!json.getSection("host").getBoolean("enabled") || hostPlugins.size() <= 0) {
|
||||
if (!host.isEnabled() || hostPlugins.size() <= 0) {
|
||||
block = div;
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
@ -276,25 +278,25 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(27, block);
|
||||
inv.setItem(28, block);
|
||||
|
||||
if (json.getSection("host").getBoolean("enabled")) {
|
||||
if (host.isEnabled()) {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + json.getSection("host").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + host.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!host.equals(json.getSection("host").getString("display")))
|
||||
lore.add(ChatColor.GRAY + host);
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("host").getSection("servers").getKeys().size())));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getSection("host").getString("address"));
|
||||
if (!host.getName().equals(host.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + host.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size())));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
blockMeta.setLore(lore);
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.RED + json.getSection("host").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.RED + host.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!host.equals(json.getSection("host").getString("display")))
|
||||
lore.add(ChatColor.GRAY + host);
|
||||
if (!host.getName().equals(host.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + host.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + json.getSection("host").getString("address"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
@ -315,7 +317,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void hostCreator(final CreatorOptions options) {
|
||||
@ -324,8 +326,8 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
windowHistory.add(() -> hostCreator(options));
|
||||
lastVisitedObjects[0] = options;
|
||||
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), json -> {
|
||||
if (!json.getBoolean("valid")|| !json.getSection("host").getBoolean("enabled")) {
|
||||
plugin.api.getHost(options.getHost(), host -> {
|
||||
if (host == null || !host.isEnabled()) {
|
||||
lastVisitedObjects[0] = null;
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
@ -337,7 +339,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
divMeta.setDisplayName(ChatColor.RESET.toString());
|
||||
div.setItemMeta(divMeta);
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 54, plugin.api.getLang("SubServers", "Interface.Host-Creator.Title").replace("$str$", json.getSection("host").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 54, plugin.api.getLang("SubServers", "Interface.Host-Creator.Title").replace("$str$", host.getDisplayName()));
|
||||
|
||||
int i = 0;
|
||||
while (i < inv.getSize()) {
|
||||
@ -449,25 +451,24 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void hostCreatorTemplates(final int page, final CreatorOptions options) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template.Title").replace("$str$", options.getHost())));
|
||||
lastVisitedObjects[0] = options;
|
||||
if (!options.init()) lastVisitedObjects[0] = options.getHost();
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), (json) -> {
|
||||
if (!json.getBoolean("valid")|| !json.getSection("host").getBoolean("enabled")) {
|
||||
plugin.api.getHost(options.getHost(), host -> {
|
||||
if (host == null || !host.isEnabled()) {
|
||||
lastVisitedObjects[0] = null;
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
lastPage = page;
|
||||
setDownloading(null);
|
||||
List<String> templates = new ArrayList<String>();
|
||||
for (String template : json.getSection("host").getSection("creator").getSection("templates").getKeys()) {
|
||||
if (json.getSection("host").getSection("creator").getSection("templates").getSection(template).getBoolean("enabled")) templates.add(template);
|
||||
List<SubCreator.ServerTemplate> index = new LinkedList<SubCreator.ServerTemplate>();
|
||||
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) {
|
||||
if (template.isEnabled()) index.add(template);
|
||||
}
|
||||
Collections.sort(templates);
|
||||
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
@ -479,10 +480,10 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int i = 0;
|
||||
int min = ((page - 1) * 36);
|
||||
int max = (min + 35);
|
||||
int count = (templates.size() == 0)?27:((templates.size() - min >= max)?36:templates.size() - min);
|
||||
int count = (index.size() == 0)?27:((index.size() - min >= max)?36:index.size() - min);
|
||||
int area = (count % 9 == 0)?count: (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template.Title").replace("$str$", json.getSection("host").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template.Title").replace("$str$", host.getDisplayName()));
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
@ -493,16 +494,16 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0);
|
||||
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
for (String template : templates) {
|
||||
if (templates.indexOf(template) >= min && templates.indexOf(template) <= max) {
|
||||
for (SubCreator.ServerTemplate template : index) {
|
||||
if (index.indexOf(template) >= min && index.indexOf(template) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
|
||||
block = parseItem(json.getSection("host").getSection("creator").getSection("templates").getSection(template).getString("icon"), new ItemStack(Material.ENDER_CHEST));
|
||||
block = parseItem(template.getIcon(), new ItemStack(Material.ENDER_CHEST));
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + json.getSection("host").getSection("creator").getSection("templates").getSection(template).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + template.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!template.equals(json.getSection("host").getSection("creator").getSection("templates").getSection(template).getString("display")))
|
||||
lore.add(ChatColor.GRAY + template);
|
||||
if (!template.getName().equals(template.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + template.getName());
|
||||
blockMeta.setLore(lore);
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i, block);
|
||||
@ -517,7 +518,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if (templates.size() == 0) {
|
||||
if (index.size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template.No-Templates"));
|
||||
@ -551,7 +552,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
i++;
|
||||
if (templates.size() - 1 > max) {
|
||||
if (index.size() - 1 > max) {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Generic.Next-Arrow"));
|
||||
@ -563,22 +564,22 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void hostPlugin(final int page, final String host) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", host)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(host, (json) -> {
|
||||
windowHistory.add(() -> hostPlugin(page, host));
|
||||
if (!json.getBoolean("valid")) {
|
||||
public void hostPlugin(final int page, final String name) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", name)));
|
||||
plugin.api.getHost(name, host -> {
|
||||
windowHistory.add(() -> hostPlugin(page, name));
|
||||
if (host == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = host;
|
||||
lastVisitedObjects[0] = name;
|
||||
lastPage = page;
|
||||
List<String> renderers = new ArrayList<String>();
|
||||
List<String> renderers = new LinkedList<String>();
|
||||
for (String renderer : renderers) {
|
||||
if (hostPlugins.get(renderer).isEnabled(json.getSection("host"))) renderers.add(renderer);
|
||||
if (hostPlugins.get(renderer).isEnabled(host)) renderers.add(renderer);
|
||||
}
|
||||
Collections.sort(renderers);
|
||||
|
||||
@ -595,7 +596,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int count = (renderers.size() == 0)?27:((renderers.size() - min >= max)?36:renderers.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", json.getSection("host").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", host.getDisplayName()));
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
@ -671,19 +672,19 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void groupMenu(final int page) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Group-Menu.Title")));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, (json) -> {
|
||||
plugin.api.getGroups(groups -> {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = null;
|
||||
lastPage = page;
|
||||
lastMenu = () -> groupMenu(1);
|
||||
windowHistory.add(() -> groupMenu(page));
|
||||
List<String> groups = new ArrayList<String>();
|
||||
groups.addAll(json.getSection("groups").getKeys());
|
||||
List<String> index = new LinkedList<String>();
|
||||
index.addAll(groups.keySet());
|
||||
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
@ -695,7 +696,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int i = 0;
|
||||
int min = ((page - 1) * 36);
|
||||
int max = (min + 35);
|
||||
int count = (groups.size() == 0)?27:((groups.size() - min >= max)?36:groups.size() - min);
|
||||
int count = (index.size() == 0)?27:((index.size() - min >= max)?36:index.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.Group-Menu.Title"));
|
||||
@ -711,8 +712,8 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
NamedContainer<String, Short> color;
|
||||
|
||||
for (String group : groups) {
|
||||
if (groups.indexOf(group) >= min && groups.indexOf(group) <= max) {
|
||||
for (String group : index) {
|
||||
if (index.indexOf(group) >= min && index.indexOf(group) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
color = (((i & 1) == 0) ? new NamedContainer<>("ORANGE_STAINED_GLASS_PANE", (short) 1) : new NamedContainer<>("YELLOW_STAINED_GLASS_PANE", (short) 4));
|
||||
|
||||
@ -720,7 +721,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GOLD + group);
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("groups").getSection(group).getKeys().size())));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(groups.get(group).size())));
|
||||
blockMeta.setLore(lore);
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(i, block);
|
||||
@ -735,7 +736,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
if (groups.size() == 0) {
|
||||
if (index.size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Group-Menu.No-Groups"));
|
||||
@ -769,7 +770,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(i++, block);
|
||||
inv.setItem(i++, block);
|
||||
i++;
|
||||
if (groups.size() - 1 > max) {
|
||||
if (index.size() - 1 > max) {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Generic.Next-Arrow"));
|
||||
@ -780,43 +781,20 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void serverMenu(final int page, final String host, final String group) {
|
||||
setDownloading(ChatColor.stripColor((host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", host)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(host, (host != null)?null:group, json -> {
|
||||
Container<String> hostname = new Container<String>(host);
|
||||
Container<List<Server>> servercontainer = new Container<List<Server>>(new LinkedList<Server>());
|
||||
Runnable renderer = () -> {
|
||||
setDownloading(null);
|
||||
lastPage = page;
|
||||
|
||||
HashMap<String, String> hosts = new HashMap<String, String>();
|
||||
List<String> servers = new ArrayList<String>();
|
||||
List<Server> servers = servercontainer.get();
|
||||
lastVisitedObjects[0] = host;
|
||||
lastVisitedObjects[1] = group;
|
||||
if (host != null && json.getSection("hosts").getKeys().contains(host)) {
|
||||
for (String subserver : json.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
hosts.put(subserver, host);
|
||||
servers.add(subserver);
|
||||
}
|
||||
} else if (group != null && json.getSection("groups").getKeys().contains(group)) {
|
||||
for (String server : json.getSection("groups").getSection(group).getKeys()) {
|
||||
hosts.put(server, (json.getSection("groups").getSection(group).getSection(server).getKeys().contains("host") && json.getSection("hosts").getKeys().contains(json.getSection("groups").getSection(group).getSection(server).getString("host")))?json.getSection("groups").getSection(group).getSection(server).getString("host"):null);
|
||||
servers.add(server);
|
||||
}
|
||||
} else {
|
||||
lastMenu = () -> serverMenu(1, null, null);
|
||||
for (String s : json.getSection("servers").getKeys()) {
|
||||
hosts.put(s, null);
|
||||
servers.add(s);
|
||||
}
|
||||
for (String h : json.getSection("hosts").getKeys()) {
|
||||
for (String ss : json.getSection("hosts").getSection(h).getSection("servers").getKeys()) {
|
||||
hosts.put(ss, h);
|
||||
servers.add(ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(servers);
|
||||
windowHistory.add(() -> serverMenu(page, host, group));
|
||||
|
||||
ItemStack block;
|
||||
@ -832,7 +810,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int count = (servers.size() == 0)?27:((servers.size() - min >= max)?36:servers.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", json.getSection("hosts").getSection(host).getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", hostname.get()));
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
@ -845,7 +823,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
boolean even = (count & 1) == 0 && count < 9;
|
||||
NamedContainer<String, Short> external, online, temp, offline, disabled;
|
||||
|
||||
for (String server : servers) {
|
||||
for (Server server : servers) {
|
||||
if (servers.indexOf(server) >= min && servers.indexOf(server) <= max) {
|
||||
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
|
||||
external = (((i & 1) == 0) ? new NamedContainer<>("WHITE_STAINED_GLASS_PANE", (short) 0) : new NamedContainer<>("LIGHT_GRAY_STAINED_GLASS_PANE", (short) 8));
|
||||
@ -854,66 +832,66 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
offline = (((i & 1) == 0) ? new NamedContainer<>("YELLOW_STAINED_GLASS_PANE", (short) 4) : new NamedContainer<>("ORANGE_STAINED_GLASS_PANE", (short) 1));
|
||||
disabled = (((i & 1) == 0) ? new NamedContainer<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new NamedContainer<>("RED_STAINED_GLASS_PANE", (short) 14));
|
||||
|
||||
if (hosts.get(server) == null) {
|
||||
if (!(server instanceof SubServer)) {
|
||||
block = createItem("STAINED_GLASS_PANE", external.name(), external.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.WHITE + json.getSection("servers").getSection(server).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.WHITE + server.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!server.equals(json.getSection("servers").getSection(server).getString("display")))
|
||||
lore.add(ChatColor.GRAY + server);
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + server.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("servers").getSection(server).getSection("players").getKeys().size())));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Invalid"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("servers").getSection(server).getString("address"):json.getSection("servers").getSection(server).getString("address").split(":")[json.getSection("servers").getSection(server).getString("address").split(":").length - 1]));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getBoolean("temp")) {
|
||||
} else if (((SubServer) server).isTemporary()) {
|
||||
block = createItem("STAINED_GLASS_PANE", temp.name(), temp.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + server.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!server.equals(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display")))
|
||||
lore.add(ChatColor.GRAY + server);
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + server.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getSection("players").getKeys().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address"):json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":")[json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":").length - 1]));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getBoolean("running")) {
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
block = createItem("STAINED_GLASS_PANE", online.name(), online.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GREEN + json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.GREEN + server.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!server.equals(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display")))
|
||||
lore.add(ChatColor.GRAY + server);
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getSection("players").getKeys().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address"):json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":")[json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":").length - 1]));
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + server.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getBoolean("enabled") && json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getList("incompatible").size() == 0) {
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", offline.name(), offline.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + server.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!server.equals(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display")))
|
||||
lore.add(ChatColor.GRAY + server);
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + server.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address"):json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":")[json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":").length - 1]));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", disabled.name(), disabled.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.RED + json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.RED + server.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!server.equals(json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("display")))
|
||||
lore.add(ChatColor.GRAY + server);
|
||||
if (json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getList("incompatible").size() != 0) {
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + server.getName());
|
||||
if (((SubServer) server).getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (int ii = 0; ii < json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getList("incompatible").size(); ii++) {
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
|
||||
}
|
||||
if (!json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getBoolean("enabled")) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address"):json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":")[json.getSection("hosts").getSection(hosts.get(server)).getSection("servers").getSection(server).getString("address").split(":").length - 1]));
|
||||
if (!((SubServer) server).isEnabled()) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
@ -976,18 +954,44 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}));
|
||||
};
|
||||
|
||||
if (host != null && host.length() > 0) {
|
||||
plugin.api.getHost(host, object -> {
|
||||
if (object == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
hostname.set(object.getDisplayName());
|
||||
servercontainer.get().addAll(object.getSubServers().values());
|
||||
renderer.run();
|
||||
}
|
||||
});
|
||||
} else if (group != null && group.length() > 0) {
|
||||
plugin.api.getGroup(group, servers -> {
|
||||
if (servers == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
servercontainer.get().addAll(servers);
|
||||
renderer.run();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
plugin.api.getServers(servers -> {
|
||||
servercontainer.get().addAll(servers.values());
|
||||
renderer.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void subserverAdmin(final String subserver) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", subserver)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, json -> {
|
||||
windowHistory.add(() -> subserverAdmin(subserver));
|
||||
if (!json.getString("type").equals("subserver")) {
|
||||
public void subserverAdmin(final String name) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", name)));
|
||||
plugin.api.getSubServer(name, subserver -> {
|
||||
windowHistory.add(() -> subserverAdmin(name));
|
||||
if (subserver == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = subserver;
|
||||
lastVisitedObjects[0] = name;
|
||||
ItemStack block;
|
||||
ItemMeta blockMeta;
|
||||
ItemStack div = createItem("STAINED_GLASS_PANE", "BLACK_STAINED_GLASS_PANE", (short) 15);
|
||||
@ -995,7 +999,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
divMeta.setDisplayName(ChatColor.RESET.toString());
|
||||
div.setItemMeta(divMeta);
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", json.getSection("server").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 36, plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Title").replace("$str$", subserver.getDisplayName()));
|
||||
|
||||
int i = 0;
|
||||
while (i < inv.getSize()) {
|
||||
@ -1004,12 +1008,12 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
}
|
||||
i = 0;
|
||||
|
||||
if (json.getSection("server").getBoolean("running")) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate." + subserver.toLowerCase()))) {
|
||||
if (subserver.isRunning()) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.terminate." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + subserver.toLowerCase())));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.terminate." + name.toLowerCase())));
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
@ -1020,11 +1024,11 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(1, block);
|
||||
inv.setItem(10, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop." + subserver.toLowerCase()))) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.stop." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + subserver.toLowerCase())));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + name.toLowerCase())));
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "MAGENTA_STAINED_GLASS_PANE", (short) 2);
|
||||
blockMeta = block.getItemMeta();
|
||||
@ -1036,11 +1040,11 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.command.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.command." + subserver.toLowerCase()))) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.command.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.command." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + subserver.toLowerCase())));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + name.toLowerCase())));
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
@ -1054,12 +1058,12 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
} else {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + subserver.toLowerCase()))) {
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.start.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.start." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + subserver.toLowerCase())));
|
||||
} else if (!json.getSection("server").getBoolean("enabled") || json.getSection("server").getList("incompatible").size() != 0) {
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + name.toLowerCase())));
|
||||
} else if (!subserver.isEnabled() || subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
|
||||
@ -1077,7 +1081,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(14, block);
|
||||
}
|
||||
|
||||
if (!json.getSection("server").getBoolean("enabled") || subserverPlugins.size() <= 0) {
|
||||
if (!subserver.isEnabled() || subserverPlugins.size() <= 0) {
|
||||
block = div;
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
@ -1088,54 +1092,54 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
inv.setItem(27, block);
|
||||
inv.setItem(28, block);
|
||||
|
||||
if (json.getSection("server").getBoolean("temp")) {
|
||||
if (subserver.isTemporary()) {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + json.getSection("server").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.AQUA + subserver.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!subserver.equals(json.getSection("server").getString("display")))
|
||||
lore.add(ChatColor.GRAY + subserver);
|
||||
if (!subserver.getName().equals(subserver.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + subserver.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary"));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("server").getSection("players").getKeys().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("server").getString("address"):json.getSection("server").getString("address").split(":")[json.getSection("server").getString("address").split(":").length - 1]));
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (json.getSection("server").getBoolean("running")) {
|
||||
} else if (subserver.isRunning()) {
|
||||
block = createItem("STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", (short) 5);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GREEN + json.getSection("server").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.GREEN + subserver.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!subserver.equals(json.getSection("server").getString("display")))
|
||||
lore.add(ChatColor.GRAY + subserver);
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(json.getSection("server").getSection("players").getKeys().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("server").getString("address"):json.getSection("server").getString("address").split(":")[json.getSection("server").getString("address").split(":").length - 1]));
|
||||
if (!subserver.getName().equals(subserver.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + subserver.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (json.getSection("server").getBoolean("enabled") && json.getSection("server").getList("incompatible").size() == 0) {
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + json.getSection("server").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + subserver.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!subserver.equals(json.getSection("server").getString("display")))
|
||||
lore.add(ChatColor.GRAY + subserver);
|
||||
if (!subserver.getName().equals(subserver.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + subserver.getName());
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("server").getString("address"):json.getSection("server").getString("address").split(":")[json.getSection("server").getString("address").split(":").length - 1]));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "RED_STAINED_GLASS_PANE", (short) 14);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.RED + json.getSection("server").getString("display"));
|
||||
blockMeta.setDisplayName(ChatColor.RED + subserver.getDisplayName());
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
if (!subserver.equals(json.getSection("server").getString("display")))
|
||||
lore.add(ChatColor.GRAY + subserver);
|
||||
if (json.getSection("server").getList("incompatible").size() != 0) {
|
||||
if (!subserver.getName().equals(subserver.getDisplayName()))
|
||||
lore.add(ChatColor.GRAY + subserver.getName());
|
||||
if (subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (int ii = 0; ii < json.getSection("server").getList("incompatible").size(); ii++) {
|
||||
for (String other : subserver.getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += json.getSection("server").getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
|
||||
}
|
||||
if (!json.getSection("server").getBoolean("enabled")) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getSection("server").getString("address"):json.getSection("server").getString("address").split(":")[json.getSection("server").getString("address").split(":").length - 1]));
|
||||
if (!subserver.isEnabled()) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
@ -1155,23 +1159,23 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void subserverPlugin(final int page, final String subserver) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", subserver)));
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver, json -> {
|
||||
windowHistory.add(() -> subserverPlugin(page, subserver));
|
||||
if (!json.getString("type").equals("subserver")) {
|
||||
public void subserverPlugin(final int page, final String name) {
|
||||
setDownloading(ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", name)));
|
||||
plugin.api.getSubServer(name, subserver -> {
|
||||
windowHistory.add(() -> subserverPlugin(page, name));
|
||||
if (subserver == null) {
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
setDownloading(null);
|
||||
lastVisitedObjects[0] = subserver;
|
||||
lastVisitedObjects[0] = name;
|
||||
lastPage = page;
|
||||
List<String> renderers = new ArrayList<String>();
|
||||
List<String> renderers = new LinkedList<String>();
|
||||
for (String renderer : renderers) {
|
||||
if (subserverPlugins.get(renderer).isEnabled(json.getSection("server"))) renderers.add(renderer);
|
||||
if (subserverPlugins.get(renderer).isEnabled(subserver)) renderers.add(renderer);
|
||||
}
|
||||
Collections.sort(renderers);
|
||||
|
||||
@ -1188,7 +1192,7 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
int count = (renderers.size() == 0)?27:((renderers.size() - min >= max)?36:renderers.size() - min);
|
||||
int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9;
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", json.getSection("server").getString("display")));
|
||||
Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", subserver.getDisplayName()));
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
block.setItemMeta(divMeta);
|
||||
while (i < area) {
|
||||
@ -1264,6 +1268,6 @@ public class InternalUIRenderer extends UIRenderer {
|
||||
Bukkit.getPlayer(player).openInventory(inv);
|
||||
open = true;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
@ -1,21 +1,20 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* GUI Renderer Layout Class
|
||||
*/
|
||||
public interface Renderer {
|
||||
public interface Renderer<T> {
|
||||
|
||||
/**
|
||||
* Open the GUI
|
||||
*
|
||||
* @param player Player Opening
|
||||
* @param object Raw Representation of an Object
|
||||
* @param object Object passed
|
||||
*/
|
||||
void open(Player player, YAMLSection object);
|
||||
void open(Player player, T object);
|
||||
|
||||
/**
|
||||
* Get Renderer Icon
|
||||
@ -27,8 +26,8 @@ public interface Renderer {
|
||||
/**
|
||||
* Check if this Renderer is enabled for this Object
|
||||
*
|
||||
* @param object Raw Representation of an Object
|
||||
* @param object Object passed
|
||||
* @return Enabled Status
|
||||
*/
|
||||
boolean isEnabled(YAMLSection object);
|
||||
boolean isEnabled(T object);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ import net.ME1312.SubServers.Client.Bukkit.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -17,8 +19,8 @@ import java.util.regex.Pattern;
|
||||
* GUI Renderer Layout Class
|
||||
*/
|
||||
public abstract class UIRenderer {
|
||||
protected static HashMap<String, Renderer> hostPlugins = new HashMap<String, Renderer>();
|
||||
protected static HashMap<String, Renderer> subserverPlugins = new HashMap<String, Renderer>();
|
||||
protected static HashMap<String, Renderer<Host>> hostPlugins = new HashMap<String, Renderer<Host>>();
|
||||
protected static HashMap<String, Renderer<SubServer>> subserverPlugins = new HashMap<String, Renderer<SubServer>>();
|
||||
private NamedContainer<String, Integer> tdownload = null;
|
||||
private int download = -1;
|
||||
private final UUID player;
|
||||
@ -265,7 +267,7 @@ public abstract class UIRenderer {
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addHostPlugin(String handle, Renderer renderer) {
|
||||
public static void addHostPlugin(String handle, Renderer<Host> renderer) {
|
||||
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
||||
hostPlugins.put(handle, renderer);
|
||||
}
|
||||
@ -295,7 +297,7 @@ public abstract class UIRenderer {
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addSubServerPlugin(String handle, Renderer renderer) {
|
||||
public static void addSubServerPlugin(String handle, Renderer<SubServer> renderer) {
|
||||
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
||||
subserverPlugins.put(handle, renderer);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Library.Compatibility;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@ -23,13 +24,13 @@ public class BungeeChat {
|
||||
}
|
||||
|
||||
public void listCommand(CommandSender sender, String label) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
TextComponent div = new TextComponent(plugin.api.getLang("SubServers", "Command.List.Divider"));
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
if (groups.keySet().size() > 0) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Group-Header"));
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
for (String group : groups.keySet()) {
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
TextComponent message = new TextComponent(group);
|
||||
@ -37,47 +38,46 @@ public class BungeeChat {
|
||||
message.setColor(ChatColor.GOLD);
|
||||
hover.setColor(ChatColor.GOLD);
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(groups.get(group).size())));
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Server 1 " + group));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
msg.addExtra(message);
|
||||
msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
for (Server server : groups.get(group)) {
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display"));
|
||||
hover = new TextComponent(data.getSection("groups").getSection(group).getSection(server).getString("display") + '\n');
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getKeys().contains("host")) {
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + server));
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
message = new TextComponent(server.getDisplayName());
|
||||
hover = new TextComponent(server.getDisplayName() + '\n');
|
||||
if (server instanceof SubServer) {
|
||||
if (((SubServer) server).isTemporary()) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new TextComponent(server + '\n');
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover = new TextComponent(server.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n');
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
hover.setColor(ChatColor.GREEN);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new TextComponent(server + '\n');
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover = new TextComponent(server.getDisplayName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message.setColor(ChatColor.YELLOW);
|
||||
hover.setColor(ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover = new TextComponent(server + '\n');
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover = new TextComponent(server.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
@ -85,30 +85,30 @@ public class BungeeChat {
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
hover.setColor(ChatColor.RED);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(server + '\n');
|
||||
hover = new TextComponent(server.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() != 0) {
|
||||
if (((SubServer) server).getCurrentIncompatibilities().size() != 0) {
|
||||
hoverm.add(hover);
|
||||
String list = "";
|
||||
for (int ii = 0; ii < data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size(); ii++) {
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("groups").getSection(group).getSection(server).getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled")) ? "" : "\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n"));
|
||||
}
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled")) {
|
||||
if (!((SubServer) server).isEnabled()) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort());
|
||||
} else {
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent("\n" + server.getAddress().getPort());
|
||||
}
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
@ -116,15 +116,20 @@ public class BungeeChat {
|
||||
} else {
|
||||
message.setColor(ChatColor.WHITE);
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(server.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External"));
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())) + '\n');
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())) + '\n');
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort());
|
||||
} else {
|
||||
hover = new TextComponent('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent("\n" + server.getAddress().getPort());
|
||||
}
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
@ -143,27 +148,27 @@ public class BungeeChat {
|
||||
sent = false;
|
||||
}
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Host-Header"));
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (Host host : hosts.values()) {
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
TextComponent message = new TextComponent(data.getSection("hosts").getSection(host).getString("display"));
|
||||
TextComponent hover = new TextComponent(data.getSection("hosts").getSection(host).getString("display") + '\n');
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
TextComponent message = new TextComponent(host.getDisplayName());
|
||||
TextComponent hover = new TextComponent(host.getDisplayName() + '\n');
|
||||
if (host.isEnabled()) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover = new TextComponent(host + '\n');
|
||||
if (!host.getName().equals(host.getDisplayName())) {
|
||||
hover = new TextComponent(host.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size())));
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
hover.setColor(ChatColor.RED);
|
||||
hoverm.add(hover);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover = new TextComponent(host + '\n');
|
||||
if (!host.getName().equals(host.getDisplayName())) {
|
||||
hover = new TextComponent(host.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
@ -171,48 +176,48 @@ public class BungeeChat {
|
||||
}
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getString("address"));
|
||||
hover = new TextComponent('\n' + host.getAddress().getHostAddress());
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
}
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Host/ " + host));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open Host/ " + host.getName()));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
msg.addExtra(message);
|
||||
msg.addExtra(new TextComponent(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"));
|
||||
hover = new TextComponent(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display") + '\n');
|
||||
message = new TextComponent(subserver.getDisplayName());
|
||||
hover = new TextComponent(subserver.getDisplayName() + '\n');
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + subserver));
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
if (subserver.isTemporary()) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover = new TextComponent(subserver.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n');
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())));
|
||||
} else if (subserver.isEnabled()) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
hover.setColor(ChatColor.GREEN);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover = new TextComponent(subserver.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())));
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())));
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message.setColor(ChatColor.YELLOW);
|
||||
hover.setColor(ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover = new TextComponent(subserver.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
@ -220,34 +225,34 @@ public class BungeeChat {
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
hover.setColor(ChatColor.RED);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(subserver + '\n');
|
||||
hover = new TextComponent(subserver.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() != 0) {
|
||||
if (subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
hoverm.add(hover);
|
||||
String list = "";
|
||||
for (int ii = 0; ii < data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size(); ii++) {
|
||||
for (String other : subserver.getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled")) ? "" : "\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n"));
|
||||
}
|
||||
if (!data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled")) {
|
||||
if (!subserver.isEnabled()) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address"));
|
||||
hover = new TextComponent('\n' + subserver.getAddress().getAddress().getHostAddress()+':'+subserver.getAddress().getPort());
|
||||
} else {
|
||||
hover = new TextComponent('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent("\n" + subserver.getAddress().getPort());
|
||||
}
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + subserver));
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, label + " open SubServer/ " + subserver.getName()));
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
if (i != 0) msg.addExtra(div);
|
||||
msg.addExtra(message);
|
||||
@ -261,26 +266,26 @@ public class BungeeChat {
|
||||
if (!sent) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Server-Header"));
|
||||
TextComponent msg = new TextComponent(" ");
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
TextComponent message = new TextComponent(data.getSection("servers").getSection(server).getString("display"));
|
||||
TextComponent hover = new TextComponent(data.getSection("servers").getSection(server).getString("display") + '\n');
|
||||
TextComponent message = new TextComponent(server.getDisplayName());
|
||||
TextComponent hover = new TextComponent(server.getDisplayName() + '\n');
|
||||
message.setColor(ChatColor.WHITE);
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
if (!server.equals(data.getSection("servers").getSection(server).getString("display"))) {
|
||||
hover = new TextComponent(server + '\n');
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover = new TextComponent(server.getName() + '\n');
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External") + '\n');
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("servers").getSection(server).getSection("players").getKeys().size())));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
hoverm.add(hover);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address"));
|
||||
hover = new TextComponent('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
} else {
|
||||
hover = new TextComponent('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]);
|
||||
hover = new TextComponent("\n" + server.getAddress().getPort());
|
||||
}
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
@ -291,7 +296,7 @@ public class BungeeChat {
|
||||
}
|
||||
if (i == 0) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
else ((Player) sender).spigot().sendMessage(msg);
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
if (proxies.keySet().size() > 0) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Proxy-Header"));
|
||||
msg = new TextComponent(" ");
|
||||
List<TextComponent> hoverm = new LinkedList<TextComponent>();
|
||||
@ -300,55 +305,64 @@ public class BungeeChat {
|
||||
message.setColor(ChatColor.GRAY);
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
if (data.getKeys().contains("master-proxy")) {
|
||||
hover = new TextComponent('\n' + data.getRawString("master-proxy"));
|
||||
if (proxymaster != null) {
|
||||
hover = new TextComponent('\n' + proxymaster.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master"));
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())));
|
||||
hoverm.add(hover);
|
||||
} else {
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master"));
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master"));
|
||||
hoverm.add(hover);
|
||||
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()])));
|
||||
msg.addExtra(message);
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display"));
|
||||
hover = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display"));
|
||||
if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
message = new TextComponent(proxy.getDisplayName());
|
||||
hover = new TextComponent(proxy.getDisplayName());
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
hover.setColor(ChatColor.GREEN);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + proxy);
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
} else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())));
|
||||
} else if (proxy.getSubData() != null) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + proxy);
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
}
|
||||
if (data.getKeys().contains("master-proxy")) {
|
||||
if (proxymaster != null) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData"));
|
||||
}
|
||||
} else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
} else if (proxy.isRedis()) {
|
||||
message.setColor(ChatColor.WHITE);
|
||||
hover.setColor(ChatColor.WHITE);
|
||||
hoverm.add(hover);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover = new TextComponent('\n' + proxy);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis"));
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())));
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
hover.setColor(ChatColor.RED);
|
||||
hoverm.add(hover);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover = new TextComponent('\n' + proxy);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover = new TextComponent('\n' + proxy.getName());
|
||||
hover.setColor(ChatColor.GRAY);
|
||||
hoverm.add(hover);
|
||||
}
|
||||
@ -361,6 +375,6 @@ public class BungeeChat {
|
||||
}
|
||||
((Player) sender).spigot().sendMessage(msg);
|
||||
}
|
||||
}));
|
||||
})))));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.API;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -46,7 +46,7 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(name, null, data -> load(data.getSection("hosts").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,20 +37,7 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
YAMLSection raw = null;
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
if (data.getSection("clients").getSection(client).getRawString("name").equals(name)) {
|
||||
raw = data.getSection("clients").getSection(client);
|
||||
load(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (raw == null) throw new IllegalStateException("Could not find proxy with name: " + name);
|
||||
}));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.API;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -36,7 +36,7 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(null, null, data -> load(data.getSection("servers").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,10 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.API;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Callback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -40,15 +37,6 @@ public class SubServer extends Server {
|
||||
return obj instanceof SubServer && super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a new copy of the data from SubData
|
||||
*/
|
||||
@Override
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> load(data.getSection("hosts").getSection(raw.getRawString("host")).getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
@ -261,11 +249,11 @@ public class SubServer extends Server {
|
||||
}
|
||||
};
|
||||
|
||||
if (host == null) {
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> {
|
||||
host = new Host(data.getSection("hosts").getSection(raw.getRawString("host")));
|
||||
if (host == null || !host.getName().equalsIgnoreCase(raw.getRawString("host"))) {
|
||||
SubAPI.getInstance().getHost(raw.getRawString("host"), host -> {
|
||||
this.host = host;
|
||||
run.run();
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
|
@ -97,6 +97,6 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Callback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.PacketOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
*/
|
||||
public PacketDownloadGroupInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (Out)
|
||||
*
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("group", group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
@ -26,12 +26,12 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host Name
|
||||
* @param host Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(host, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -39,10 +39,10 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("host", host);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,19 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server List Packet
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (In)
|
||||
*/
|
||||
public PacketDownloadServerList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (Out)
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerList(String host, String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
@ -44,8 +32,6 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (host != null) data.set("host", host);
|
||||
if (group != null) data.set("group", group);
|
||||
return data;
|
||||
}
|
||||
|
@ -15,24 +15,34 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
*/
|
||||
public PacketDownloadProxyInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (Out)
|
||||
*
|
||||
* @param proxy Proxy name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.proxy = proxy;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("proxy", proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,6 +53,6 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadServerInfo (Out)
|
||||
*
|
||||
* @param server Server name
|
||||
* @param server Server name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -96,13 +96,14 @@ public final class SubDataClient {
|
||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(), "SubServers", "DownloadServerList");
|
||||
registerPacket(new PacketInRunEvent(plugin), "SubServers", "RunEvent");
|
||||
registerPacket(new PacketInReload(plugin), "SubServers", "Reload");
|
||||
registerPacket(new PacketInReset(), "SubServers", "Reset");
|
||||
@ -113,13 +114,14 @@ public final class SubDataClient {
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubServers", "DownloadServerList");
|
||||
registerPacket(PacketLinkServer.class, "SubServers", "LinkServer");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
|
@ -9,9 +9,7 @@ import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadPlayerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -69,7 +67,7 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
||||
@ -93,7 +91,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getHosts(hosts -> callback.run(hosts.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
Host host = null;
|
||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(host);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +116,7 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
@ -152,7 +164,29 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getLowercaseGroups(groups -> callback.run(groups.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
List<Server> servers = null;
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
||||
servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(servers);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,14 +197,13 @@ public final class SubAPI {
|
||||
public void getServers(Callback<Map<String, Server>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
servers.put(subserver.toLowerCase(), new SubServer(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver)));
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +225,26 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getServers(servers -> callback.run(servers.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
Server server = null;
|
||||
if (data.getSection("servers").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getSection("servers").getSection(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(server);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,18 +271,18 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getSubServer(String name, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getSubServers(subservers -> callback.run(subservers.get(name.toLowerCase())));
|
||||
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the known Proxies
|
||||
*
|
||||
* @return Proxy Map
|
||||
* @param callback Proxy Map
|
||||
*/
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
||||
@ -250,11 +302,49 @@ public final class SubAPI {
|
||||
* Gets a Proxy
|
||||
*
|
||||
* @param name Proxy name
|
||||
* @return a Proxy
|
||||
* @param callback a Proxy
|
||||
*/
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getProxies(proxies -> callback.run(proxies.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
*
|
||||
* @param callback Master Proxy
|
||||
*/
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,10 @@ import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -77,65 +80,67 @@ public final class SubCommand implements CommandExecutor {
|
||||
new net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.BungeeChat(plugin).listCommand(sender, label);
|
||||
} else {
|
||||
final String fLabel = label;
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getProxies(proxies -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Group-Header"));
|
||||
String div = plugin.api.getLang("SubServers", "Command.List.Divider");
|
||||
if (groups.keySet().size() > 0) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Group-Header"));
|
||||
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
String message = " ";
|
||||
message += ChatColor.GOLD + group + plugin.api.getLang("SubServers", "Command.List.Header");
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
if (i != 0) message += div;
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).getKeys().contains("host")) {
|
||||
message += ChatColor.WHITE;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
for (String group : groups.keySet()) {
|
||||
String message = " ";
|
||||
message += ChatColor.GOLD + group + plugin.api.getLang("SubServers", "Command.List.Header");
|
||||
for (Server server : groups.get(group)) {
|
||||
if (i != 0) message += div;
|
||||
if (!(server instanceof SubServer)) {
|
||||
message += ChatColor.WHITE;
|
||||
} else if (((SubServer) server).isTemporary()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += server.getDisplayName() + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName()))?"":ChatColor.stripColor(div)+server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
message += data.getSection("groups").getSection(group).getSection(server).getString("display") + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?data.getSection("groups").getSection(group).getSection(server).getString("address"):data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]) + ((server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display")))?"":ChatColor.stripColor(div)+server) + ")";
|
||||
i++;
|
||||
if (i == 0) message += plugin.api.getLang("SubServers", "Command.List.Empty");
|
||||
sender.sendMessage(message);
|
||||
i = 0;
|
||||
sent = true;
|
||||
}
|
||||
if (i == 0) message += plugin.api.getLang("SubServers", "Command.List.Empty");
|
||||
sender.sendMessage(message);
|
||||
i = 0;
|
||||
sent = true;
|
||||
if (!sent) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
sent = false;
|
||||
}
|
||||
if (!sent) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
sent = false;
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Host-Header"));
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (Host host : hosts.values()) {
|
||||
String message = " ";
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
if (host.isEnabled()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getString("display");
|
||||
message += host.getDisplayName();
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
message += " (" + data.getSection("hosts").getSection(host).getString("address") + ((host.equals(data.getSection("hosts").getSection(host).getString("display")))?"":ChatColor.stripColor(div)+host) + ")";
|
||||
} else if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
message += " (" + host.getAddress() + ((host.getName().equals(host.getDisplayName()))?"":ChatColor.stripColor(div)+host.getName()) + ")";
|
||||
} else if (!host.getName().equals(host.getDisplayName())) {
|
||||
message += " (" + host + ")";
|
||||
}
|
||||
message += plugin.api.getLang("SubServers", "Command.List.Header");
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
if (i != 0) message += div;
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
if (subserver.isTemporary()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
} else if (subserver.isRunning()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display") + " (" + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":").length - 1] + ((subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display")))?"":ChatColor.stripColor(div)+subserver) + ")";
|
||||
message += subserver.getDisplayName() + " (" + subserver.getAddress().getPort() + ((subserver.getName().equals(subserver.getDisplayName()))?"":ChatColor.stripColor(div)+subserver.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += plugin.api.getLang("SubServers", "Command.List.Empty");
|
||||
@ -146,75 +151,76 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (!sent) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Server-Header"));
|
||||
String message = " ";
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
|
||||
if (i != 0) message += div;
|
||||
message += ChatColor.WHITE + data.getSection("servers").getSection(server).getString("display") + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?data.getSection("servers").getSection(server).getString("address"):data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]) + ((server.equals(data.getSection("servers").getSection(server).getString("display")))?"":ChatColor.stripColor(div)+server) + ")";
|
||||
message += ChatColor.WHITE + server.getDisplayName() + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName()))?"":ChatColor.stripColor(div)+server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.List.Empty"));
|
||||
else sender.sendMessage(message);
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
if (proxies.keySet().size() > 0) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Proxy-Header"));
|
||||
message = " (master)";
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) {
|
||||
} else if (proxy.getSubData() != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')');
|
||||
message += proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName()))?"":" ("+proxy.getName()+')');
|
||||
}
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}));
|
||||
}))));
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
|
||||
if (args.length > 1) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(args[1].toLowerCase(), data -> {
|
||||
switch (data.getString("type").toLowerCase()) {
|
||||
case "invalid":
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown"));
|
||||
break;
|
||||
case "subserver":
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", data.getSection("server").getString("display")));
|
||||
if (!data.getSection("server").getString("name").equals(data.getSection("server").getString("display")))
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name") + ChatColor.AQUA + data.getSection("server").getString("name"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host") + ChatColor.AQUA + data.getSection("server").getString("host"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((data.getSection("server").getBoolean("enabled"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable") + ((data.getSection("server").getBoolean("editable"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (data.getSection("server").getList("group").size() > 0) {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group"));
|
||||
for (int i = 0; i < data.getSection("server").getList("group").size(); i++)
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ChatColor.GOLD + data.getSection("server").getList("group").get(i).asString()));
|
||||
}
|
||||
if (data.getSection("server").getBoolean("temp")) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary") + ChatColor.GREEN+"yes");
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((data.getSection("server").getBoolean("running"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging") + ((data.getSection("server").getBoolean("log"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.AQUA + data.getSection("server").getString("address"));
|
||||
} else {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA + data.getSection("server").getString("address").split(":")[data.getSection("server").getString("address").split(":").length - 1]);
|
||||
}
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart") + ((data.getSection("server").getBoolean("auto-restart"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden") + ((data.getSection("server").getBoolean("hidden"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (data.getSection("server").getList("incompatible-list").size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible").size(); i++) current.add(data.getSection("server").getList("incompatible").get(i).asString().toLowerCase());
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities"));
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible-list").size(); i++)
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ((current.contains(data.getSection("server").getList("incompatible-list").get(i).asString().toLowerCase()))?ChatColor.DARK_RED:ChatColor.RED) + data.getSection("server").getList("incompatible-list").get(i).asString()));
|
||||
}
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + data.getSection("server").getString("signature"));
|
||||
break;
|
||||
default:
|
||||
plugin.api.getServer(args[1], subserver -> {
|
||||
if (subserver == null) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Unknown"));
|
||||
} else if (!(subserver instanceof SubServer)) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Invalid"));
|
||||
} else ((SubServer) subserver).getHost(host -> {
|
||||
if (host == null) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Invalid"));
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", subserver.getDisplayName()));
|
||||
if (!subserver.getName().equals(subserver.getDisplayName()))
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name") + ChatColor.AQUA + subserver.getName());
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host") + ChatColor.AQUA + host.getName());
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((((SubServer) subserver).isEnabled())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable") + ((((SubServer) subserver).isEditable())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (subserver.getGroups().size() > 0) {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group"));
|
||||
for (String group : subserver.getGroups())
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ChatColor.GOLD + group));
|
||||
}
|
||||
if (((SubServer) subserver).isTemporary()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary") + ChatColor.GREEN+"yes");
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((((SubServer) subserver).isRunning())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging") + ((((SubServer) subserver).isLogging())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.AQUA + subserver.getAddress().getAddress().getHostAddress());
|
||||
} else {
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA + subserver.getAddress().getPort());
|
||||
}
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart") + ((((SubServer) subserver).willAutoRestart())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden") + ((subserver.isHidden())?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no"));
|
||||
if (((SubServer) subserver).getIncompatibilities().size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (String other : ((SubServer) subserver).getCurrentIncompatibilities()) current.add(other.toLowerCase());
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities"));
|
||||
for (String other : ((SubServer) subserver).getIncompatibilities())
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", ((current.contains(other.toLowerCase()))?ChatColor.DARK_RED:ChatColor.RED) + other));
|
||||
}
|
||||
sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + subserver.getSignature());
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <SubServer>"));
|
||||
}
|
||||
@ -230,16 +236,15 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Invalid"));
|
||||
break;
|
||||
case 5:
|
||||
if (data.getString("m").contains("Host")) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled"));
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled"));
|
||||
}
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled"));
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled"));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running"));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1]));
|
||||
break;
|
||||
case 0:
|
||||
@ -366,9 +371,10 @@ public final class SubCommand implements CommandExecutor {
|
||||
plugin.subdata.sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], args[2], args[3], new Version(args[4]), Integer.parseInt(args[5]), data -> {
|
||||
switch (data.getInt("r")) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Exists"));
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Host"));
|
||||
break;
|
||||
case 6:
|
||||
|
@ -1,21 +1,20 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Graphic;
|
||||
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.item.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* GUI Renderer Layout Class
|
||||
*/
|
||||
public interface Renderer {
|
||||
public interface Renderer<T> {
|
||||
|
||||
/**
|
||||
* Open the GUI
|
||||
*
|
||||
* @param player Player Opening
|
||||
* @param object Raw Representation of an Object
|
||||
* @param object Object passed
|
||||
*/
|
||||
void open(Player player, YAMLSection object);
|
||||
void open(Player player, T object);
|
||||
|
||||
/**
|
||||
* Get Renderer Icon
|
||||
@ -27,8 +26,8 @@ public interface Renderer {
|
||||
/**
|
||||
* Check if this Renderer is enabled for this Object
|
||||
*
|
||||
* @param object Raw Representation of an Object
|
||||
* @param object Object passed
|
||||
* @return Enabled Status
|
||||
*/
|
||||
boolean isEnabled(YAMLSection object);
|
||||
boolean isEnabled(T object);
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Graphic;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Container;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* GUI Renderer Layout Class
|
||||
*/
|
||||
public abstract class UIRenderer {
|
||||
protected static HashMap<String, Renderer> hostPlugins = new HashMap<String, Renderer>();
|
||||
protected static HashMap<String, Renderer> subserverPlugins = new HashMap<String, Renderer>();
|
||||
protected static HashMap<String, Renderer<Host>> hostPlugins = new HashMap<String, Renderer<Host>>();
|
||||
protected static HashMap<String, Renderer<SubServer>> subserverPlugins = new HashMap<String, Renderer<SubServer>>();
|
||||
private NamedContainer<String, Integer> tdownload = null;
|
||||
private int download = -1;
|
||||
private final UUID player;
|
||||
@ -67,7 +66,7 @@ public abstract class UIRenderer {
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addHostPlugin(String handle, Renderer renderer) {
|
||||
public static void addHostPlugin(String handle, Renderer<Host> renderer) {
|
||||
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
||||
hostPlugins.put(handle, renderer);
|
||||
}
|
||||
@ -77,8 +76,8 @@ public abstract class UIRenderer {
|
||||
*
|
||||
* @return Host Plugins
|
||||
*/
|
||||
public static Map<String, Renderer> getHostPlugins() {
|
||||
return new HashMap<String, Renderer>(hostPlugins);
|
||||
public static Map<String, Renderer<Host>> getHostPlugins() {
|
||||
return new HashMap<String, Renderer<Host>>(hostPlugins);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +96,7 @@ public abstract class UIRenderer {
|
||||
* @param handle Handle to bind
|
||||
* @param renderer Renderer
|
||||
*/
|
||||
public static void addSubServerPlugin(String handle, Renderer renderer) {
|
||||
public static void addSubServerPlugin(String handle, Renderer<SubServer> renderer) {
|
||||
if (Util.isNull(handle, renderer)) throw new NullPointerException();
|
||||
subserverPlugins.put(handle, renderer);
|
||||
}
|
||||
@ -107,8 +106,8 @@ public abstract class UIRenderer {
|
||||
*
|
||||
* @return SubServer Plugins
|
||||
*/
|
||||
public static Map<String, Renderer> getSubServerPlugins() {
|
||||
return new HashMap<String, Renderer>(subserverPlugins);
|
||||
public static Map<String, Renderer<SubServer>> getSubServerPlugins() {
|
||||
return new HashMap<String, Renderer<SubServer>>(subserverPlugins);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -46,7 +46,7 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(name, null, data -> load(data.getSection("hosts").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,20 +37,7 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
YAMLSection raw = null;
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
if (data.getSection("clients").getSection(client).getRawString("name").equals(name)) {
|
||||
raw = data.getSection("clients").getSection(client);
|
||||
load(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (raw == null) throw new IllegalStateException("Could not find proxy with name: " + name);
|
||||
}));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -36,7 +36,7 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(null, null, data -> load(data.getSection("servers").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
@ -40,15 +40,6 @@ public class SubServer extends Server {
|
||||
return obj instanceof SubServer && super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a new copy of the data from SubData
|
||||
*/
|
||||
@Override
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> load(data.getSection("hosts").getSection(raw.getRawString("host")).getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
@ -261,11 +252,11 @@ public class SubServer extends Server {
|
||||
}
|
||||
};
|
||||
|
||||
if (host == null) {
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> {
|
||||
host = new Host(data.getSection("hosts").getSection(raw.getRawString("host")));
|
||||
if (host == null || !host.getName().equalsIgnoreCase(raw.getRawString("host"))) {
|
||||
SubAPI.getInstance().getHost(raw.getRawString("host"), host -> {
|
||||
this.host = host;
|
||||
run.run();
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
|
@ -97,6 +97,6 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
*/
|
||||
public PacketDownloadGroupInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (Out)
|
||||
*
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("group", group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
@ -26,12 +26,12 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host Name
|
||||
* @param host Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(host, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -39,10 +39,10 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("host", host);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,19 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server List Packet
|
||||
* Download Platform Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (In)
|
||||
*/
|
||||
public PacketDownloadServerList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (Out)
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerList(String host, String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
@ -44,8 +32,6 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (host != null) data.set("host", host);
|
||||
if (group != null) data.set("group", group);
|
||||
return data;
|
||||
}
|
||||
|
@ -15,24 +15,34 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
*/
|
||||
public PacketDownloadProxyInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (Out)
|
||||
*
|
||||
* @param proxy Proxy name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.proxy = proxy;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("proxy", proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,6 +53,6 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadServerInfo (Out)
|
||||
*
|
||||
* @param server Server name
|
||||
* @param server Server name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -103,13 +103,14 @@ public final class SubDataClient {
|
||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(), "SubServers", "DownloadServerList");
|
||||
registerPacket(new PacketInRunEvent(plugin), "SubServers", "RunEvent");
|
||||
registerPacket(new PacketInReload(plugin), "SubServers", "Reload");
|
||||
registerPacket(new PacketInReset(), "SubServers", "Reset");
|
||||
@ -120,13 +121,14 @@ public final class SubDataClient {
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubServers", "DownloadServerList");
|
||||
registerPacket(PacketLinkServer.class, "SubServers", "LinkServer");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
|
@ -9,9 +9,7 @@ import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadPlayerList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
||||
import org.spongepowered.api.Platform;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -71,7 +69,7 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
||||
@ -95,7 +93,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getHosts(hosts -> callback.run(hosts.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
Host host = null;
|
||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(host);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +118,7 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
@ -154,7 +166,29 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getLowercaseGroups(groups -> callback.run(groups.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
List<Server> servers = null;
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
||||
servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(servers);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,14 +199,13 @@ public final class SubAPI {
|
||||
public void getServers(Callback<Map<String, Server>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
servers.put(subserver.toLowerCase(), new SubServer(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver)));
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +227,26 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getServers(servers -> callback.run(servers.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
Server server = null;
|
||||
if (data.getSection("servers").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getSection("servers").getSection(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(server);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,23 +273,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getSubServer(String name, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getSubServers(subservers -> callback.run(subservers.get(name.toLowerCase())));
|
||||
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the known Proxies
|
||||
*
|
||||
* @return Proxy Map
|
||||
* @param callback Proxy Map
|
||||
*/
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
proxies.put(data.getSection("clients").getSection(client).getRawString("name").toLowerCase(), new Proxy(data.getSection("clients").getSection(client)));
|
||||
}
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -254,11 +304,49 @@ public final class SubAPI {
|
||||
* Gets a Proxy
|
||||
*
|
||||
* @param name Proxy name
|
||||
* @return a Proxy
|
||||
* @param callback a Proxy
|
||||
*/
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getProxies(proxies -> callback.run(proxies.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
*
|
||||
* @param callback Master Proxy
|
||||
*/
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,10 @@ import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
||||
import org.spongepowered.api.Platform;
|
||||
import org.spongepowered.api.Sponge;
|
||||
@ -189,48 +192,48 @@ public final class SubCommand implements CommandExecutor {
|
||||
public final class LIST implements CommandExecutor {
|
||||
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
|
||||
if (canRun(sender)) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
Text div = Text.of(plugin.api.getLang("SubServers", "Command.List.Divider"));
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
if (groups.keySet().size() > 0) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Group-Header")));
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
for (String group : groups.keySet()) {
|
||||
Text.Builder msg = Text.builder(group).color(TextColors.GOLD).onHover(TextActions.showText(
|
||||
Text.builder(group + '\n').color(TextColors.GOLD).append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getKeys().size())))
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Group-Menu.Group-Server-Count").replace("$int$", new DecimalFormat("#,###").format(groups.get(group).size())))
|
||||
).build())
|
||||
).onClick(TextActions.runCommand("/subservers open Server 1 " + group)).append(Text.of(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
Text.Builder message = Text.builder(data.getSection("groups").getSection(group).getSection(server).getString("display"));
|
||||
Text.Builder hover = Text.builder(data.getSection("groups").getSection(group).getSection(server).getString("display") + '\n');
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getKeys().contains("host")) {
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server));
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
for (Server server : groups.get(group)) {
|
||||
Text.Builder message = Text.builder(server.getDisplayName());
|
||||
Text.Builder hover = Text.builder(server.getDisplayName() + '\n');
|
||||
if (server instanceof SubServer) {
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server.getName()));
|
||||
if (((SubServer) server).isTemporary()) {
|
||||
message.color(TextColors.AQUA);
|
||||
hover.color(TextColors.AQUA);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover.append(Text.builder(server + '\n').color(TextColors.GRAY).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n'),
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())))
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
|
||||
);
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
message.color(TextColors.GREEN);
|
||||
hover.color(TextColors.GREEN);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover.append(Text.builder(server + '\n').color(TextColors.GRAY).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())) + '\n')
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())) + '\n')
|
||||
);
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message.color(TextColors.YELLOW);
|
||||
hover.color(TextColors.YELLOW);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover.append(Text.builder(server + '\n').color(TextColors.GRAY).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline"))
|
||||
@ -238,38 +241,41 @@ public final class SubCommand implements CommandExecutor {
|
||||
} else {
|
||||
message.color(TextColors.RED);
|
||||
hover.color(TextColors.RED);
|
||||
if (!server.equals(data.getSection("groups").getSection(group).getSection(server).getString("display"))) {
|
||||
hover.append(Text.builder(server + '\n').color(TextColors.GRAY).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() != 0) {
|
||||
if (((SubServer) server).getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (int ii = 0; ii < data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size(); ii++) {
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("groups").getSection(group).getSection(server).getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled"))?"":"\n")));
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n")));
|
||||
}
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled")) {
|
||||
if (!((SubServer) server).isEnabled()) {
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled")));
|
||||
}
|
||||
}
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover.append(Text.builder('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address")).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
} else {
|
||||
hover.append(Text.builder('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
}
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server));
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + server.getName()));
|
||||
} else {
|
||||
message.color(TextColors.WHITE);
|
||||
hover.color(TextColors.WHITE);
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External") + '\n'),
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("groups").getSection(group).getSection(server).getSection("players").getKeys().size())))
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
|
||||
);
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover.append(Text.builder('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address")).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
} else {
|
||||
hover.append(Text.builder('\n' + data.getSection("groups").getSection(group).getSection(server).getString("address").split(":")[data.getSection("groups").getSection(group).getSection(server).getString("address").split(":").length - 1]).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
}
|
||||
}
|
||||
message.onHover(TextActions.showText(hover.build()));
|
||||
@ -286,83 +292,82 @@ public final class SubCommand implements CommandExecutor {
|
||||
sent = false;
|
||||
}
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Host-Header")));
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
Text.Builder msg = Text.builder(data.getSection("hosts").getSection(host).getString("display"));
|
||||
Text.Builder hover = Text.builder(data.getSection("hosts").getSection(host).getString("display") + '\n');
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
for (Host host : hosts.values()) {
|
||||
Text.Builder msg = Text.builder(host.getDisplayName());
|
||||
Text.Builder hover = Text.builder(host.getDisplayName() + '\n');
|
||||
if (host.isEnabled()) {
|
||||
msg.color(TextColors.AQUA);
|
||||
hover.color(TextColors.AQUA);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover.append(Text.builder(host + '\n').color(TextColors.GRAY).build());
|
||||
if (!host.getName().equals(host.getDisplayName())) {
|
||||
hover.append(Text.builder(host.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getKeys().size()))));
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Server-Count").replace("$int$", new DecimalFormat("#,###").format(host.getSubServers().keySet().size()))));
|
||||
} else {
|
||||
msg.color(TextColors.RED);
|
||||
hover.color(TextColors.RED);
|
||||
if (!host.equals(data.getSection("hosts").getSection(host).getString("display"))) {
|
||||
hover.append(Text.builder(host + '\n').color(TextColors.GRAY).build());
|
||||
if (!host.getName().equals(host.getDisplayName())) {
|
||||
hover.append(Text.builder(host.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Host-Menu.Host-Disabled")));
|
||||
}
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover.append(Text.builder('\n' + data.getSection("hosts").getSection(host).getString("address")).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder('\n' + host.getAddress().getHostAddress()).color(TextColors.WHITE).build());
|
||||
}
|
||||
msg.onClick(TextActions.runCommand("/subservers open Host/ " + host));
|
||||
msg.onClick(TextActions.runCommand("/subservers open Host/ " + host.getName()));
|
||||
msg.onHover(TextActions.showText(hover.build()));
|
||||
msg.append(Text.of(plugin.api.getLang("SubServers", "Command.List.Header")));
|
||||
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
Text.Builder message = Text.builder(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"));
|
||||
hover = Text.builder(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display") + '\n');
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + subserver));
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
Text.Builder message = Text.builder(subserver.getDisplayName());
|
||||
hover = Text.builder(subserver.getDisplayName() + '\n');
|
||||
if (subserver.isTemporary()) {
|
||||
message.color(TextColors.AQUA);
|
||||
hover.color(TextColors.AQUA);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover.append(Text.builder(subserver + '\n').color(TextColors.GRAY).build());
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Temporary") + '\n'),
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size())))
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())))
|
||||
);
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
} else if (subserver.isRunning()) {
|
||||
message.color(TextColors.GREEN);
|
||||
hover.color(TextColors.GREEN);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover.append(Text.builder(subserver + '\n').color(TextColors.GRAY).build());
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getSection("players").getKeys().size()))));
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size()))));
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message.color(TextColors.YELLOW);
|
||||
hover.color(TextColors.YELLOW);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover.append(Text.builder(subserver + '\n').color(TextColors.GRAY).build());
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Offline")));
|
||||
} else {
|
||||
message.color(TextColors.RED);
|
||||
hover.color(TextColors.RED);
|
||||
if (!subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("display"))) {
|
||||
hover.append(Text.builder(subserver + '\n').color(TextColors.GRAY).build());
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() != 0) {
|
||||
if (subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (int ii = 0; ii < data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size(); ii++) {
|
||||
for (String other : subserver.getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").get(ii).asString();
|
||||
list += other;
|
||||
}
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled"))?"":"\n")));
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n")));
|
||||
}
|
||||
if (!data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled")) {
|
||||
if (!subserver.isEnabled()) {
|
||||
hover.append(Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled")));
|
||||
}
|
||||
}
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover.append(Text.builder('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address")).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder('\n' + subserver.getAddress().getAddress().getHostAddress()+':'+subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
} else {
|
||||
hover.append(Text.builder('\n' + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getString("address").split(":").length - 1]).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder("\n" + subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
}
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + subserver));
|
||||
message.onClick(TextActions.runCommand("/subservers open SubServer/ " + subserver.getName()));
|
||||
message.onHover(TextActions.showText(hover.build()));
|
||||
if (i != 0) msg.append(div);
|
||||
msg.append(message.build());
|
||||
@ -376,21 +381,21 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (!sent) sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Server-Header")));
|
||||
Text.Builder msg = Text.builder();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
Text.Builder message = Text.builder(data.getSection("servers").getSection(server).getString("display"));
|
||||
Text.Builder hover = Text.builder(data.getSection("servers").getSection(server).getString("display") + '\n');
|
||||
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
|
||||
Text.Builder message = Text.builder(server.getDisplayName());
|
||||
Text.Builder hover = Text.builder(server.getDisplayName() + '\n');
|
||||
message.color(TextColors.WHITE);
|
||||
hover.color(TextColors.WHITE);
|
||||
if (!server.equals(data.getSection("servers").getSection(server).getString("display"))) {
|
||||
hover.append(Text.builder(server + '\n').color(TextColors.GRAY).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-External") + '\n'),
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(data.getSection("servers").getSection(server).getSection("players").getKeys().size()))));
|
||||
Text.of(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size()))));
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
hover.append(Text.builder('\n' + data.getSection("servers").getSection(server).getString("address")).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
} else {
|
||||
hover.append(Text.builder('\n' + data.getSection("servers").getSection(server).getString("address").split(":")[data.getSection("servers").getSection(server).getString("address").split(":").length - 1]).color(TextColors.WHITE).build());
|
||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||
}
|
||||
message.onHover(TextActions.showText(hover.build()));
|
||||
if (i != 0) msg.append(div);
|
||||
@ -399,49 +404,56 @@ public final class SubCommand implements CommandExecutor {
|
||||
}
|
||||
if (i == 0) sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.List.Empty")));
|
||||
else sender.sendMessage(Text.builder(" ").append(msg.build()).build());
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
if (proxies.keySet().size() > 0) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Proxy-Header")));
|
||||
msg = Text.builder();
|
||||
Text.Builder message = Text.builder("(master)");
|
||||
Text.Builder hover = Text.builder("(master)");
|
||||
message.color(TextColors.GRAY);
|
||||
hover.color(TextColors.GRAY);
|
||||
if (data.getKeys().contains("master-proxy")) {
|
||||
hover.append(Text.builder('\n' + data.getRawString("master-proxy")).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")));
|
||||
if (proxymaster != null) {
|
||||
hover.append(
|
||||
Text.builder('\n' + proxymaster.getName()).color(TextColors.GRAY).build(),
|
||||
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")),
|
||||
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxymaster.getPlayers().size())))
|
||||
);
|
||||
} else hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")));
|
||||
message.onHover(TextActions.showText(hover.build()));
|
||||
msg.append(message.build());
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
message = Text.builder(data.getSection("proxies").getSection(proxy).getString("display"));
|
||||
hover = Text.builder(data.getSection("proxies").getSection(proxy).getString("display"));
|
||||
if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message = Text.builder(proxy.getDisplayName());
|
||||
hover = Text.builder(proxy.getDisplayName());
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
message.color(TextColors.GREEN);
|
||||
hover.color(TextColors.GREEN);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
} else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) {
|
||||
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
|
||||
} else if (proxy.getSubData() != null) {
|
||||
message.color(TextColors.AQUA);
|
||||
hover.color(TextColors.AQUA);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
if (data.getKeys().contains("master-proxy")) {
|
||||
if (proxymaster != null) {
|
||||
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData")));
|
||||
}
|
||||
} else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
} else if (proxy.isRedis()) {
|
||||
message.color(TextColors.WHITE);
|
||||
hover.color(TextColors.WHITE);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")));
|
||||
hover.append(
|
||||
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")),
|
||||
Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())))
|
||||
);
|
||||
} else {
|
||||
message.color(TextColors.RED);
|
||||
hover.color(TextColors.RED);
|
||||
if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) {
|
||||
hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||
}
|
||||
hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Disconnected")));
|
||||
}
|
||||
@ -450,7 +462,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
}
|
||||
sender.sendMessage(Text.builder(" ").append(msg.build()).build());
|
||||
}
|
||||
}));
|
||||
})))));
|
||||
return CommandResult.builder().successCount(1).build();
|
||||
} else {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
|
||||
@ -464,46 +476,46 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (canRun(sender)) {
|
||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||
if (subserver.isPresent()) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(subserver.get().toLowerCase(), data -> {
|
||||
switch (data.getString("type").toLowerCase()) {
|
||||
case "invalid":
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Unknown")));
|
||||
break;
|
||||
case "subserver":
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", data.getSection("server").getString("display"))));
|
||||
if (!data.getSection("server").getString("name").equals(data.getSection("server").getString("display")))
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name")).append(Text.builder(data.getSection("server").getString("name")).color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host")).append(Text.builder(data.getSection("server").getString("host")).color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).append(Text.builder((data.getSection("server").getBoolean("enabled"))?"yes":"no").color((data.getSection("server").getBoolean("enabled"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable")).append(Text.builder((data.getSection("server").getBoolean("editable"))?"yes":"no").color((data.getSection("server").getBoolean("editable"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (data.getSection("server").getList("group").size() > 0) {
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group")));
|
||||
for (int i = 0; i < data.getSection("server").getList("group").size(); i++)
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", "\u00A76" + data.getSection("server").getList("group").get(i).asString())));
|
||||
}
|
||||
if (data.getSection("server").getBoolean("temp")) sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary")).append(Text.builder("yes").color(TextColors.GREEN).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).append(Text.builder((data.getSection("server").getBoolean("running"))?"yes":"no").color((data.getSection("server").getBoolean("running"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging")).append(Text.builder((data.getSection("server").getBoolean("log"))?"yes":"no").color((data.getSection("server").getBoolean("log"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).append(Text.builder(data.getSection("server").getString("address")).color(TextColors.AQUA).build()).build());
|
||||
} else {
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).append(Text.builder(data.getSection("server").getString("address").split(":")[data.getSection("server").getString("address").split(":").length - 1]).color(TextColors.AQUA).build()).build());
|
||||
}
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart")).append(Text.builder((data.getSection("server").getBoolean("auto-restart"))?"yes":"no").color((data.getSection("server").getBoolean("auto-restart"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden")).append(Text.builder((data.getSection("server").getBoolean("hidden"))?"yes":"no").color((data.getSection("server").getBoolean("hidden"))?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (data.getSection("server").getList("incompatible-list").size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible").size(); i++) current.add(data.getSection("server").getList("incompatible").get(i).asString().toLowerCase());
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities")));
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible-list").size(); i++)
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", '\u00A7' + ((current.contains(data.getSection("server").getList("incompatible-list").get(i).asString().toLowerCase()))?'4':'c') + data.getSection("server").getList("incompatible-list").get(i).asString())));
|
||||
}
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).append(Text.builder(data.getSection("server").getString("signature")).color(TextColors.AQUA).build()).build());
|
||||
break;
|
||||
default:
|
||||
plugin.api.getServer(subserver.get(), server -> {
|
||||
if (server == null) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Unknown")));
|
||||
} else if (!(server instanceof SubServer)) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Invalid")));
|
||||
} else ((SubServer) server).getHost(host -> {
|
||||
if (host == null) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info.Invalid")));
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", server.getDisplayName())));
|
||||
if (!server.getName().equals(server.getDisplayName()))
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Real Name")).append(Text.builder(server.getName()).color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host")).append(Text.builder(host.getName()).color(TextColors.AQUA).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).append(Text.builder((((SubServer) server).isEnabled())?"yes":"no").color((((SubServer) server).isEnabled())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable")).append(Text.builder((((SubServer) server).isEditable())?"yes":"no").color((((SubServer) server).isEditable())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (server.getGroups().size() > 0) {
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group")));
|
||||
for (String group : server.getGroups())
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", "\u00A76" + group)));
|
||||
}
|
||||
if (((SubServer) server).isTemporary()) sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Temporary")).append(Text.builder("yes").color(TextColors.GREEN).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Logging")).append(Text.builder((((SubServer) server).isLogging())?"yes":"no").color((((SubServer) server).isLogging())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).append(Text.builder(server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.AQUA).build()).build());
|
||||
} else {
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
|
||||
}
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Auto Restart")).append(Text.builder((((SubServer) server).willAutoRestart())?"yes":"no").color((((SubServer) server).willAutoRestart())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
sender.sendMessage(Text.builder(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Hidden")).append(Text.builder((server.isHidden())?"yes":"no").color((server.isHidden())?TextColors.GREEN:TextColors.DARK_RED).build()).build());
|
||||
if (((SubServer) server).getIncompatibilities().size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Incompatibilities")));
|
||||
for (String other : ((SubServer) server).getIncompatibilities())
|
||||
sender.sendMessage(Text.of(" " + plugin.api.getLang("SubServers", "Command.Info.List").replace("$str$", '\u00A7' + ((current.contains(other.toLowerCase()))?'4':'c') + other)));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return CommandResult.builder().successCount(1).build();
|
||||
} else {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", "/sub info <SubServer>")));
|
||||
@ -531,16 +543,15 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Invalid")));
|
||||
break;
|
||||
case 5:
|
||||
if (data.getString("m").contains("Host")) {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled")));
|
||||
} else {
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled")));
|
||||
}
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled")));
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Running")));
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled")));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Running")));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1])));
|
||||
break;
|
||||
case 0:
|
||||
@ -716,9 +727,10 @@ public final class SubCommand implements CommandExecutor {
|
||||
plugin.subdata.sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, name.get(), host.get(), template.get(), new Version(version.get()), Integer.parseInt(port.get()), data -> {
|
||||
switch (data.getInt("r")) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Exists")));
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Host")));
|
||||
break;
|
||||
case 6:
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Host.Network.API;
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -46,7 +46,7 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(name, null, data -> load(data.getSection("hosts").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Host.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,20 +37,7 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
YAMLSection raw = null;
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
if (data.getSection("clients").getSection(client).getRawString("name").equals(name)) {
|
||||
raw = data.getSection("clients").getSection(client);
|
||||
load(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (raw == null) throw new IllegalStateException("Could not find proxy with name: " + name);
|
||||
}));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Host.Network.API;
|
||||
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -36,7 +36,7 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(null, null, data -> load(data.getSection("servers").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Host.Library.Callback;
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
@ -42,15 +42,6 @@ public class SubServer extends Server {
|
||||
return obj instanceof SubServer && super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a new copy of the data from SubData
|
||||
*/
|
||||
@Override
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> load(data.getSection("hosts").getSection(raw.getRawString("host")).getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
@ -263,11 +254,11 @@ public class SubServer extends Server {
|
||||
}
|
||||
};
|
||||
|
||||
if (host == null) {
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> {
|
||||
host = new Host(data.getSection("hosts").getSection(raw.getRawString("host")));
|
||||
if (host == null || !host.getName().equalsIgnoreCase(raw.getRawString("host"))) {
|
||||
SubAPI.getInstance().getHost(raw.getRawString("host"), host -> {
|
||||
this.host = host;
|
||||
run.run();
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
|
@ -75,6 +75,6 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Host.Library.Callback;
|
||||
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Host.Network.PacketOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
*/
|
||||
public PacketDownloadGroupInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (Out)
|
||||
*
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("group", group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
@ -26,12 +26,12 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host Name
|
||||
* @param host Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(host, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -39,10 +39,10 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("host", host);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,20 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server List Packet
|
||||
* Download Platform Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (In)
|
||||
*/
|
||||
public PacketDownloadServerList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (Out)
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerList(String host, String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
@ -44,8 +33,6 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (host != null) data.set("host", host);
|
||||
if (group != null) data.set("group", group);
|
||||
return data;
|
||||
}
|
||||
|
@ -15,25 +15,34 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
*/
|
||||
public PacketDownloadProxyInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (Out)
|
||||
*
|
||||
* @param proxy Proxy name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.proxy = proxy;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("proxy", proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,6 +53,6 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadServerInfo (Out)
|
||||
*
|
||||
* @param server Server name
|
||||
* @param server Server name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -39,10 +39,10 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("server", server);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("server", server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -106,13 +106,14 @@ public final class SubDataClient {
|
||||
registerPacket(new PacketAuthorization(host), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(host), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(), "SubServers", "DownloadServerList");
|
||||
registerPacket(new PacketExAddServer(host), "SubServers", "ExAddServer");
|
||||
registerPacket(new PacketExConfigureHost(host), "SubServers", "ExConfigureHost");
|
||||
registerPacket(new PacketExCreateServer(host), "SubServers", "ExCreateServer");
|
||||
@ -130,13 +131,14 @@ public final class SubDataClient {
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubServers", "DownloadServerList");
|
||||
registerPacket(PacketExAddServer.class, "SubServers", "ExAddServer");
|
||||
registerPacket(PacketExConfigureHost.class, "SubServers", "ExConfigureHost");
|
||||
registerPacket(PacketExCreateServer.class, "SubServers", "ExCreateServer");
|
||||
|
@ -13,9 +13,7 @@ import net.ME1312.SubServers.Host.Network.API.Host;
|
||||
import net.ME1312.SubServers.Host.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Host.Network.API.Server;
|
||||
import net.ME1312.SubServers.Host.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadPlayerList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -69,7 +67,7 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
host.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
||||
@ -80,7 +78,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -93,7 +91,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getHosts(hosts -> callback.run(hosts.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
Host host = null;
|
||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(host);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
this.host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +116,7 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
host.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
@ -123,7 +135,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -152,7 +164,29 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getLowercaseGroups(groups -> callback.run(groups.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
List<Server> servers = null;
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
||||
servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(servers);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,14 +197,13 @@ public final class SubAPI {
|
||||
public void getServers(Callback<Map<String, Server>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
host.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
servers.put(subserver.toLowerCase(), new SubServer(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver)));
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +212,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -192,7 +225,26 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getServers(servers -> callback.run(servers.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
Server server = null;
|
||||
if (data.getSection("servers").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getSection("servers").getSection(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(server);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,23 +271,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getSubServer(String name, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getSubServers(subservers -> callback.run(subservers.get(name.toLowerCase())));
|
||||
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the known Proxies
|
||||
*
|
||||
* @return Proxy Map
|
||||
* @param callback Proxy Map
|
||||
*/
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
proxies.put(data.getSection("clients").getSection(client).getRawString("name").toLowerCase(), new Proxy(data.getSection("clients").getSection(client)));
|
||||
}
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -243,7 +293,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -252,11 +302,49 @@ public final class SubAPI {
|
||||
* Gets a Proxy
|
||||
*
|
||||
* @param name Proxy name
|
||||
* @return a Proxy
|
||||
* @param callback a Proxy
|
||||
*/
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getProxies(proxies -> callback.run(proxies.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
*
|
||||
* @param callback Master Proxy
|
||||
*/
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
host.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,7 +367,7 @@ public final class SubAPI {
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
host.log.error.println(ew);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Host.Library.TextColor;
|
||||
import net.ME1312.SubServers.Host.Library.Util;
|
||||
import net.ME1312.SubServers.Host.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.API.Host;
|
||||
import net.ME1312.SubServers.Host.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Host.Network.API.Server;
|
||||
import net.ME1312.SubServers.Host.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -101,29 +104,29 @@ public class SubCommand {
|
||||
new Command(null) {
|
||||
@Override
|
||||
public void command(String handle, String[] args) {
|
||||
host.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
host.api.getGroups(groups -> host.api.getHosts(hosts -> host.api.getServers(servers -> host.api.getMasterProxy(proxymaster -> host.api.getProxies(proxies -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
String div = TextColor.RESET + ", ";
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
if (groups.keySet().size() > 0) {
|
||||
host.log.message.println("Group/Server List:");
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
for (String group : groups.keySet()) {
|
||||
String message = " ";
|
||||
message += TextColor.GOLD + group + TextColor.RESET + ": ";
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
for (Server server : groups.get(group)) {
|
||||
if (i != 0) message += div;
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).contains("host")) {
|
||||
if (!(server instanceof SubServer)) {
|
||||
message += TextColor.WHITE;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
} else if (((SubServer) server).isTemporary()) {
|
||||
message += TextColor.AQUA;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
message += TextColor.GREEN;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += TextColor.YELLOW;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
}
|
||||
message += data.getSection("groups").getSection(group).getSection(server).getRawString("display") + " (" + data.getSection("groups").getSection(group).getSection(server).getRawString("address") + ((server.equals(data.getSection("groups").getSection(group).getSection(server).getRawString("display"))) ? "" : TextColor.stripColor(div) + server) + ")";
|
||||
message += server.getDisplayName() + " (" + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName())) ? "" : TextColor.stripColor(div) + server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += TextColor.RESET + "(none)";
|
||||
@ -136,26 +139,26 @@ public class SubCommand {
|
||||
}
|
||||
ExHost h = host;
|
||||
host.log.message.println("Host/SubServer List:");
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (Host host : hosts.values()) {
|
||||
String message = " ";
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
if (host.isEnabled()) {
|
||||
message += TextColor.AQUA;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getRawString("display") + " (" + data.getSection("hosts").getSection(host).getRawString("address") + ((host.equals(data.getSection("hosts").getSection(host).getRawString("display")))?"":TextColor.stripColor(div)+host) + ")" + TextColor.RESET + ": ";
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
message += host.getDisplayName() + " (" + host.getAddress().getHostAddress() + ((host.getName().equals(host.getDisplayName()))?"":TextColor.stripColor(div)+host.getName()) + ")" + TextColor.RESET + ": ";
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
if (i != 0) message += div;
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
if (subserver.isTemporary()) {
|
||||
message += TextColor.AQUA;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
} else if (subserver.isRunning()) {
|
||||
message += TextColor.GREEN;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += TextColor.YELLOW;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("display") + " (" + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("address").split(":").length - 1] + ((subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("display")))?"":TextColor.stripColor(div)+subserver) + ")";
|
||||
message += subserver.getDisplayName() + " (" + subserver.getAddress().getPort() + ((subserver.getName().equals(subserver.getDisplayName()))?"":TextColor.stripColor(div)+subserver.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += TextColor.RESET + "(none)";
|
||||
@ -166,32 +169,32 @@ public class SubCommand {
|
||||
if (!sent) host.log.message.println(TextColor.RESET + "(none)");
|
||||
host.log.message.println("Server List:");
|
||||
String message = " ";
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
|
||||
if (i != 0) message += div;
|
||||
message += TextColor.WHITE + data.getSection("servers").getSection(server).getRawString("display") + " (" + data.getSection("servers").getSection(server).getRawString("address") + ((server.equals(data.getSection("servers").getSection(server).getRawString("display")))?"":TextColor.stripColor(div)+server) + ")";
|
||||
message += TextColor.WHITE + server.getDisplayName() + " (" + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName()))?"":TextColor.stripColor(div)+server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += TextColor.RESET + "(none)";
|
||||
host.log.message.println(message);
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
if (proxies.keySet().size() > 0) {
|
||||
host.log.message.println("Proxy List:");
|
||||
message = " (master)";
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
message += TextColor.GREEN;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) {
|
||||
} else if (proxy.getSubData() != null) {
|
||||
message += TextColor.AQUA;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
} else if (proxy.isRedis()) {
|
||||
message += TextColor.WHITE;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
}
|
||||
message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')');
|
||||
message += proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName()))?"":" ("+proxy.getName()+')');
|
||||
}
|
||||
host.log.message.println(message);
|
||||
}
|
||||
}));
|
||||
})))));
|
||||
}
|
||||
}.description("Lists the available Hosts and Servers").help(
|
||||
"This command will print a list of the available Hosts and Servers.",
|
||||
@ -204,41 +207,43 @@ public class SubCommand {
|
||||
@Override
|
||||
public void command(String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
host.subdata.sendPacket(new PacketDownloadServerInfo(args[0].toLowerCase(), data -> {
|
||||
switch (data.getRawString("type").toLowerCase()) {
|
||||
case "invalid":
|
||||
host.log.message.println("There is no server with that name");
|
||||
break;
|
||||
case "subserver":
|
||||
host.log.message.println("Info on " + data.getSection("server").getRawString("display") + ':');
|
||||
if (!data.getSection("server").getRawString("name").equals(data.getSection("server").getRawString("display"))) host.log.message.println(" - Real Name: " + data.getSection("server").getRawString("name"));
|
||||
host.log.message.println(" - Host: " + data.getSection("server").getRawString("host"));
|
||||
host.log.message.println(" - Enabled: " + ((data.getSection("server").getBoolean("enabled"))?"yes":"no"));
|
||||
host.log.message.println(" - Editable: " + ((data.getSection("server").getBoolean("editable"))?"yes":"no"));
|
||||
if (data.getSection("server").getList("group").size() > 0) {
|
||||
host.log.message.println(" - Group:");
|
||||
for (int i = 0; i < data.getSection("server").getList("group").size(); i++)
|
||||
host.log.message.println(" - " + data.getSection("server").getList("group").get(i).asRawString());
|
||||
host.api.getServer(args[0], server -> {
|
||||
ExHost h = host;
|
||||
if (server == null) {
|
||||
h.log.message.println("There is no server with that name");
|
||||
} else if (!(server instanceof SubServer)) {
|
||||
h.log.message.println("That Server is not a SubServer");
|
||||
} else ((SubServer) server).getHost(host -> {
|
||||
if (host == null) {
|
||||
h.log.message.println("That Server is not a SubServer");
|
||||
} else {
|
||||
h.log.message.println("Info on " + server.getDisplayName() + ':');
|
||||
if (!server.getName().equals(server.getDisplayName())) h.log.message.println(" - Real Name: " + server.getName());
|
||||
h.log.message.println(" - Host: " + host.getName());
|
||||
h.log.message.println(" - Enabled: " + ((((SubServer) server).isEnabled())?"yes":"no"));
|
||||
h.log.message.println(" - Editable: " + ((((SubServer) server).isEditable())?"yes":"no"));
|
||||
if (server.getGroups().size() > 0) {
|
||||
h.log.message.println(" - Group:");
|
||||
for (String group : server.getGroups())
|
||||
h.log.message.println(" - " + group);
|
||||
}
|
||||
if (data.getSection("server").getBoolean("temp")) host.log.message.println(" - Temporary: yes");
|
||||
host.log.message.println(" - Running: " + ((data.getSection("server").getBoolean("running"))?"yes":"no"));
|
||||
host.log.message.println(" - Logging: " + ((data.getSection("server").getBoolean("log"))?"yes":"no"));
|
||||
host.log.message.println(" - Address: " + data.getSection("server").getRawString("address"));
|
||||
host.log.message.println(" - Auto Restart: " + ((data.getSection("server").getBoolean("auto-restart"))?"yes":"no"));
|
||||
host.log.message.println(" - Hidden: " + ((data.getSection("server").getBoolean("hidden"))?"yes":"no"));
|
||||
if (data.getSection("server").getList("incompatible-list").size() > 0) {
|
||||
if (((SubServer) server).isTemporary()) h.log.message.println(" - Temporary: yes");
|
||||
h.log.message.println(" - Running: " + ((((SubServer) server).isRunning())?"yes":"no"));
|
||||
h.log.message.println(" - Logging: " + ((((SubServer) server).isLogging())?"yes":"no"));
|
||||
h.log.message.println(" - Address: " + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
h.log.message.println(" - Auto Restart: " + ((((SubServer) server).willAutoRestart())?"yes":"no"));
|
||||
h.log.message.println(" - Hidden: " + ((server.isHidden())?"yes":"no"));
|
||||
if (((SubServer) server).getIncompatibilities().size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible").size(); i++) current.add(data.getSection("server").getList("incompatible").get(i).asRawString().toLowerCase());
|
||||
host.log.message.println(" - Incompatibilities:");
|
||||
for (int i = 0; i < data.getSection("server").getList("incompatible-list").size(); i++)
|
||||
host.log.message.println(" - " + data.getSection("server").getList("incompatible-list").get(i).asRawString() + ((current.contains(data.getSection("server").getList("incompatible-list").get(i).asRawString().toLowerCase()))?"*":""));
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
|
||||
h.log.message.println(" - Incompatibilities:");
|
||||
for (String other : ((SubServer) server).getIncompatibilities())
|
||||
h.log.message.println(" - " + other + ((current.contains(other))?"*":""));
|
||||
}
|
||||
host.log.message.println(" - Signature: " + data.getSection("server").getRawString("signature"));
|
||||
break;
|
||||
default:
|
||||
host.log.message.println("That Server is not a SubServer");
|
||||
}
|
||||
}));
|
||||
h.log.message.println(" - Signature: " + server.getSignature());
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
host.log.message.println("Usage: /" + handle + " <SubServer>");
|
||||
}
|
||||
@ -266,16 +271,15 @@ public class SubCommand {
|
||||
host.log.message.println("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
if (data.getRawString("m").contains("Host")) {
|
||||
host.log.message.println("That SubServer's Host is not enabled");
|
||||
} else {
|
||||
host.log.message.println("That SubServer is not enabled");
|
||||
}
|
||||
host.log.message.println("That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 6:
|
||||
host.log.message.println("That SubServer is already running");
|
||||
host.log.message.println("That SubServer is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
host.log.message.println("That SubServer is already running");
|
||||
break;
|
||||
case 8:
|
||||
host.log.message.println("That SubServer cannot start while these server(s) are running:", data.getRawString("m").split(":\\s")[1]);
|
||||
break;
|
||||
case 0:
|
||||
@ -440,12 +444,14 @@ public class SubCommand {
|
||||
if (Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||
host.log.message.println("Invalid Port Number");
|
||||
} else {
|
||||
host.subdata.sendPacket(new PacketCreateServer(null, args[0], args[1],args[2], new Version(args[3]), Integer.parseInt(args[4]), data -> {
|
||||
host.subdata.sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), Integer.parseInt(args[4]), data -> {
|
||||
switch (data.getInt("r")) {
|
||||
case 3:
|
||||
host.log.message.println("Server names cannot use spaces");
|
||||
case 4:
|
||||
host.log.message.println("There is already a SubServer with that name");
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
host.log.message.println("There is no host with that name");
|
||||
break;
|
||||
case 6:
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Sync.Network.API;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -46,7 +46,7 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(name, null, data -> load(data.getSection("hosts").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,20 +37,7 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
YAMLSection raw = null;
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
if (data.getSection("clients").getSection(client).getRawString("name").equals(name)) {
|
||||
raw = data.getSection("clients").getSection(client);
|
||||
load(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (raw == null) throw new IllegalStateException("Could not find proxy with name: " + name);
|
||||
}));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Sync.Network.API;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -36,7 +36,7 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(null, null, data -> load(data.getSection("servers").getSection(name))));
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ import net.ME1312.SubServers.Sync.Library.Callback;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
@ -42,15 +41,6 @@ public class SubServer extends Server {
|
||||
return obj instanceof SubServer && super.equals(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a new copy of the data from SubData
|
||||
*/
|
||||
@Override
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> load(data.getSection("hosts").getSection(raw.getRawString("host")).getSection("servers").getSection(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Server
|
||||
*
|
||||
@ -263,11 +253,11 @@ public class SubServer extends Server {
|
||||
}
|
||||
};
|
||||
|
||||
if (host == null) {
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerList(raw.getRawString("host"), null, data -> {
|
||||
host = new Host(data.getSection("hosts").getSection(raw.getRawString("host")));
|
||||
if (host == null || !host.getName().equalsIgnoreCase(raw.getRawString("host"))) {
|
||||
SubAPI.getInstance().getHost(raw.getRawString("host"), host -> {
|
||||
this.host = host;
|
||||
run.run();
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
run.run();
|
||||
}
|
||||
|
@ -75,6 +75,6 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -11,30 +11,27 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server List Packet
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (In)
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
*/
|
||||
public PacketDownloadServerList() {}
|
||||
public PacketDownloadGroupInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerList (Out)
|
||||
* New PacketDownloadGroupInfo (Out)
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Group name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerList(String host, String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -44,8 +41,7 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (host != null) json.set("host", host);
|
||||
if (group != null) json.set("group", group);
|
||||
json.set("group", group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@ -57,6 +53,6 @@ public class PacketDownloadServerList implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
@ -26,12 +26,12 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host Name
|
||||
* @param host Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(host, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -39,10 +39,10 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("host", host);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("host", host);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Callback;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -15,25 +15,34 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
*/
|
||||
public PacketDownloadProxyInfo() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (Out)
|
||||
*
|
||||
* @param proxy Proxy name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.proxy = proxy;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
json.set("proxy", proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,6 +53,6 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadServerInfo (Out)
|
||||
*
|
||||
* @param server Server name
|
||||
* @param server Server name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
@ -53,6 +53,6 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
return new Version("2.13b");
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import net.ME1312.SubServers.Sync.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.Network.Encryption.AES;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
@ -22,7 +23,6 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
@ -86,35 +86,30 @@ public final class SubDataClient {
|
||||
private void init() {
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang(plugin));
|
||||
plugin.subdata.sendPacket(new PacketLinkProxy(plugin));
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(proxy -> plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
if (plugin.lastReload != proxy.getSection("subservers").getLong("last-reload")) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadPlatformInfo(platform -> plugin.api.getServers(servers -> {
|
||||
if (plugin.lastReload != platform.getSection("subservers").getLong("last-reload")) {
|
||||
System.out.println("SubServers > Resetting Server Data");
|
||||
plugin.servers.clear();
|
||||
plugin.lastReload = proxy.getSection("subservers").getLong("last-reload");
|
||||
plugin.lastReload = platform.getSection("subservers").getLong("last-reload");
|
||||
}
|
||||
try {
|
||||
LinkedList<ListenerInfo> listeners = new LinkedList<ListenerInfo>(plugin.getConfig().getListeners());
|
||||
for (int i = 0; i < proxy.getSection("bungee").getSectionList("listeners").size(); i++) if (i < listeners.size()) {
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Forced-Hosts", true)) updateField(ListenerInfo.class.getDeclaredField("forcedHosts"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getSection("forced-hosts").get());
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Motd", false)) updateField(ListenerInfo.class.getDeclaredField("motd"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getRawString("motd"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(ListenerInfo.class.getDeclaredField("maxPlayers"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getInt("player-limit"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Server-Priorities", true)) updateField(ListenerInfo.class.getDeclaredField("serverPriority"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getRawStringList("priorities"));
|
||||
for (int i = 0; i < platform.getSection("bungee").getSectionList("listeners").size(); i++) if (i < listeners.size()) {
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Forced-Hosts", true)) updateField(ListenerInfo.class.getDeclaredField("forcedHosts"), listeners.get(i), platform.getSection("bungee").getSectionList("listeners").get(i).getSection("forced-hosts").get());
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Motd", false)) updateField(ListenerInfo.class.getDeclaredField("motd"), listeners.get(i), platform.getSection("bungee").getSectionList("listeners").get(i).getRawString("motd"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(ListenerInfo.class.getDeclaredField("maxPlayers"), listeners.get(i), platform.getSection("bungee").getSectionList("listeners").get(i).getInt("player-limit"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Server-Priorities", true)) updateField(ListenerInfo.class.getDeclaredField("serverPriority"), listeners.get(i), platform.getSection("bungee").getSectionList("listeners").get(i).getRawStringList("priorities"));
|
||||
}
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Disabled-Commands", false)) updateField(Configuration.class.getDeclaredField("disabledCommands"), plugin.getConfig(), proxy.getSection("bungee").getRawStringList("disabled-cmds"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(Configuration.class.getDeclaredField("playerLimit"), plugin.getConfig(), proxy.getSection("bungee").getInt("player-limit"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Disabled-Commands", false)) updateField(Configuration.class.getDeclaredField("disabledCommands"), plugin.getConfig(), platform.getSection("bungee").getRawStringList("disabled-cmds"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(Configuration.class.getDeclaredField("playerLimit"), plugin.getConfig(), platform.getSection("bungee").getInt("player-limit"));
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubServers > Problem syncing BungeeCord configuration options");
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
plugin.merge(subserver, data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver), true);
|
||||
}
|
||||
for (Server server : servers.values()) {
|
||||
plugin.merge(server);
|
||||
}
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
plugin.merge(server, data.getSection("servers").getSection(server), false);
|
||||
}
|
||||
}))));
|
||||
})));
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
@ -138,13 +133,14 @@ public final class SubDataClient {
|
||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketDownloadServerList(), "SubServers", "DownloadServerList");
|
||||
registerPacket(new PacketInRunEvent(), "SubServers", "RunEvent");
|
||||
registerPacket(new PacketInReset(), "SubServers", "Reset");
|
||||
registerPacket(new PacketLinkProxy(plugin), "SubServers", "LinkProxy");
|
||||
@ -154,13 +150,14 @@ public final class SubDataClient {
|
||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
||||
registerPacket(PacketDownloadServerList.class, "SubServers", "DownloadServerList");
|
||||
registerPacket(PacketLinkProxy.class, "SubServers", "LinkProxy");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
|
@ -6,9 +6,7 @@ import net.ME1312.SubServers.Sync.Network.API.Host;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadNetworkList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadPlayerList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerList;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@ -67,7 +65,7 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
||||
@ -91,7 +89,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getHosts(hosts -> callback.run(hosts.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
Host host = null;
|
||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(host);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,7 +114,7 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
@ -150,7 +162,29 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getLowercaseGroups(groups -> callback.run(groups.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
List<Server> servers = null;
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
||||
servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(servers);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,14 +195,13 @@ public final class SubAPI {
|
||||
public void getServers(Callback<Map<String, Server>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
servers.put(subserver.toLowerCase(), new SubServer(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver)));
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +223,26 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getServers(servers -> callback.run(servers.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
Server server = null;
|
||||
if (data.getSection("servers").getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getSection("servers").getSection(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(server);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,23 +269,21 @@ public final class SubAPI {
|
||||
*/
|
||||
public void getSubServer(String name, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getSubServers(subservers -> callback.run(subservers.get(name.toLowerCase())));
|
||||
getServer(name, server -> callback.run((server instanceof SubServer)?(SubServer) server:null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the known Proxies
|
||||
*
|
||||
* @return Proxy Map
|
||||
* @param callback Proxy Map
|
||||
*/
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadNetworkList(data -> {
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||
for (String client : data.getSection("clients").getKeys()) {
|
||||
if (data.getSection("clients").getSection(client).getKeys().size() > 0 && data.getSection("clients").getSection(client).getRawString("type", "").equals("Proxy")) {
|
||||
proxies.put(data.getSection("clients").getSection(client).getRawString("name").toLowerCase(), new Proxy(data.getSection("clients").getSection(client)));
|
||||
}
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -250,11 +300,49 @@ public final class SubAPI {
|
||||
* Gets a Proxy
|
||||
*
|
||||
* @param name Proxy name
|
||||
* @return a Proxy
|
||||
* @param callback a Proxy
|
||||
*/
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
getProxies(proxies -> callback.run(proxies.get(name.toLowerCase())));
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Master Proxy redis container (null if unavailable)
|
||||
*
|
||||
* @param callback Master Proxy
|
||||
*/
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
}
|
||||
|
||||
try {
|
||||
callback.run(proxy);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,10 +6,11 @@ import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Host;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Proxy;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.Server.Server;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@ -91,29 +92,29 @@ public final class SubCommand extends CommandX {
|
||||
}
|
||||
}).start();
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, data -> {
|
||||
plugin.api.getGroups(groups -> plugin.api.getHosts(hosts -> plugin.api.getServers(servers -> plugin.api.getMasterProxy(proxymaster -> plugin.api.getProxies(proxies -> {
|
||||
int i = 0;
|
||||
boolean sent = false;
|
||||
String div = ChatColor.RESET + ", ";
|
||||
if (data.getSection("groups").getKeys().size() > 0) {
|
||||
sender.sendMessage("SubServers > Group/Server List:");
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
if (groups.keySet().size() > 0) {
|
||||
sender.sendMessage("Group/Server List:");
|
||||
for (String group : groups.keySet()) {
|
||||
String message = " ";
|
||||
message += ChatColor.GOLD + group + ChatColor.RESET + ": ";
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
for (Server server : groups.get(group)) {
|
||||
if (i != 0) message += div;
|
||||
if (!data.getSection("groups").getSection(group).getSection(server).contains("host")) {
|
||||
if (!(server instanceof SubServer)) {
|
||||
message += ChatColor.WHITE;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("temp")) {
|
||||
} else if (((SubServer) server).isTemporary()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("running")) {
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("groups").getSection(group).getSection(server).getBoolean("enabled") && data.getSection("groups").getSection(group).getSection(server).getList("incompatible").size() == 0) {
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("groups").getSection(group).getSection(server).getRawString("display") + " (" + data.getSection("groups").getSection(group).getSection(server).getRawString("address") + ((server.equals(data.getSection("groups").getSection(group).getSection(server).getRawString("display"))) ? "" : ChatColor.stripColor(div) + server) + ")";
|
||||
message += server.getDisplayName() + " (" + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName())) ? "" : ChatColor.stripColor(div) + server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += ChatColor.RESET + "(none)";
|
||||
@ -124,27 +125,27 @@ public final class SubCommand extends CommandX {
|
||||
if (!sent) sender.sendMessage(ChatColor.RESET + "(none)");
|
||||
sent = false;
|
||||
}
|
||||
sender.sendMessage("SubServers > Host/SubServer List:");
|
||||
for (String host : data.getSection("hosts").getKeys()) {
|
||||
sender.sendMessage("Host/SubServer List:");
|
||||
for (Host host : hosts.values()) {
|
||||
String message = " ";
|
||||
if (data.getSection("hosts").getSection(host).getBoolean("enabled")) {
|
||||
if (host.isEnabled()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getRawString("display") + " (" + data.getSection("hosts").getSection(host).getRawString("address") + ((host.equals(data.getSection("hosts").getSection(host).getRawString("display"))) ? "" : ChatColor.stripColor(div) + host) + ")" + ChatColor.RESET + ": ";
|
||||
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) {
|
||||
message += host.getDisplayName() + " (" + host.getAddress().getHostAddress() + ((host.getName().equals(host.getDisplayName()))?"":ChatColor.stripColor(div)+host.getName()) + ")" + ChatColor.RESET + ": ";
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
if (i != 0) message += div;
|
||||
if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("temp")) {
|
||||
if (subserver.isTemporary()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("running")) {
|
||||
} else if (subserver.isRunning()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getBoolean("enabled") && data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getList("incompatible").size() == 0) {
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("display") + " (" + data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("address").split(":")[data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("address").split(":").length - 1] + ((subserver.equals(data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver).getRawString("display"))) ? "" : ChatColor.stripColor(div) + subserver) + ")";
|
||||
message += subserver.getDisplayName() + " (" + subserver.getAddress().getPort() + ((subserver.getName().equals(subserver.getDisplayName()))?"":ChatColor.stripColor(div)+subserver.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += ChatColor.RESET + "(none)";
|
||||
@ -153,34 +154,34 @@ public final class SubCommand extends CommandX {
|
||||
sent = true;
|
||||
}
|
||||
if (!sent) sender.sendMessage(ChatColor.RESET + "(none)");
|
||||
sender.sendMessage("SubServers > Server List:");
|
||||
sender.sendMessage("Server List:");
|
||||
String message = " ";
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
for (Server server : servers.values()) if (!(server instanceof SubServer)) {
|
||||
if (i != 0) message += div;
|
||||
message += ChatColor.WHITE + data.getSection("servers").getSection(server).getRawString("display") + " (" + data.getSection("servers").getSection(server).getRawString("address") + ((server.equals(data.getSection("servers").getSection(server).getRawString("display"))) ? "" : ChatColor.stripColor(div) + server) + ")";
|
||||
message += ChatColor.WHITE + server.getDisplayName() + " (" + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName()))?"":ChatColor.stripColor(div)+server.getName()) + ")";
|
||||
i++;
|
||||
}
|
||||
if (i == 0) message += ChatColor.RESET + "(none)";
|
||||
sender.sendMessage(message);
|
||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
||||
sender.sendMessage("SubServers > Proxy List:");
|
||||
if (proxies.keySet().size() > 0) {
|
||||
sender.sendMessage("Proxy List:");
|
||||
message = " (master)";
|
||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) {
|
||||
} else if (proxy.getSubData() != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) {
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
}
|
||||
message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')');
|
||||
message += proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName()))?"":" ("+proxy.getName()+')');
|
||||
}
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
}));
|
||||
})))));
|
||||
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) {
|
||||
if (args.length > 1) {
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(args[1].toLowerCase(), data -> {
|
||||
@ -232,15 +233,17 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
if (data.getRawString("m").contains("Host")) {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
} else {
|
||||
sender.sendMessage("SubServers > That SubServer is not enabled");
|
||||
}
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("SubServers > That SubServer is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("SubServers > That SubServer is already running");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessages("That SubServer cannot start while these server(s) are running:", data.getRawString("m").split(":\\s")[1]);
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("SubServers > Server was started successfully");
|
||||
@ -349,9 +352,10 @@ public final class SubCommand extends CommandX {
|
||||
plugin.subdata.sendPacket(new PacketCreateServer(null, args[1], args[2],args[3], new Version(args[4]), Integer.parseInt(args[5]), data -> {
|
||||
switch (data.getInt("r")) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage("SubServers > There is already a SubServer with that name");
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
sender.sendMessage("SubServers > There is no host with that name");
|
||||
break;
|
||||
case 6:
|
||||
@ -437,10 +441,10 @@ public final class SubCommand extends CommandX {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (args.length == 2) {
|
||||
if (last.length() == 0) {
|
||||
for (Server server : plugin.servers.values()) if (server instanceof SubServer) list.add(server.getName());
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) if (server instanceof net.ME1312.SubServers.Sync.Server.SubServer) list.add(server.getName());
|
||||
} else {
|
||||
for (Server server : plugin.servers.values()) {
|
||||
if (server instanceof SubServer && server.getName().toLowerCase().startsWith(last))
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Server.SubServer && server.getName().toLowerCase().startsWith(last))
|
||||
list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
@ -452,10 +456,10 @@ public final class SubCommand extends CommandX {
|
||||
if (args.length == 2) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (Server server : plugin.servers.values()) if (server instanceof SubServer) list.add(server.getName());
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) if (server instanceof net.ME1312.SubServers.Sync.Server.SubServer) list.add(server.getName());
|
||||
} else {
|
||||
for (Server server : plugin.servers.values()) {
|
||||
if (server instanceof SubServer && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Server.SubServer && server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
@ -519,16 +523,16 @@ public final class SubCommand extends CommandX {
|
||||
private void updateTemplateCache() {
|
||||
if (Calendar.getInstance().getTime().getTime() - templateCache.name() >= TimeUnit.MINUTES.toMillis(5)) {
|
||||
templateCache.rename(Calendar.getInstance().getTime().getTime());
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, (json) -> {
|
||||
TreeMap<String, List<String>> hosts = new TreeMap<String, List<String>>();
|
||||
for (String host : json.getSection("hosts").getKeys()) {
|
||||
plugin.api.getHosts(hosts -> {
|
||||
TreeMap<String, List<String>> cache = new TreeMap<String, List<String>>();
|
||||
for (Host host : hosts.values()) {
|
||||
List<String> templates = new ArrayList<String>();
|
||||
templates.addAll(json.getSection("hosts").getSection(host).getSection("creator").getSection("templates").getKeys());
|
||||
hosts.put(host, templates);
|
||||
templates.addAll(host.getCreator().getTemplates().keySet());
|
||||
cache.put(host.getName().toLowerCase(), templates);
|
||||
}
|
||||
templateCache.set(hosts);
|
||||
templateCache.set(cache);
|
||||
templateCache.rename(Calendar.getInstance().getTime().getTime());
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@ -565,7 +569,7 @@ public final class SubCommand extends CommandX {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
if (args.length > 0) {
|
||||
Map<String, Server> servers = plugin.servers;
|
||||
Map<String, net.ME1312.SubServers.Sync.Server.Server> servers = plugin.servers;
|
||||
if (servers.keySet().contains(args[0].toLowerCase())) {
|
||||
((ProxiedPlayer) sender).connect(servers.get(args[0].toLowerCase()));
|
||||
} else {
|
||||
@ -575,8 +579,8 @@ public final class SubCommand extends CommandX {
|
||||
int i = 0;
|
||||
TextComponent serverm = new TextComponent(ChatColor.RESET.toString());
|
||||
TextComponent div = new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.Divider"));
|
||||
for (Server server : plugin.servers.values()) {
|
||||
if (!server.isHidden() && (!(server instanceof SubServer) || ((SubServer) server).isRunning())) {
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
|
||||
if (!server.isHidden() && (!(server instanceof net.ME1312.SubServers.Sync.Server.SubServer) || ((net.ME1312.SubServers.Sync.Server.SubServer) server).isRunning())) {
|
||||
if (i != 0) serverm.addExtra(div);
|
||||
TextComponent message = new TextComponent(plugin.api.getLang("SubServers", "Bungee.Server.List").replace("$str$", server.getDisplayName()));
|
||||
try {
|
||||
@ -646,7 +650,7 @@ public final class SubCommand extends CommandX {
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
List<String> messages = new LinkedList<String>();
|
||||
int players = 0;
|
||||
for (Server server : plugin.servers.values()) {
|
||||
for (net.ME1312.SubServers.Sync.Server.Server server : plugin.servers.values()) {
|
||||
List<String> playerlist = new ArrayList<String>();
|
||||
if (plugin.redis) {
|
||||
try {
|
||||
@ -660,7 +664,7 @@ public final class SubCommand extends CommandX {
|
||||
Collections.sort(playerlist);
|
||||
|
||||
players += playerlist.size();
|
||||
if (!server.isHidden() && (!(server instanceof SubServer) || ((SubServer) server).isRunning())) {
|
||||
if (!server.isHidden() && (!(server instanceof net.ME1312.SubServers.Sync.Server.SubServer) || ((net.ME1312.SubServers.Sync.Server.SubServer) server).isRunning())) {
|
||||
int i = 0;
|
||||
String message = plugin.api.getLang("SubServers", "Bungee.List.Format").replace("$str$", server.getDisplayName()).replace("$int$", Integer.toString(playerlist.size()));
|
||||
for (String player : playerlist) {
|
||||
|
@ -245,21 +245,19 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void add(SubAddServerEvent e) {
|
||||
subdata.sendPacket(new PacketDownloadServerInfo(e.getServer(), data -> {
|
||||
switch (data.getRawString("type").toLowerCase()) {
|
||||
case "invalid":
|
||||
System.out.println("PacketDownloadServerInfo(" + e.getServer() + ") returned with an invalid response");
|
||||
break;
|
||||
case "subserver":
|
||||
servers.put(data.getSection("server").getRawString("name").toLowerCase(), new SubServer(data.getSection("server").getRawString("signature"), data.getSection("server").getRawString("name"), data.getSection("server").getRawString("display"), new InetSocketAddress(data.getSection("server").getRawString("address").split(":")[0], Integer.parseInt(data.getSection("server").getRawString("address").split(":")[1])), data.getSection("server").getRawString("motd"), data.getSection("server").getBoolean("hidden"), data.getSection("server").getBoolean("restricted"), data.getSection("server").getBoolean("running")));
|
||||
api.getServer(e.getServer(), server -> {
|
||||
if (server != null) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getMotd(), server.isHidden(), server.isRestricted(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
System.out.println("SubServers > Added SubServer: " + e.getServer());
|
||||
break;
|
||||
default:
|
||||
servers.put(data.getSection("server").getRawString("name").toLowerCase(), new Server(data.getSection("server").getRawString("signature"), data.getSection("server").getRawString("name"), data.getSection("server").getRawString("display"), new InetSocketAddress(data.getSection("server").getRawString("address").split(":")[0], Integer.parseInt(data.getSection("server").getRawString("address").split(":")[1])), data.getSection("server").getRawString("motd"), data.getSection("server").getBoolean("hidden"), data.getSection("server").getBoolean("restricted")));
|
||||
} else {
|
||||
servers.put(server.getName().toLowerCase(), new Server(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getMotd(), server.isHidden(), server.isRestricted()));
|
||||
System.out.println("SubServers > Added Server: " + e.getServer());
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
} else System.out.println("PacketDownloadServerInfo(" + e.getServer() + ") returned with an invalid response");
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
@ -268,35 +266,35 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
((SubServer) servers.get(e.getServer().toLowerCase())).setRunning(true);
|
||||
}
|
||||
|
||||
public Boolean merge(String name, YAMLSection data, boolean isSubServer) {
|
||||
Server server = servers.get(name.toLowerCase());
|
||||
if (server == null || isSubServer || !(server instanceof SubServer)) {
|
||||
if (server == null || !server.getSignature().equals(data.getRawString("signature"))) {
|
||||
if (isSubServer) {
|
||||
servers.put(name.toLowerCase(), new SubServer(data.getRawString("signature"), name, data.getRawString("display"), new InetSocketAddress(data.getRawString("address").split(":")[0],
|
||||
Integer.parseInt(data.getRawString("address").split(":")[1])), data.getRawString("motd"), data.getBoolean("hidden"), data.getBoolean("restricted"), data.getBoolean("running")));
|
||||
public Boolean merge(net.ME1312.SubServers.Sync.Network.API.Server server) {
|
||||
Server current = servers.get(server.getName().toLowerCase());
|
||||
if (current == null || server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer || !(current instanceof SubServer)) {
|
||||
if (current == null || !current.getSignature().equals(server.getSignature())) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getMotd(), server.isHidden(), server.isRestricted(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
} else {
|
||||
servers.put(name.toLowerCase(), new Server(data.getRawString("signature"), name, data.getRawString("display"), new InetSocketAddress(data.getRawString("address").split(":")[0],
|
||||
Integer.parseInt(data.getRawString("address").split(":")[1])), data.getRawString("motd"), data.getBoolean("hidden"), data.getBoolean("restricted")));
|
||||
servers.put(server.getName().toLowerCase(), new Server(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getMotd(), server.isHidden(), server.isRestricted()));
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Added "+((isSubServer)?"Sub":"")+"Server: " + name);
|
||||
System.out.println("SubServers > Added "+((server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer)?"Sub":"")+"Server: " + server.getName());
|
||||
return true;
|
||||
} else {
|
||||
if (isSubServer) {
|
||||
if (data.getBoolean("running") != ((SubServer) server).isRunning())
|
||||
((SubServer) server).setRunning(data.getBoolean("running"));
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
if (((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning() != ((SubServer) current).isRunning())
|
||||
((SubServer) current).setRunning(((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning());
|
||||
}
|
||||
if (!data.getRawString("motd").equals(server.getMotd()))
|
||||
server.setMotd(data.getRawString("motd"));
|
||||
if (data.getBoolean("hidden") != server.isHidden())
|
||||
server.setHidden(data.getBoolean("hidden"));
|
||||
if (data.getBoolean("restricted") != server.isRestricted())
|
||||
server.setRestricted(data.getBoolean("restricted"));
|
||||
if (!data.getRawString("display").equals(server.getDisplayName()))
|
||||
server.setDisplayName(data.getRawString("display"));
|
||||
if (!server.getMotd().equals(current.getMotd()))
|
||||
current.setMotd(server.getMotd());
|
||||
if (server.isHidden() != current.isHidden())
|
||||
current.setHidden(server.isHidden());
|
||||
if (server.isRestricted() != current.isRestricted())
|
||||
current.setRestricted(server.isRestricted());
|
||||
if (!server.getDisplayName().equals(current.getDisplayName()))
|
||||
current.setDisplayName(server.getDisplayName());
|
||||
|
||||
System.out.println("SubServers > Re-added "+((isSubServer)?"Sub":"")+"Server: " + name);
|
||||
System.out.println("SubServers > Re-added "+((server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer)?"Sub":"")+"Server: " + server.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user