mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Mirror changes in SubServers.Sync
This commit is contained in:
parent
61ee89cfe3
commit
185b6b84bb
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w20a</version>
|
||||
<version>19w20b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w20f</version>
|
||||
<version>19w20g</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -62,7 +62,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
this.queue = new LinkedList<PacketObjectOut>();
|
||||
this.clean = false;
|
||||
|
||||
setSubData(null, 0);
|
||||
subdata.put(0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -365,4 +365,13 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> hinfo = super.forSubData();
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>();
|
||||
for (int channel : this.subdata.keySet()) subdata.set(channel, (this.subdata.get(channel) == null)?null:this.subdata.get(channel).getID());
|
||||
hinfo.set("subdata", subdata);
|
||||
return hinfo;
|
||||
}
|
||||
}
|
||||
|
@ -450,11 +450,6 @@ public abstract class Host implements ExtraDataHandler {
|
||||
servers.set(server.getName(), server.forSubData());
|
||||
}
|
||||
hinfo.set("servers", servers);
|
||||
if (this instanceof ClientHandler) {
|
||||
LinkedList<UUID> subdata = new LinkedList<UUID>();
|
||||
for (DataClient client : ((ClientHandler) this).getSubData()) subdata.add((client == null)?null:client.getID());
|
||||
hinfo.set("subdata", subdata);
|
||||
}
|
||||
hinfo.set("signature", signature);
|
||||
hinfo.set("extra", getExtra());
|
||||
return hinfo;
|
||||
|
@ -36,7 +36,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
this.name = name;
|
||||
this.signature = SubAPI.getInstance().signAnonymousObject();
|
||||
|
||||
setSubData(null, 0);
|
||||
subdata.put(0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,8 +48,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
public void setSubData(SubDataClient client, int channel) {
|
||||
boolean update = false;
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (client != null || channel == 0) {
|
||||
@ -189,8 +188,8 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
}
|
||||
info.set("players", players);
|
||||
info.set("redis", isRedis());
|
||||
LinkedList<UUID> subdata = new LinkedList<UUID>();
|
||||
for (DataClient client : getSubData()) subdata.add((client == null)?null:client.getID());
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>();
|
||||
for (int channel : this.subdata.keySet()) subdata.set(channel, (this.subdata.get(channel) == null)?null:this.subdata.get(channel).getID());
|
||||
info.set("subdata", subdata);
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
|
@ -41,7 +41,7 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
SubAPI.getInstance().getSubDataNetwork().getProtocol().whitelist(getAddress().getAddress().getHostAddress());
|
||||
this.hidden = hidden;
|
||||
|
||||
setSubData(null, 0);
|
||||
subdata.put(0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,7 +71,7 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
args.set("channel", channel);
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
if (client != null) args.set("id", client.getID());
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
}
|
||||
}
|
||||
@ -259,8 +259,8 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
players.set(player.get().toString(), pinfo);
|
||||
}
|
||||
info.set("players", players);
|
||||
LinkedList<UUID> subdata = new LinkedList<UUID>();
|
||||
for (DataClient client : getSubData()) subdata.add((client == null)?null:client.getID());
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>();
|
||||
for (int channel : this.subdata.keySet()) subdata.set(channel, (this.subdata.get(channel) == null)?null:this.subdata.get(channel).getID());
|
||||
info.set("subdata", subdata);
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
|
@ -81,6 +81,7 @@ public class ConfigUpdater {
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Smart-Fallback", updated.getMap("Settings", new YAMLSection()).getBoolean("Smart-Fallback", true));
|
||||
settings.set("Override-Bungee-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Override-Bungee-Commands", true));
|
||||
|
||||
YAMLSection upnp = new YAMLSection();
|
||||
@ -164,7 +165,6 @@ public class ConfigUpdater {
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Smart-Fallback", updated.getMap("Settings", new YAMLSection()).getBoolean("Smart-Fallback", true));
|
||||
settings.set("Run-On-Launch-Timeout", updated.getMap("Settings", new YAMLSection()).getInt("Run-On-Launch-Timeout", 0));
|
||||
|
||||
rewritten.set("Settings", settings);
|
||||
|
@ -61,17 +61,20 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
|
||||
Map<String, Proxy> proxies = plugin.api.getProxies();
|
||||
String name = ((data.contains(0x0000))?data.getRawString(0x0000):null);
|
||||
Integer channel = data.getInt(0x0001);
|
||||
|
||||
boolean isnew = false;
|
||||
Proxy proxy;
|
||||
if (name != null && proxies.keySet().contains(name.toLowerCase())) {
|
||||
proxy = proxies.get(name.toLowerCase());
|
||||
} else {
|
||||
proxy = new Proxy((name != null && !proxies.keySet().contains(name.toLowerCase()))?name:null);
|
||||
plugin.getPluginManager().callEvent(new SubAddProxyEvent(proxy));
|
||||
isnew = true;
|
||||
plugin.proxies.put(proxy.getName().toLowerCase(), proxy);
|
||||
}
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(Proxy.class.getDeclaredField("subdata"), proxy), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
proxy.setSubData(client, channel);
|
||||
if (isnew) plugin.getPluginManager().callEvent(new SubAddProxyEvent(proxy));
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName() + ((channel > 0)?" (Sub-"+channel+")":""));
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0, null));
|
||||
setReady(client, true);
|
||||
|
@ -57,10 +57,18 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
}
|
||||
|
||||
private void broadcast(PacketOutExRunEvent packet) {
|
||||
broadcast(null, packet);
|
||||
}
|
||||
|
||||
private void broadcast(Object self, PacketOutExRunEvent packet) {
|
||||
List<SubDataClient> clients = new LinkedList<SubDataClient>();
|
||||
clients.addAll(plugin.subdata.getClients().values());
|
||||
for (SubDataClient client : clients) {
|
||||
client.sendPacket(packet);
|
||||
if (client.getHandler() == null || client.getHandler() != self) { // Don't send events about yourself to yourself
|
||||
if (client.getHandler() == null || client.getHandler().getSubData()[0] == client) { // Don't send events over subchannels
|
||||
client.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +76,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
public void event(SubAddProxyEvent event) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("proxy", event.getProxy().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getProxy(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
@ -77,7 +85,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +96,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
if (event.getHost() != null) args.set("host", event.getHost().getName());
|
||||
args.set("server", event.getServer().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +171,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
if (event.getHost() != null) args.set("host", event.getHost().getName());
|
||||
args.set("server", event.getServer().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +181,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,6 +189,6 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
public void event(SubRemoveProxyEvent event) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("proxy", event.getProxy().getName());
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
broadcast(event.getProxy(), new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
@ -48,13 +48,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w20a</version>
|
||||
<version>19w20b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w20f</version>
|
||||
<version>19w20g</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -57,8 +57,18 @@ public class Host {
|
||||
*
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
if (raw.contains("subdata")) {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
} else {
|
||||
return new UUID[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +46,14 @@ public class Proxy {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +45,14 @@ public class Server {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w20a</version>
|
||||
<version>19w20b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w20f</version>
|
||||
<version>19w20g</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -60,8 +60,18 @@ public class Host {
|
||||
*
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
if (raw.contains("subdata")) {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
} else {
|
||||
return new UUID[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +46,14 @@ public class Proxy {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +45,14 @@ public class Server {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,13 +20,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w20a</version>
|
||||
<version>19w20b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w20f</version>
|
||||
<version>19w20g</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -60,8 +60,18 @@ public class Host {
|
||||
*
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
if (raw.contains("subdata")) {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
} else {
|
||||
return new UUID[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +46,14 @@ public class Proxy {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,8 +45,14 @@ public class Server {
|
||||
*
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ import net.ME1312.Galaxi.Engine.GalaxiEngine;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Library.DebugUtil;
|
||||
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
@ -57,7 +58,8 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
setReady(client, true);
|
||||
} else {
|
||||
log.info("Could not link name with host" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||
log.severe("Could not link name with host" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||
DebugUtil.logException(new IllegalStateException(), log);
|
||||
GalaxiEngine.getInstance().stop();
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import net.ME1312.SubServers.Host.Library.TextColor;
|
||||
import net.ME1312.SubServers.Host.Network.API.*;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -30,6 +30,14 @@ public class SubCommand {
|
||||
private static TreeMap<String, Boolean> serverCache = new TreeMap<String, Boolean>();
|
||||
private static long cacheDate = 0;
|
||||
|
||||
private static boolean canRun() {
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] == null) {
|
||||
throw new IllegalStateException("SubData is not connected");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private SubCommand() {}
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static void load(ExHost host) {
|
||||
@ -37,18 +45,20 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
int i = 0;
|
||||
String str = args[0];
|
||||
if (args.length > 1) {
|
||||
do {
|
||||
i++;
|
||||
str = str + " " + args[i].replace(" ", "\\ ");
|
||||
} while ((i + 1) != args.length);
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
int i = 0;
|
||||
String str = args[0];
|
||||
if (args.length > 1) {
|
||||
do {
|
||||
i++;
|
||||
str = str + " " + args[i].replace(" ", "\\ ");
|
||||
} while ((i + 1) != args.length);
|
||||
}
|
||||
GalaxiEngine.getInstance().getConsoleReader().runCommand(sender, str);
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <Command> [Args...]");
|
||||
}
|
||||
GalaxiEngine.getInstance().getConsoleReader().runCommand(sender, str);
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <Command> [Args...]");
|
||||
}
|
||||
}
|
||||
}.autocomplete((sender, handle, args) -> {
|
||||
@ -91,7 +101,7 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
host.api.getGroups(groups -> host.api.getHosts(hosts -> host.api.getServers(servers -> host.api.getMasterProxy(proxymaster -> host.api.getProxies(proxies -> {
|
||||
if (canRun()) 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 + ", ";
|
||||
@ -196,125 +206,127 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
String type = (args.length > 1)?args[0]:null;
|
||||
String name = args[(type != null)?1:0];
|
||||
|
||||
Runnable getServer = () -> host.api.getServer(name, server -> {
|
||||
if (server != null) {
|
||||
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + TextColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + TextColor.RED + "no");
|
||||
sender.sendMessage(" -> Host: " + TextColor.WHITE + ((SubServer) server).getHost());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + TextColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + TextColor.WHITE + group);
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?TextColor.GREEN+"yes"+((server.getSubData().length > 1)?TextColor.AQUA+" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Players: " + TextColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(" -> MOTD: " + TextColor.WHITE + TextColor.stripColor(server.getMotd()));
|
||||
if (server instanceof SubServer && ((SubServer) server).getStopAction() != SubServer.StopAction.NONE) sender.sendMessage(" -> Stop Action: " + TextColor.WHITE + ((SubServer) server).getStopAction().toString());
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + server.getSignature());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Logging: " + ((((SubServer) server).isLogging())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Restricted: " + ((server.isRestricted())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
|
||||
sender.sendMessage(" -> Incompatibilities:");
|
||||
for (String other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(" - " + ((current.contains(other.toLowerCase()))?TextColor.WHITE:TextColor.GRAY) + other);
|
||||
}
|
||||
sender.sendMessage(" -> Hidden: " + ((server.isHidden())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
} else {
|
||||
if (type == null) {
|
||||
sender.sendMessage("SubServers > There is no object with that name");
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
String type = (args.length > 1)?args[0]:null;
|
||||
String name = args[(type != null)?1:0];
|
||||
|
||||
Runnable getServer = () -> host.api.getServer(name, server -> {
|
||||
if (server != null) {
|
||||
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + TextColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + TextColor.RED + "no");
|
||||
sender.sendMessage(" -> Host: " + TextColor.WHITE + ((SubServer) server).getHost());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + TextColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + TextColor.WHITE + group);
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?TextColor.GREEN+"yes"+((server.getSubData().length > 1)?TextColor.AQUA+" +"+(server.getSubData().length-1)+" subchannel"+((server.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Players: " + TextColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(" -> MOTD: " + TextColor.WHITE + TextColor.stripColor(server.getMotd()));
|
||||
if (server instanceof SubServer && ((SubServer) server).getStopAction() != SubServer.StopAction.NONE) sender.sendMessage(" -> Stop Action: " + TextColor.WHITE + ((SubServer) server).getStopAction().toString());
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + server.getSignature());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Logging: " + ((((SubServer) server).isLogging())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Restricted: " + ((server.isRestricted())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (server instanceof SubServer && ((SubServer) server).getIncompatibilities().size() > 0) {
|
||||
List<String> current = new ArrayList<String>();
|
||||
for (String other : ((SubServer) server).getCurrentIncompatibilities()) current.add(other.toLowerCase());
|
||||
sender.sendMessage(" -> Incompatibilities:");
|
||||
for (String other : ((SubServer) server).getIncompatibilities()) sender.sendMessage(" - " + ((current.contains(other.toLowerCase()))?TextColor.WHITE:TextColor.GRAY) + other);
|
||||
}
|
||||
sender.sendMessage(" -> Hidden: " + ((server.isHidden())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no server with that name");
|
||||
if (type == null) {
|
||||
sender.sendMessage("SubServers > There is no object with that name");
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no server with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getGroup = () -> host.api.getGroup(name, group -> {
|
||||
if (group != null) {
|
||||
sender.sendMessage("SubServers > Info on Group: " + TextColor.WHITE + name);
|
||||
sender.sendMessage(" -> Servers: " + ((group.size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + group.size()));
|
||||
for (Server server : group) sender.sendMessage(" - " + TextColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
|
||||
} else {
|
||||
if (type == null) {
|
||||
getServer.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no group with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getHost = () -> host.api.getHost(name, host -> {
|
||||
if (host != null) {
|
||||
sender.sendMessage("SubServers > Info on Host: " + TextColor.WHITE + host.getDisplayName());
|
||||
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + host.getName());
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData().length > 0) sender.sendMessage(" -> Connected: " + ((host.getSubData()[0] != null)?TextColor.GREEN+"yes"+((host.getSubData().length > 1)?TextColor.AQUA+" +"+(host.getSubData().length-1)+" subchannel"+((host.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?TextColor.WHITE:TextColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(" - " + ((template.isEnabled())?TextColor.WHITE:TextColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + host.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
getGroup.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no host with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getProxy = () -> host.api.getProxy(name, proxy -> {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage("SubServers > Info on Proxy: " + TextColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?TextColor.GREEN+"yes"+((proxy.getSubData().length > 1)?TextColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?TextColor.GREEN:TextColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
getHost.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no proxy with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (type == null) {
|
||||
getProxy.run();
|
||||
} else {
|
||||
switch (type.toLowerCase()) {
|
||||
case "p":
|
||||
case "proxy":
|
||||
getProxy.run();
|
||||
break;
|
||||
case "h":
|
||||
case "host":
|
||||
getHost.run();
|
||||
break;
|
||||
case "g":
|
||||
case "group":
|
||||
getGroup.run();
|
||||
break;
|
||||
case "s":
|
||||
case "server":
|
||||
case "subserver":
|
||||
getServer.run();
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage("SubServers > There is no object type with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getGroup = () -> host.api.getGroup(name, group -> {
|
||||
if (group != null) {
|
||||
sender.sendMessage("SubServers > Info on Group: " + TextColor.WHITE + name);
|
||||
sender.sendMessage(" -> Servers: " + ((group.size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + group.size()));
|
||||
for (Server server : group) sender.sendMessage(" - " + TextColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ("+server.getName()+')'));
|
||||
} else {
|
||||
if (type == null) {
|
||||
getServer.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no group with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getHost = () -> host.api.getHost(name, host -> {
|
||||
if (host != null) {
|
||||
sender.sendMessage("SubServers > Info on Host: " + TextColor.WHITE + host.getDisplayName());
|
||||
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + host.getName());
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + TextColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData().length > 0) sender.sendMessage(" -> Connected: " + ((host.getSubData()[0] != null)?TextColor.GREEN+"yes"+((host.getSubData().length > 1)?TextColor.AQUA+" +"+(host.getSubData().length-1)+" subchannel"+((host.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?TextColor.WHITE:TextColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) sender.sendMessage(" - " + ((template.isEnabled())?TextColor.WHITE:TextColor.GRAY) + template.getDisplayName() + ((template.getName().equals(template.getDisplayName()))?"":" ("+template.getName()+')'));
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + host.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
getGroup.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no host with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
Runnable getProxy = () -> host.api.getProxy(name, proxy -> {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage("SubServers > Info on Proxy: " + TextColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?TextColor.GREEN+"yes"+((proxy.getSubData().length > 1)?TextColor.AQUA+" +"+(proxy.getSubData().length-1)+" subchannel"+((proxy.getSubData().length == 2)?"":"s"):""):TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?TextColor.GREEN:TextColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + TextColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + TextColor.AQUA + proxy.getSignature());
|
||||
} else {
|
||||
if (type == null) {
|
||||
getHost.run();
|
||||
} else {
|
||||
sender.sendMessage("SubServers > There is no proxy with that name");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (type == null) {
|
||||
getProxy.run();
|
||||
} else {
|
||||
switch (type.toLowerCase()) {
|
||||
case "p":
|
||||
case "proxy":
|
||||
getProxy.run();
|
||||
break;
|
||||
case "h":
|
||||
case "host":
|
||||
getHost.run();
|
||||
break;
|
||||
case "g":
|
||||
case "group":
|
||||
getGroup.run();
|
||||
break;
|
||||
case "s":
|
||||
case "server":
|
||||
case "subserver":
|
||||
getServer.run();
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage("SubServers > There is no object type with that name");
|
||||
}
|
||||
sender.sendMessage("SubServers > Usage: /" + handle + " [proxy|host|group|server] <Name>");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Usage: /" + handle + " [proxy|host|group|server] <Name>");
|
||||
}
|
||||
}
|
||||
}.autocomplete((sender, handle, args) -> {
|
||||
@ -434,38 +446,40 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer's Host is not available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That SubServer is not enabled");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("That SubServer is already running");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer's Host is not available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That SubServer is not enabled");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("That SubServer is already running");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete(defaultCompletor = (sender, handle, args) -> {
|
||||
@ -498,72 +512,74 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
TimerTask starter = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage("Could not restart server: That SubServer has disappeared");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("Could not restart server: That SubServer's Host is no longer available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("Could not restart server: That SubServer's Host is no longer enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 8:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> json) {
|
||||
try {
|
||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(args[0])) {
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", this);
|
||||
} else {
|
||||
new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Server_Restart_Command_Handler(" + args[0] + ')').schedule(starter, 100);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
if (data.getInt(0x0001) != 0) listening.set(false);
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
starter.run();
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
TimerTask starter = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[0], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
sender.sendMessage("Could not restart server: That SubServer has disappeared");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("Could not restart server: That SubServer's Host is no longer available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("Could not restart server: That SubServer's Host is no longer enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 8:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(ObjectMap<String> json) {
|
||||
try {
|
||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(args[0])) {
|
||||
PacketInExRunEvent.callback("SubStoppedEvent", this);
|
||||
} else {
|
||||
new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Server_Restart_Command_Handler(" + args[0] + ')').schedule(starter, 100);
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
if (data.getInt(0x0001) != 0) listening.set(false);
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
starter.run();
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete(defaultCompletor).usage("<SubServer>").description("Restarts a SubServer").help(
|
||||
@ -580,26 +596,28 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], false, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was stopped successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete(defaultCompletor).usage("<SubServer>").description("Stops a SubServer").help(
|
||||
@ -616,26 +634,28 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was terminated successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(null, args[0], true, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was terminated successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete(defaultCompletor).usage("<SubServer>").description("Terminates a SubServer").help(
|
||||
@ -652,35 +672,37 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 1) {
|
||||
int i = 1;
|
||||
String str = args[1];
|
||||
if (args.length > 2) {
|
||||
do {
|
||||
i++;
|
||||
str = str + " " + args[i];
|
||||
} while ((i + 1) != args.length);
|
||||
}
|
||||
final String cmd = str;
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(null, args[0], cmd, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Command was sent successfully");
|
||||
break;
|
||||
if (canRun()) {
|
||||
if (args.length > 1) {
|
||||
int i = 1;
|
||||
String str = args[1];
|
||||
if (args.length > 2) {
|
||||
do {
|
||||
i++;
|
||||
str = str + " " + args[i];
|
||||
} while ((i + 1) != args.length);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer> <Command> [Args...]");
|
||||
final String cmd = str;
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(null, args[0], cmd, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer is not running");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Command was sent successfully");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer> <Command> [Args...]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete(defaultCompletor).usage("<SubServer>", "<Command>", "[Args...]").description("Sends a Command to a SubServer").help(
|
||||
@ -699,47 +721,49 @@ public class SubCommand {
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
if (canRun()) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
} else {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("Server names cannot use spaces");
|
||||
case 4:
|
||||
sender.sendMessage("There is already a SubServer with that name");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("There is no host with that name");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("That Host is not available");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That Host is not enabled");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("There is no template with that name");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That Template is not enabled");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("That Template requires a Minecraft Version to be specified");
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Launching SubCreator...");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("Server names cannot use spaces");
|
||||
case 4:
|
||||
sender.sendMessage("There is already a SubServer with that name");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("There is no host with that name");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("That Host is not available");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That Host is not enabled");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("There is no template with that name");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That Template is not enabled");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("That Template requires a Minecraft Version to be specified");
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Launching SubCreator...");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
sender.sendMessage("Usage: /" + handle + " <Name> <Host> <Template> [Version] [Port]");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <Name> <Host> <Template> [Version] [Port]");
|
||||
}
|
||||
}
|
||||
}.autocomplete((sender, handle, args) -> {
|
||||
@ -798,34 +822,36 @@ public class SubCommand {
|
||||
}
|
||||
|
||||
private static void updateCache() {
|
||||
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(1)) {
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
SubAPI.getInstance().getProxies(proxies -> {
|
||||
proxyCache = new LinkedList<String>(proxies.keySet());
|
||||
if (canRun()) {
|
||||
if (Calendar.getInstance().getTime().getTime() - cacheDate >= TimeUnit.MINUTES.toMillis(1)) {
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().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(host.getCreator().getTemplates().keySet());
|
||||
cache.put(host.getName().toLowerCase(), templates);
|
||||
}
|
||||
hostCache = cache;
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().getGroups(groups -> {
|
||||
groupCache = new LinkedList<String>(groups.keySet());
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().getServers(servers -> {
|
||||
TreeMap<String, Boolean> cache = new TreeMap<String, Boolean>();
|
||||
for (Server server : servers.values()) {
|
||||
cache.put(server.getName(), server instanceof SubServer);
|
||||
}
|
||||
serverCache = cache;
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().getProxies(proxies -> {
|
||||
proxyCache = new LinkedList<String>(proxies.keySet());
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().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(host.getCreator().getTemplates().keySet());
|
||||
cache.put(host.getName().toLowerCase(), templates);
|
||||
}
|
||||
hostCache = cache;
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().getGroups(groups -> {
|
||||
groupCache = new LinkedList<String>(groups.keySet());
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
SubAPI.getInstance().getServers(servers -> {
|
||||
TreeMap<String, Boolean> cache = new TreeMap<String, Boolean>();
|
||||
for (Server server : servers.values()) {
|
||||
cache.put(server.getName(), server instanceof SubServer);
|
||||
}
|
||||
serverCache = cache;
|
||||
cacheDate = Calendar.getInstance().getTime().getTime();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,9 +28,15 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.8.16</version>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w20b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w20g</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
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.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -15,7 +15,7 @@ import java.util.UUID;
|
||||
public class SubEditServerEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private String server;
|
||||
private NamedContainer<String, YAMLValue> edit;
|
||||
private NamedContainer<String, ObjectMapValue<String>> edit;
|
||||
private boolean perm;
|
||||
|
||||
/**
|
||||
@ -28,11 +28,11 @@ public class SubEditServerEvent extends Event implements SubEvent {
|
||||
*/
|
||||
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
|
||||
if (Util.isNull(server, edit)) throw new NullPointerException();
|
||||
YAMLSection section = new YAMLSection();
|
||||
ObjectMap<String> section = new ObjectMap<String>();
|
||||
section.set(".", edit.get());
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.edit = new NamedContainer<String, YAMLValue>(edit.name(), section.get("."));
|
||||
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.get("."));
|
||||
this.perm = permanent;
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class SubEditServerEvent extends Event implements SubEvent {
|
||||
*
|
||||
* @return Edit to be made
|
||||
*/
|
||||
public NamedContainer<String, YAMLValue> getEdit() {
|
||||
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,42 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public class SubNetworkDisconnectEvent extends Event implements SubEvent {}
|
||||
public class SubNetworkDisconnectEvent extends Event implements SubEvent {
|
||||
private DataClient network;
|
||||
private DisconnectReason reason;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public SubNetworkDisconnectEvent(DataClient network, DisconnectReason reason) {
|
||||
if (Util.isNull(network, reason)) throw new NullPointerException();
|
||||
this.network = network;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SubData network
|
||||
*
|
||||
* @return SubData Network
|
||||
*/
|
||||
public DataClient getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reason the client disconnected
|
||||
*
|
||||
* @return Disconnect Reason
|
||||
*/
|
||||
public DisconnectReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.ME1312.SubServers.Sync;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Container;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.VersionType;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Version.VersionType;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.Security;
|
||||
|
@ -1,13 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
/**
|
||||
* Callback Class
|
||||
*/
|
||||
public interface Callback<T> {
|
||||
/**
|
||||
* Run the Callback
|
||||
*
|
||||
* @param obj Object
|
||||
*/
|
||||
void run(T obj);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Compatibility;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
@ -1,110 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Config;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* YAML Config Class
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class YAMLConfig {
|
||||
private File file;
|
||||
private Yaml yaml;
|
||||
private YAMLSection config;
|
||||
|
||||
/**
|
||||
* Creates/Loads a YAML Formatted Config
|
||||
*
|
||||
* @param file
|
||||
* @throws IOException
|
||||
* @throws YAMLException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLConfig(File file) throws IOException, YAMLException {
|
||||
if (Util.isNull(file)) throw new NullPointerException();
|
||||
this.file = file;
|
||||
this.yaml = new Yaml(getDumperOptions());
|
||||
if (file.exists()) {
|
||||
InputStream stream = new FileInputStream(file);
|
||||
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
|
||||
stream.close();
|
||||
} else {
|
||||
this.config = new YAMLSection(null, null, null, yaml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Config Contents
|
||||
*
|
||||
* @return Config Contents
|
||||
*/
|
||||
public YAMLSection get() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Config Contents
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void set(YAMLSection value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
config = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload Config Contents
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void reload() throws IOException {
|
||||
if (file.exists()) {
|
||||
InputStream stream = new FileInputStream(file);
|
||||
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
|
||||
stream.close();
|
||||
} else {
|
||||
this.config = new YAMLSection(null, null, null, yaml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Config Contents
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
if (!file.exists()) file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
yaml.dump(config.map, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof YAMLConfig) {
|
||||
return get().equals(((YAMLConfig) object).get());
|
||||
} else {
|
||||
return super.equals(object);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return yaml.dump(config.map);
|
||||
}
|
||||
|
||||
protected static DumperOptions getDumperOptions() {
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setAllowUnicode(false);
|
||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
options.setIndent(2);
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,400 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Config;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* YAML Value Class
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public class YAMLValue {
|
||||
protected Object obj;
|
||||
protected String label;
|
||||
protected YAMLSection up;
|
||||
private Yaml yaml;
|
||||
|
||||
protected YAMLValue(Object obj, YAMLSection up, String label, Yaml yaml) {
|
||||
this.obj = obj;
|
||||
this.label = label;
|
||||
this.yaml = yaml;
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the YAML Section this Object was defined in
|
||||
*
|
||||
* @return YAML Section
|
||||
*/
|
||||
public YAMLSection getDefiningSection() {
|
||||
return up;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object
|
||||
*
|
||||
* @return Object
|
||||
*/
|
||||
public Object asObject() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as List
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<?> asObjectList() {
|
||||
return (List<?>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Boolean
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public Boolean asBoolean() {
|
||||
return (Boolean) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as List
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<Boolean> asBooleanList() {
|
||||
return (List<Boolean>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as YAML Section
|
||||
*
|
||||
* @return YAML Section
|
||||
*/
|
||||
public YAMLSection asSection() {
|
||||
if (obj != null) return new YAMLSection((Map<String, ?>) obj, up, label, yaml);
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as YAML Section List
|
||||
*
|
||||
* @return YAML Section List
|
||||
*/
|
||||
public List<YAMLSection> asSectionList() {
|
||||
if (obj != null) {
|
||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
||||
for (Map<String, ?> value : (List<? extends Map<String, ?>>) obj) {
|
||||
values.add(new YAMLSection(value, null, null, yaml));
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Double
|
||||
*
|
||||
* @return Double
|
||||
*/
|
||||
public Double asDouble() {
|
||||
return ((Number) obj).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Double List
|
||||
*
|
||||
* @return Double List
|
||||
*/
|
||||
public List<Double> asDoubleList() {
|
||||
return (List<Double>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Float
|
||||
*
|
||||
* @return Float
|
||||
*/
|
||||
public Float asFloat() {
|
||||
return ((Number) obj).floatValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Float List
|
||||
*
|
||||
* @return Float List
|
||||
*/
|
||||
public List<Float> asFloatList() {
|
||||
return (List<Float>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Integer
|
||||
*
|
||||
* @return Integer
|
||||
*/
|
||||
public Integer asInt() {
|
||||
return ((Number) obj).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Integer List
|
||||
*
|
||||
* @return Integer List
|
||||
*/
|
||||
public List<Integer> asIntList() {
|
||||
return (List<Integer>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Long
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
public Long asLong() {
|
||||
return ((Number) obj).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Long List
|
||||
*
|
||||
* @return Long List
|
||||
*/
|
||||
public List<Long> asLongList() {
|
||||
return (List<Long>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Short by Handle
|
||||
*
|
||||
* @return Short
|
||||
*/
|
||||
public Short asShort() {
|
||||
return ((Number) obj).shortValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Short List by Handle
|
||||
*
|
||||
* @return Short List
|
||||
*/
|
||||
public List<Short> asShortList() {
|
||||
return (List<Short>) obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Unparsed String
|
||||
*
|
||||
* @return Unparsed String
|
||||
*/
|
||||
public String asRawString() {
|
||||
if (obj != null) return obj.toString();
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Unparsed String List
|
||||
*
|
||||
* @return Unparsed String List
|
||||
*/
|
||||
public List<String> asRawStringList() {
|
||||
if (obj != null) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (Object value : (List<?>) obj) {
|
||||
values.add(value.toString());
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as String
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String asString() {
|
||||
if (obj != null) return Util.unescapeJavaString(asRawString());
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as String List
|
||||
*
|
||||
* @return String List
|
||||
*/
|
||||
public List<String> asStringList() {
|
||||
if (obj != null) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : asRawStringList()) {
|
||||
values.add(Util.unescapeJavaString(value));
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Colored String
|
||||
*
|
||||
* @param color Color Char to parse
|
||||
* @return Colored String
|
||||
*/
|
||||
public String asColoredString(char color) {
|
||||
if (Util.isNull(color)) throw new NullPointerException();
|
||||
if (obj != null) return ChatColor.translateAlternateColorCodes(color, asString());
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Colored String List
|
||||
*
|
||||
* @param color Color Char to parse
|
||||
* @return Colored String List
|
||||
*/
|
||||
public List<String> asColoredStringList(char color) {
|
||||
if (obj != null) {
|
||||
if (Util.isNull(color)) throw new NullPointerException();
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String value : asStringList()) {
|
||||
values.add(ChatColor.translateAlternateColorCodes(color, value));
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as UUID
|
||||
*
|
||||
* @return UUID
|
||||
*/
|
||||
public UUID asUUID() {
|
||||
if (obj != null) return UUID.fromString(asRawString());
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as UUID List
|
||||
*
|
||||
* @return UUID List
|
||||
*/
|
||||
public List<UUID> asUUIDList() {
|
||||
if (obj != null) {
|
||||
List<UUID> values = new ArrayList<UUID>();
|
||||
for (String value : (List<String>) obj) {
|
||||
values.add(UUID.fromString(value));
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Version
|
||||
*
|
||||
* @return Version
|
||||
*/
|
||||
public Version asVersion() {
|
||||
if (obj != null) return Version.fromString(asRawString());
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Object as Version List
|
||||
*
|
||||
* @return Version List
|
||||
*/
|
||||
public List<Version> asVersionList() {
|
||||
if (obj != null) {
|
||||
List<Version> values = new ArrayList<Version>();
|
||||
for (String value : (List<String>) obj) {
|
||||
values.add(Version.fromString(value));
|
||||
}
|
||||
return values;
|
||||
} else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is Null
|
||||
*
|
||||
* @return Null Status
|
||||
*/
|
||||
public boolean isNull() {
|
||||
return obj == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a Boolean
|
||||
*
|
||||
* @return Boolean Status
|
||||
*/
|
||||
public boolean isBoolean() {
|
||||
return (obj instanceof Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a YAML Section
|
||||
*
|
||||
* @return YAML Section Status
|
||||
*/
|
||||
public boolean isSection() {
|
||||
return (obj instanceof Map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a List
|
||||
*
|
||||
* @return List Status
|
||||
*/
|
||||
public boolean isList() {
|
||||
return (obj instanceof List);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a Number
|
||||
*
|
||||
* @return Number Status
|
||||
*/
|
||||
public boolean isNumber() {
|
||||
return (obj instanceof Number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a String
|
||||
*
|
||||
* @return String Status
|
||||
*/
|
||||
public boolean isString() {
|
||||
return (obj instanceof String);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is a UUID
|
||||
*
|
||||
* @return UUID Status
|
||||
*/
|
||||
public boolean isUUID() {
|
||||
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (obj == null) {
|
||||
return object == null;
|
||||
} else {
|
||||
if (object instanceof YAMLValue) {
|
||||
return obj.equals(((YAMLValue) object).obj);
|
||||
} else {
|
||||
return obj.equals(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (obj != null) return obj.toString();
|
||||
else return "null";
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
/**
|
||||
* Container Class
|
||||
*
|
||||
* @param <V> Item
|
||||
*/
|
||||
public class Container<V> {
|
||||
private V obj;
|
||||
|
||||
/**
|
||||
* Creates a Container
|
||||
*
|
||||
* @param item Object to Store
|
||||
*/
|
||||
public Container(V item) {
|
||||
obj = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Object
|
||||
*
|
||||
* @return The Object
|
||||
*/
|
||||
public V get() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite the Object
|
||||
*
|
||||
* @param value Object to Store
|
||||
*/
|
||||
public void set(V value) {
|
||||
obj = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof Container) {
|
||||
if (obj == null || ((Container) object).get() == null) {
|
||||
return obj == ((Container) object).get();
|
||||
} else {
|
||||
return obj.equals(((Container) object).get());
|
||||
}
|
||||
} else {
|
||||
return super.equals(object);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Exception;
|
||||
|
||||
/**
|
||||
* Illegal Packet Exception
|
||||
*/
|
||||
public class IllegalPacketException extends IllegalStateException {
|
||||
public IllegalPacketException() {}
|
||||
public IllegalPacketException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLValue;
|
||||
|
||||
/**
|
||||
* Extra Data Handler Layout Class
|
||||
*/
|
||||
public interface ExtraDataHandler {
|
||||
/**
|
||||
* Add an extra value to this Object
|
||||
*
|
||||
* @param handle Handle
|
||||
* @param value Value
|
||||
*/
|
||||
void addExtra(String handle, Object value);
|
||||
|
||||
/**
|
||||
* Determine if an extra value exists
|
||||
*
|
||||
* @param handle Handle
|
||||
* @return Value Status
|
||||
*/
|
||||
boolean hasExtra(String handle);
|
||||
|
||||
/**
|
||||
* Get an extra value
|
||||
*
|
||||
* @param handle Handle
|
||||
* @return Value
|
||||
*/
|
||||
YAMLValue getExtra(String handle);
|
||||
|
||||
/**
|
||||
* Get the extra value section
|
||||
*
|
||||
* @return Extra Value Section
|
||||
*/
|
||||
YAMLSection getExtra();
|
||||
|
||||
/**
|
||||
* Remove an extra value from this Object
|
||||
*
|
||||
* @param handle Handle
|
||||
*/
|
||||
void removeExtra(String handle);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Fallback;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
@ -78,7 +78,7 @@ public class SmartReconnectHandler implements ReconnectHandler {
|
||||
if (server instanceof ServerContainer) {
|
||||
if (!((ServerContainer) server).isHidden()) confidence++;
|
||||
if (!((ServerContainer) server).isRestricted()) confidence++;
|
||||
if (((ServerContainer) server).getSubData() != null) confidence++;
|
||||
if (((ServerContainer) server).getSubData()[0] != null) confidence++;
|
||||
} if (server instanceof SubServerContainer) {
|
||||
if (!((SubServerContainer) server).isRunning()) valid = false;
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
/**
|
||||
* Named Container Class
|
||||
* @param <T> Name
|
||||
* @param <V> Item
|
||||
*/
|
||||
public class NamedContainer<T, V> extends Container<V> {
|
||||
private T name;
|
||||
|
||||
/**
|
||||
* Creates a TaggedContainer
|
||||
*
|
||||
* @param name Tag to Bind
|
||||
* @param item Object to Store
|
||||
*/
|
||||
public NamedContainer(T name, V item) {
|
||||
super(item);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the Container
|
||||
*
|
||||
* @return Container name
|
||||
*/
|
||||
public T name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the Container
|
||||
*
|
||||
* @param name New Container Name
|
||||
*/
|
||||
public void rename(T name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof NamedContainer) {
|
||||
if (name == null || ((NamedContainer) object).name() == null) {
|
||||
return name == ((NamedContainer) object).name() && super.equals(object);
|
||||
} else {
|
||||
return name.equals(((NamedContainer) object).name()) && super.equals(object);
|
||||
}
|
||||
} else {
|
||||
return super.equals(object);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Universal File Class
|
||||
*/
|
||||
public class UniversalFile extends File {
|
||||
|
||||
/**
|
||||
* Creates a File Link. Path names are separated by ':'
|
||||
*
|
||||
* @param pathname Path name
|
||||
*/
|
||||
public UniversalFile(String pathname) {
|
||||
super(pathname.replace(".:", System.getProperty("user.dir") + ":").replace(':', File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File Link. Path names are separated by the divider
|
||||
*
|
||||
* @param pathname Path name
|
||||
* @param divider Divider to use
|
||||
*/
|
||||
public UniversalFile(String pathname, char divider) {
|
||||
super(pathname.replace("." + divider, System.getProperty("user.dir") + divider).replace(divider, File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File Link.
|
||||
*
|
||||
* @see File
|
||||
* @param file File
|
||||
*/
|
||||
public UniversalFile(File file) {
|
||||
super(file.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File. Path names are separated by the ':'
|
||||
*
|
||||
* @see File
|
||||
* @param parent Parent File
|
||||
* @param child Path name
|
||||
*/
|
||||
public UniversalFile(File parent, String child) {
|
||||
super(parent, child.replace(':', File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a File. Path names are separated by the divider
|
||||
*
|
||||
* @see File
|
||||
* @param parent Parent File
|
||||
* @param child Path name
|
||||
* @param divider Divider to use
|
||||
*/
|
||||
public UniversalFile(File parent, String child, char divider) {
|
||||
super(parent, child.replace(divider, File.separatorChar));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Universal File Path (separated by ':')
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUniversalPath() {
|
||||
return getPath().replace(File.separatorChar, ':');
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Updates;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* SubServers Configuration Updater
|
||||
*/
|
||||
public class ConfigUpdater {
|
||||
private static final Version UNSIGNED = new Version(new SimpleDateFormat("yy'w'ww'zz'").format(Calendar.getInstance().getTime()));
|
||||
|
||||
/**
|
||||
* Update SubServers' config.yml
|
||||
*
|
||||
* @param file File to bring up-to-date
|
||||
*/
|
||||
public static void updateConfig(File file) throws IOException {
|
||||
YAMLConfig config = new YAMLConfig(file);
|
||||
YAMLSection existing = config.get().clone();
|
||||
YAMLSection updated = existing.clone();
|
||||
YAMLSection rewritten = new YAMLSection();
|
||||
|
||||
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
|
||||
Version now = SubAPI.getInstance().getWrapperBuild();
|
||||
|
||||
int i = 0;
|
||||
if (now == null) now = UNSIGNED;
|
||||
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
|
||||
|
||||
i++;
|
||||
System.out.println("SubServers > Created ./SubServers/sync.yml");
|
||||
} else {
|
||||
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
// i++
|
||||
//}
|
||||
|
||||
if (i > 0) System.out.println("SubServers > Updated ./SubServers/sync.yml (" + i + " pass" + ((i != 1)?"es":"") + ")");
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Smart-Fallback", updated.getMap("Settings", new YAMLSection()).getBoolean("Smart-Fallback", true));
|
||||
settings.set("Override-Bungee-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Override-Bungee-Commands", true));
|
||||
|
||||
YAMLSection upnp = new YAMLSection();
|
||||
upnp.set("Forward-Proxy", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true));
|
||||
settings.set("UPnP", upnp);
|
||||
|
||||
YAMLSection subdata = new YAMLSection();
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Name")) subdata.set("Name", updated.getMap("Settings").getMap("SubData").getRawString("Name"));
|
||||
subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Address", "127.0.0.1:4391"));
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password")) subdata.set("Password", updated.getMap("Settings").getMap("SubData").getRawString("Password"));
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Reconnect")) subdata.set("Reconnect", updated.getMap("Settings").getMap("SubData").getInt("Reconnect"));
|
||||
settings.set("SubData", subdata);
|
||||
|
||||
rewritten.set("Settings", settings);
|
||||
|
||||
|
||||
YAMLSection sync = new YAMLSection();
|
||||
settings.set("Disabled-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Disabled-Commands", false));
|
||||
settings.set("Forced-Hosts", updated.getMap("Settings", new YAMLSection()).getBoolean("Forced-Hosts", true));
|
||||
settings.set("Motd", updated.getMap("Settings", new YAMLSection()).getBoolean("Motd", false));
|
||||
settings.set("Player-Limit", updated.getMap("Settings", new YAMLSection()).getBoolean("Player-Limit", false));
|
||||
settings.set("Server-Priorities", updated.getMap("Settings", new YAMLSection()).getBoolean("Server-Priorities", true));
|
||||
|
||||
rewritten.set("Sync", sync);
|
||||
|
||||
config.set(rewritten);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,398 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* SubServers Utility Class
|
||||
*/
|
||||
public final class Util {
|
||||
private Util(){}
|
||||
public interface ExceptionReturnRunnable<R> {
|
||||
R run() throws Throwable;
|
||||
}
|
||||
public interface ExceptionRunnable<R> {
|
||||
void run() throws Throwable;
|
||||
}
|
||||
public interface ReturnRunnable<R> {
|
||||
R run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks values to make sure they're not null
|
||||
*
|
||||
* @param values Values to check
|
||||
* @return If any are null
|
||||
*/
|
||||
public static boolean isNull(Object... values) {
|
||||
boolean ret = false;
|
||||
for (Object value : values) {
|
||||
if (value == null) ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get keys by value from map
|
||||
*
|
||||
* @param map Map to search
|
||||
* @param value Value to search for
|
||||
* @param <K> Key
|
||||
* @param <V> Value
|
||||
* @return Search results
|
||||
*/
|
||||
public static <K, V> List<K> getBackwards(Map<K, V> map, V value) {
|
||||
List<K> values = new ArrayList<K>();
|
||||
|
||||
for (K key : map.keySet()) {
|
||||
if (map.get(key).equals(value)) {
|
||||
values.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from a map ignoring case
|
||||
*
|
||||
* @param map Map to search
|
||||
* @param key Key to search with
|
||||
* @param <V> Value
|
||||
* @return Search Result
|
||||
*/
|
||||
public static <V> V getCaseInsensitively(Map<String, V> map, String key) {
|
||||
HashMap<String, String> insensitivity = new HashMap<String, String>();
|
||||
for (String item : map.keySet()) insensitivity.put(item.toLowerCase(), item);
|
||||
if (insensitivity.keySet().contains(key.toLowerCase())) {
|
||||
return map.get(insensitivity.get(key.toLowerCase()));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new Variable that doesn't match the existing Variables
|
||||
*
|
||||
* @param existing Existing Variables
|
||||
* @param generator Variable Generator
|
||||
* @param <V> Variable Type
|
||||
* @return Variable
|
||||
*/
|
||||
public static <V> V getNew(Collection<? extends V> existing, ReturnRunnable<V> generator) {
|
||||
V result = null;
|
||||
while (result == null) {
|
||||
V tmp = generator.run();
|
||||
if (!existing.contains(tmp)) result = tmp;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Everything from Reader
|
||||
*
|
||||
* @param rd Reader
|
||||
* @return Reader Contents
|
||||
* @throws IOException
|
||||
*/
|
||||
public static String readAll(Reader rd) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int cp;
|
||||
while ((cp = rd.read()) != -1) {
|
||||
sb.append((char) cp);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy from the Class Loader
|
||||
*
|
||||
* @param loader ClassLoader
|
||||
* @param resource Location From
|
||||
* @param destination Location To
|
||||
*/
|
||||
public static void copyFromJar(ClassLoader loader, String resource, String destination) {
|
||||
InputStream resStreamIn = loader.getResourceAsStream(resource);
|
||||
File resDestFile = new File(destination);
|
||||
try {
|
||||
OutputStream resStreamOut = new FileOutputStream(resDestFile);
|
||||
int readBytes;
|
||||
byte[] buffer = new byte[4096];
|
||||
while ((readBytes = resStreamIn.read(buffer)) > 0) {
|
||||
resStreamOut.write(buffer, 0, readBytes);
|
||||
}
|
||||
resStreamOut.close();
|
||||
resStreamIn.close();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Field's value using Reflection
|
||||
*
|
||||
* @param field Field to grab
|
||||
* @param instance Object Instance (Null for static fields)
|
||||
* @param <R> Return Type
|
||||
* @return Field Value
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <R> R reflect(Field field, Object instance) throws IllegalAccessException {
|
||||
R value;
|
||||
field.setAccessible(true);
|
||||
value = (R) field.get(instance);
|
||||
field.setAccessible(false);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a Field's value using Reflection
|
||||
*
|
||||
* @param field Field to write to
|
||||
* @param instance Object Instance (Null for static fields)
|
||||
* @param value Value to write
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
public static void reflect(Field field, Object instance, Object value) throws IllegalAccessException {
|
||||
field.setAccessible(true);
|
||||
field.set(instance, value);
|
||||
field.setAccessible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a method using Reflection
|
||||
*
|
||||
* @param method Method to call
|
||||
* @param instance Object Instance (Null for static methods)
|
||||
* @param arguments Method Arguments
|
||||
* @param <R> Return Type
|
||||
* @return Returned Value
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <R> R reflect(Method method, Object instance, Object... arguments) throws InvocationTargetException, IllegalAccessException {
|
||||
R value;
|
||||
method.setAccessible(true);
|
||||
value = (R) method.invoke(instance, arguments);
|
||||
method.setAccessible(false);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an object using Reflection
|
||||
*
|
||||
* @param constructor Constructor to use
|
||||
* @param arguments Constructor Arguments
|
||||
* @param <R> Return Type
|
||||
* @return New Instance
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <R> R reflect(Constructor<?> constructor, Object... arguments) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
R value;
|
||||
constructor.setAccessible(true);
|
||||
value = (R) constructor.newInstance(arguments);
|
||||
constructor.setAccessible(false);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a variable from a method which may throw an exception
|
||||
*
|
||||
* @param runnable Runnable
|
||||
* @param def Default value when an exception is thrown
|
||||
* @param <R> Variable Type
|
||||
* @return Returns value or default depending on if an exception is thrown
|
||||
*/
|
||||
public static <R> R getDespiteException(ExceptionReturnRunnable<R> runnable, R def) {
|
||||
try {
|
||||
return runnable.run();
|
||||
} catch (Throwable e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an Exception will occur
|
||||
*
|
||||
* @param runnable Runnable
|
||||
* @return If an Exception occured
|
||||
*/
|
||||
public static boolean isException(ExceptionRunnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
return false;
|
||||
} catch (Throwable e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Directory
|
||||
*
|
||||
* @param folder Location
|
||||
*/
|
||||
public static void deleteDirectory(File folder) {
|
||||
File[] files = folder.listFiles();
|
||||
if(files!=null) {
|
||||
for(File f : files) {
|
||||
if(f.isDirectory() && !Files.isSymbolicLink(f.toPath())) {
|
||||
deleteDirectory(f);
|
||||
} else try {
|
||||
Files.delete(f.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
folder.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a Directory
|
||||
*
|
||||
* @param from Source
|
||||
* @param to Destination
|
||||
*/
|
||||
public static void copyDirectory(File from, File to) {
|
||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
||||
if (!to.exists()) {
|
||||
to.mkdirs();
|
||||
}
|
||||
|
||||
for (String file : from.list()) {
|
||||
File srcFile = new File(from, file);
|
||||
File destFile = new File(to, file);
|
||||
|
||||
copyDirectory(srcFile, destFile);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Random Integer
|
||||
*
|
||||
* @param min Minimum Value
|
||||
* @param max Maximum Value
|
||||
* @return Random Integer
|
||||
*/
|
||||
public static int random(int min, int max) {
|
||||
return new Random().nextInt((max - min) + 1) + min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse escapes in a Java String
|
||||
*
|
||||
* @param str String
|
||||
* @return Unescaped String
|
||||
*/
|
||||
public static String unescapeJavaString(String str) {
|
||||
StringBuilder sb = new StringBuilder(str.length());
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
int ch = str.codePointAt(i);
|
||||
if (ch == '\\') {
|
||||
int nextChar = (i == str.length() - 1) ? '\\' : str
|
||||
.codePointAt(i + 1);
|
||||
// Octal escape?
|
||||
if (nextChar >= '0' && nextChar <= '7') {
|
||||
StringBuilder code = new StringBuilder();
|
||||
code.appendCodePoint(nextChar);
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
|
||||
&& str.codePointAt(i + 1) <= '7') {
|
||||
code.appendCodePoint(str.codePointAt(i + 1));
|
||||
i++;
|
||||
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
|
||||
&& str.codePointAt(i + 1) <= '7') {
|
||||
code.appendCodePoint(str.codePointAt(i + 1));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sb.append((char) Integer.parseInt(code.toString(), 8));
|
||||
continue;
|
||||
}
|
||||
switch (nextChar) {
|
||||
case '\\':
|
||||
ch = '\\';
|
||||
break;
|
||||
case 'b':
|
||||
ch = '\b';
|
||||
break;
|
||||
case 'f':
|
||||
ch = '\f';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
case '\"':
|
||||
ch = '\"';
|
||||
break;
|
||||
case '\'':
|
||||
ch = '\'';
|
||||
break;
|
||||
// Hex Unicode Char: u????
|
||||
// Hex Unicode Codepoint: u{??????}
|
||||
case 'u':
|
||||
try {
|
||||
if (i >= str.length() - 4) throw new IllegalStateException();
|
||||
StringBuilder escape = new StringBuilder();
|
||||
int offset = 2;
|
||||
|
||||
if (str.codePointAt(i + 2) != '{') {
|
||||
if (i >= str.length() - 5) throw new IllegalStateException();
|
||||
while (offset <= 5) {
|
||||
Integer.toString(str.codePointAt(i + offset), 16);
|
||||
escape.appendCodePoint(str.codePointAt(i + offset));
|
||||
offset++;
|
||||
}
|
||||
offset--;
|
||||
} else {
|
||||
offset++;
|
||||
while (str.codePointAt(i + offset) != '}') {
|
||||
Integer.toString(str.codePointAt(i + offset), 16);
|
||||
escape.appendCodePoint(str.codePointAt(i + offset));
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
sb.append(new String(new int[]{
|
||||
Integer.parseInt(escape.toString(), 16)
|
||||
}, 0, 1));
|
||||
|
||||
i += offset;
|
||||
continue;
|
||||
} catch (Throwable e){
|
||||
sb.append('\\');
|
||||
ch = 'u';
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sb.appendCodePoint(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,411 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Version;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Version Class
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Version implements Serializable, Comparable<Version> {
|
||||
private final Version parent;
|
||||
private final VersionType type;
|
||||
private final String string;
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param string Version String
|
||||
*/
|
||||
public Version(String string) {
|
||||
this(VersionType.VERSION, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param type Version Type
|
||||
* @param string Version String
|
||||
*/
|
||||
public Version(VersionType type, String string) {
|
||||
this(null, type, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version (Appending the parent)
|
||||
*
|
||||
* @param parent Parent Version
|
||||
* @param string Version String
|
||||
*/
|
||||
public Version(Version parent, String string) {
|
||||
this(parent, VersionType.VERSION, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version (Appending the parent)
|
||||
*
|
||||
* @param parent Parent Version
|
||||
* @param type Version Type
|
||||
* @param string Version String
|
||||
*/
|
||||
public Version(Version parent, VersionType type, String string) {
|
||||
if (Util.isNull(string, type)) throw new NullPointerException();
|
||||
this.parent = parent;
|
||||
this.type = type;
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param ints Version Numbers (Will be separated with dots)
|
||||
*/
|
||||
public Version(int... ints) {
|
||||
this(VersionType.VERSION, ints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version
|
||||
*
|
||||
* @param type Version Type
|
||||
* @param ints Version Numbers (Will be separated with dots)
|
||||
*/
|
||||
public Version(VersionType type, int... ints) {
|
||||
this(null, type, ints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version (Appending the parent)
|
||||
*
|
||||
* @param parent Parent Version
|
||||
* @param ints Version Numbers (Will be separated with dots)
|
||||
*/
|
||||
public Version(Version parent, int... ints) {
|
||||
this(parent, VersionType.VERSION, ints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Version (Appending the parent)
|
||||
*
|
||||
* @param parent Parent Version
|
||||
* @param type Version Type
|
||||
* @param ints Version Numbers (Will be separated with dots)
|
||||
*/
|
||||
public Version(Version parent, VersionType type, int... ints) {
|
||||
if (Util.isNull(type)) throw new NullPointerException();
|
||||
this.parent = parent;
|
||||
this.type = type;
|
||||
String string = Integer.toString(ints[0]);
|
||||
int i = 0;
|
||||
if (ints.length != 1) {
|
||||
do {
|
||||
i++;
|
||||
string = string + "." + ints[i];
|
||||
} while ((i + 1) != ints.length);
|
||||
}
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a Version from a string
|
||||
*
|
||||
* @param string String to parse
|
||||
* @see #toFullString() <b>#toFullString()</b> returns a valid string
|
||||
* @see #toFullString() <b>#toString()</b> returns a valid string
|
||||
*/
|
||||
public static Version fromString(String string) {
|
||||
Matcher regex = Pattern.compile("(rv|p?[abrv]|[su])?([^/]+)", Pattern.CASE_INSENSITIVE).matcher(string);
|
||||
Version current = null;
|
||||
while (regex.find()) {
|
||||
try {
|
||||
VersionType type = VersionType.VERSION;
|
||||
if (regex.group(1) != null) switch (regex.group(1).toLowerCase()) {
|
||||
case "pa":
|
||||
type = VersionType.PRE_ALPHA;
|
||||
break;
|
||||
case "a":
|
||||
type = VersionType.ALPHA;
|
||||
break;
|
||||
case "pv":
|
||||
type = VersionType.PREVIEW;
|
||||
break;
|
||||
case "pb":
|
||||
type = VersionType.PRE_BETA;
|
||||
break;
|
||||
case "b":
|
||||
type = VersionType.BETA;
|
||||
break;
|
||||
case "s":
|
||||
type = VersionType.SNAPSHOT;
|
||||
break;
|
||||
case "pr":
|
||||
type = VersionType.PRE_RELEASE;
|
||||
break;
|
||||
case "r":
|
||||
type = VersionType.RELEASE;
|
||||
break;
|
||||
case "rv":
|
||||
type = VersionType.REVISION;
|
||||
break;
|
||||
case "u":
|
||||
type = VersionType.UPDATE;
|
||||
break;
|
||||
}
|
||||
current = new Version(current, type, regex.group(2));
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
if (current == null) throw new IllegalArgumentException("Could not find version in string: " + string);
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default toString() method<br>
|
||||
* <br>
|
||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
||||
* <b style="font-family: consolas">1.0.0/pa7</b>
|
||||
*
|
||||
* @return Version as a String
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return ((parent == null)?"":parent.toString()+'/'+type.shortname) + string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full toString() method<br>
|
||||
* <br>
|
||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
||||
* <b style="font-family: consolas">r1.0.0/pa7</b>
|
||||
*
|
||||
* @return Version as a String
|
||||
*/
|
||||
public String toFullString() {
|
||||
return ((parent == null)?"":parent.toFullString()+'/') + type.shortname + string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extended toString() method<br>
|
||||
* <br>
|
||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
||||
* <b style="font-family: consolas">1.0.0 pre-alpha 7</b>
|
||||
*
|
||||
* @return Version as a String
|
||||
*/
|
||||
public String toExtendedString() {
|
||||
return ((parent == null)?"":parent.toExtendedString()+' '+type.longname+' ') + string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full extended toString() method<br>
|
||||
* <br>
|
||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
||||
* <b style="font-family: consolas">release 1.0.0 pre-alpha 7</b>
|
||||
*
|
||||
* @return Version as a String
|
||||
*/
|
||||
public String toFullExtendedString() {
|
||||
return ((parent == null)?"":parent.toFullExtendedString()+' ') + type.longname + ' ' + string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof Version) {
|
||||
return equals((Version) object);
|
||||
} else {
|
||||
return super.equals(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See if Versions are Equal
|
||||
*
|
||||
* @param version Version to Compare to
|
||||
* @return
|
||||
*/
|
||||
public boolean equals(Version version) {
|
||||
return compareTo(version) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if Greater than
|
||||
* Returns 0 if Equal
|
||||
* Returns -1 if Less than
|
||||
*//**
|
||||
*
|
||||
* Compare Versions
|
||||
*
|
||||
* @param version Version to Compare to
|
||||
*/
|
||||
public int compareTo(Version version) {
|
||||
return compare(this, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if Versions are Equal
|
||||
*
|
||||
* @param ver1 Version to Compare
|
||||
* @param ver2 Version to Compare
|
||||
* @return
|
||||
*/
|
||||
public static boolean equals(Version ver1, Version ver2) {
|
||||
return compare(ver1, ver2) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if Greater than
|
||||
* Returns 0 if Equal
|
||||
* Returns -1 if Less than
|
||||
*//**
|
||||
* Compare Versions
|
||||
*
|
||||
* @param ver1 Version to Compare
|
||||
* @param ver2 Version to Compare
|
||||
*/
|
||||
public static int compare(Version ver1, Version ver2) {
|
||||
if (ver1 == null && ver2 == null) {
|
||||
// Both versions are null
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ver1 == null) {
|
||||
// Version one is null
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ver2 == null) {
|
||||
// Version two is null
|
||||
return 1;
|
||||
}
|
||||
|
||||
LinkedList<Version> stack1 = new LinkedList<Version>();
|
||||
stack1.add(ver1);
|
||||
while (ver1.parent != null) {
|
||||
ver1 = ver1.parent;
|
||||
stack1.add(ver1);
|
||||
}
|
||||
Collections.reverse(stack1);
|
||||
|
||||
LinkedList<Version> stack2 = new LinkedList<Version>();
|
||||
stack2.add(ver2);
|
||||
while (ver2.parent != null) {
|
||||
ver2 = ver2.parent;
|
||||
stack2.add(ver2);
|
||||
}
|
||||
Collections.reverse(stack2);
|
||||
|
||||
int id;
|
||||
for (id = 0; id < stack1.size(); id++) {
|
||||
if (id >= stack2.size()) {
|
||||
// Version one still has children when version two does not...
|
||||
if (stack1.get(id).type.stageid < 0) {
|
||||
// ...making version two the official version
|
||||
return -1;
|
||||
} else {
|
||||
// ...however the direct child of version one has a stageid higher than or equal to a release
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int result = stack1.get(id).compare(stack2.get(id));
|
||||
if (result != 0) {
|
||||
// Versions are not the same, return the result
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (id < stack2.size()) {
|
||||
// Version one does not children when version two still does...
|
||||
if (stack2.get(id).type.stageid < 0) {
|
||||
// ...making version one the official version
|
||||
return 1;
|
||||
} else {
|
||||
// ...however the direct child of version two has a stageid higher than or equal to a release
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares versions ignoring parent/child relationships
|
||||
*/
|
||||
private int compare(Version version) {
|
||||
if (this.type.stageid > version.type.stageid) {
|
||||
// Version one has a type of a later stage than version two
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (this.type.stageid < version.type.stageid) {
|
||||
// Version one has a type of an earlier stage than version two
|
||||
return -1;
|
||||
}
|
||||
|
||||
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
||||
|
||||
int number1, number2;
|
||||
String suffix1, suffix2;
|
||||
|
||||
while (tokenizer1.MoveNext()) {
|
||||
if (!tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
if (number1 != 0 || suffix1.length() != 0) {
|
||||
// Version one is longer than number two, and non-zero
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
while (tokenizer1.MoveNext());
|
||||
|
||||
// Version one is longer than version two, but zero
|
||||
return 0;
|
||||
}
|
||||
|
||||
number1 = tokenizer1.getNumber();
|
||||
suffix1 = tokenizer1.getSuffix();
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
|
||||
if (number1 < number2) {
|
||||
// Number one is less than number two
|
||||
return -1;
|
||||
}
|
||||
if (number1 > number2) {
|
||||
// Number one is greater than number two
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean empty1 = suffix1.length() == 0;
|
||||
boolean empty2 = suffix2.length() == 0;
|
||||
|
||||
if (empty1 && empty2) continue; // No suffixes
|
||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
||||
|
||||
// Lexical comparison of suffixes
|
||||
int result = suffix1.compareTo(suffix2);
|
||||
if (result != 0) return result;
|
||||
|
||||
}
|
||||
if (tokenizer2.MoveNext()) {
|
||||
do {
|
||||
number2 = tokenizer2.getNumber();
|
||||
suffix2 = tokenizer2.getSuffix();
|
||||
if (number2 != 0 || suffix2.length() != 0) {
|
||||
// Version one is longer than version two, and non-zero
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (tokenizer2.MoveNext());
|
||||
|
||||
// Version two is longer than version one, but zero
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Version;
|
||||
|
||||
final class VersionTokenizer {
|
||||
private final String _versionString;
|
||||
private final int _length;
|
||||
|
||||
private int _position;
|
||||
private int _number;
|
||||
private String _suffix;
|
||||
private boolean _hasValue;
|
||||
|
||||
protected int getNumber() {
|
||||
return _number;
|
||||
}
|
||||
|
||||
protected String getSuffix() {
|
||||
return _suffix;
|
||||
}
|
||||
|
||||
protected boolean hasValue() {
|
||||
return _hasValue;
|
||||
}
|
||||
|
||||
protected VersionTokenizer(String versionString) {
|
||||
if (versionString == null)
|
||||
throw new IllegalArgumentException("versionString is null");
|
||||
|
||||
_versionString = versionString;
|
||||
_length = versionString.length();
|
||||
}
|
||||
|
||||
protected boolean MoveNext() {
|
||||
_number = 0;
|
||||
_suffix = "";
|
||||
_hasValue = false;
|
||||
|
||||
// No more characters
|
||||
if (_position >= _length)
|
||||
return false;
|
||||
|
||||
_hasValue = true;
|
||||
|
||||
while (_position < _length) {
|
||||
char c = _versionString.charAt(_position);
|
||||
if (c < '0' || c > '9') break;
|
||||
_number = _number * 10 + (c - '0');
|
||||
_position++;
|
||||
}
|
||||
|
||||
int suffixStart = _position;
|
||||
|
||||
while (_position < _length) {
|
||||
char c = _versionString.charAt(_position);
|
||||
if (c == '.') break;
|
||||
_position++;
|
||||
}
|
||||
|
||||
_suffix = _versionString.substring(suffixStart, _position);
|
||||
|
||||
if (_position < _length) _position++;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Version;
|
||||
|
||||
public enum VersionType {
|
||||
PRE_ALPHA(-6, "pa", "pre-alpha"),
|
||||
ALPHA(-5, "a", "alpha"),
|
||||
PREVIEW(-4, "pv", "preview"),
|
||||
PRE_BETA(-4, "pb", "pre-beta"),
|
||||
BETA(-3, "b", "beta"),
|
||||
SNAPSHOT(-2, "s", "snapshot"),
|
||||
PRE_RELEASE(-1, "pr", "pre-release"),
|
||||
RELEASE(0, "r", "release"),
|
||||
REVISION(0, "rv", "revision"),
|
||||
VERSION(0, "v", "version"),
|
||||
UPDATE(0, "u", "update"),
|
||||
;
|
||||
final short stageid;
|
||||
final String shortname, longname;
|
||||
VersionType(int stageid, String shortname, String longname) {
|
||||
this.stageid = (short) stageid;
|
||||
this.shortname = shortname;
|
||||
this.longname = longname;
|
||||
}
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
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.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketAddServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDeleteServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadHostInfo;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketRemoveServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
@ -13,7 +19,7 @@ import java.util.*;
|
||||
public class Host {
|
||||
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
private SubCreator creator;
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -21,7 +27,7 @@ public class Host {
|
||||
*
|
||||
* @param raw Raw representation of the Host
|
||||
*/
|
||||
public Host(YAMLSection raw) {
|
||||
public Host(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -30,14 +36,14 @@ public class Host {
|
||||
return obj instanceof Host && getSignature().equals(((Host) obj).getSignature());
|
||||
}
|
||||
|
||||
private void load(YAMLSection raw) {
|
||||
private void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
|
||||
servers.clear();
|
||||
this.creator = new SubCreator(this, raw.getSection("creator"));
|
||||
for (String server : raw.getSection("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new SubServer(this, raw.getSection("servers").getSection(server)));
|
||||
this.creator = new SubCreator(this, raw.getMap("creator"));
|
||||
for (String server : raw.getMap("servers").getKeys()) {
|
||||
servers.put(server.toLowerCase(), new SubServer(this, raw.getMap("servers").getMap(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,16 +52,26 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client Address
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Address (or null if unlinked/unsupported)
|
||||
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
if (raw.contains("subdata")) {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
} else {
|
||||
return new UUID[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,6 +248,380 @@ public class Host {
|
||||
return getSubServers().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param player Player adding
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, enabled, getName(), port, motd, log, directory, executable, stopcmd, hidden, restricted, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a SubServer
|
||||
*
|
||||
* @param player Player adding
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @return The SubServer
|
||||
*/
|
||||
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||
addSubServer(player, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void removeSubServer(String name) throws InterruptedException {
|
||||
removeSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void removeSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRemoveSubServer(String name) throws InterruptedException {
|
||||
forceRemoveSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRemoveSubServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
removeSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a SubServer
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceRemoveSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveSubServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeSubServer(player, name, true, response);
|
||||
}
|
||||
|
||||
private void removeSubServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void recycleSubServer(String name) throws InterruptedException {
|
||||
recycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void recycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRecycleSubServer(String name) throws InterruptedException {
|
||||
forceRecycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public void forceRecycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void recycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
recycleSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void recycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRecycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceRecycleSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRecycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, true, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(String name) throws InterruptedException {
|
||||
deleteSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, false, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(String name) throws InterruptedException {
|
||||
forceDeleteSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, true, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
deleteSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void deleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||
forceDeleteSubServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public void forceDeleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
deleteSubServer(player, name, false, true, response);
|
||||
}
|
||||
|
||||
private void deleteSubServer(UUID player, String name, boolean recycle, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Signature of this Object
|
||||
*
|
||||
@ -258,7 +648,7 @@ public class Host {
|
||||
*/
|
||||
public boolean hasExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").getKeys().contains(handle);
|
||||
return raw.getMap("extra").getKeys().contains(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -267,9 +657,9 @@ public class Host {
|
||||
* @param handle Handle
|
||||
* @return Value
|
||||
*/
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue<String> getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").get(handle);
|
||||
return raw.getMap("extra").get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,8 +667,8 @@ public class Host {
|
||||
*
|
||||
* @return Extra Value Section
|
||||
*/
|
||||
public YAMLSection getExtra() {
|
||||
return raw.getSection("extra").clone();
|
||||
public ObjectMap<String> getExtra() {
|
||||
return raw.getMap("extra").clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,13 +676,7 @@ public class Host {
|
||||
*
|
||||
* @return Raw Host
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
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.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadProxyInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Proxy {
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -18,7 +19,7 @@ public class Proxy {
|
||||
*
|
||||
* @param raw Raw representation of the Proxy
|
||||
*/
|
||||
public Proxy(YAMLSection raw) {
|
||||
public Proxy(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -27,7 +28,7 @@ public class Proxy {
|
||||
return obj instanceof Proxy && getSignature().equals(((Proxy) obj).getSignature());
|
||||
}
|
||||
|
||||
private void load(YAMLSection raw) {
|
||||
private void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
}
|
||||
@ -37,16 +38,22 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,8 +90,8 @@ public class Proxy {
|
||||
*/
|
||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : raw.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : raw.getMap("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
@ -115,7 +122,7 @@ public class Proxy {
|
||||
*/
|
||||
public boolean hasExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").getKeys().contains(handle);
|
||||
return raw.getMap("extra").getKeys().contains(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,9 +131,9 @@ public class Proxy {
|
||||
* @param handle Handle
|
||||
* @return Value
|
||||
*/
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue<String> getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return raw.getSection("extra").get(handle);
|
||||
return raw.getMap("extra").get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,8 +141,8 @@ public class Proxy {
|
||||
*
|
||||
* @return Extra Value Section
|
||||
*/
|
||||
public YAMLSection getExtra() {
|
||||
return raw.getSection("extra").clone();
|
||||
public ObjectMap<String> getExtra() {
|
||||
return raw.getMap("extra").clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,13 +150,7 @@ public class Proxy {
|
||||
*
|
||||
* @return Raw Proxy
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
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.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketDownloadServerInfo;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
@ -9,7 +10,7 @@ import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class Server {
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
long timestamp;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ public class Server {
|
||||
*
|
||||
* @param raw Raw representation of the Server
|
||||
*/
|
||||
public Server(YAMLSection raw) {
|
||||
public Server(ObjectMap<String> raw) {
|
||||
load(raw);
|
||||
}
|
||||
|
||||
@ -26,7 +27,7 @@ public class Server {
|
||||
return obj instanceof Server && getSignature().equals(((Server) obj).getSignature());
|
||||
}
|
||||
|
||||
void load(YAMLSection raw) {
|
||||
void load(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||
}
|
||||
@ -36,16 +37,22 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client Address
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Address (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public String getSubData() {
|
||||
return raw.getRawString("subdata", null);
|
||||
@SuppressWarnings("unchecked")
|
||||
public UUID[] getSubData() {
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) raw.getObject("subdata"));
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.getKeys());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.getUUID(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,8 +97,8 @@ public class Server {
|
||||
*/
|
||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : raw.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : raw.getMap("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
@ -165,13 +172,7 @@ public class Server {
|
||||
*
|
||||
* @return Raw Server
|
||||
*/
|
||||
public YAMLSection getRaw() {
|
||||
public ObjectMap<String> getRaw() {
|
||||
return raw.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package net.ME1312.SubServers.Sync.Network.API;
|
||||
|
||||
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.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
@ -16,14 +17,14 @@ import java.util.UUID;
|
||||
public class SubCreator {
|
||||
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
||||
Host host;
|
||||
YAMLSection raw;
|
||||
ObjectMap<String> raw;
|
||||
|
||||
SubCreator(Host host, YAMLSection raw) {
|
||||
SubCreator(Host host, ObjectMap<String> raw) {
|
||||
this.host = host;
|
||||
this.raw = raw;
|
||||
|
||||
for (String template : raw.getSection("templates").getKeys()) {
|
||||
templates.put(template.toLowerCase(), new ServerTemplate(raw.getSection("templates").getSection(template)));
|
||||
for (String template : raw.getMap("templates").getKeys()) {
|
||||
templates.put(template.toLowerCase(), new ServerTemplate(raw.getMap("templates").getMap(template)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,10 +34,10 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
public static class ServerTemplate {
|
||||
private YAMLSection raw;
|
||||
private ObjectMap<String> raw;
|
||||
private ServerType type;
|
||||
|
||||
public ServerTemplate(YAMLSection raw) {
|
||||
public ServerTemplate(ObjectMap<String> raw) {
|
||||
this.raw = raw;
|
||||
this.type = (Util.isException(() -> ServerType.valueOf(raw.getRawString("type").toUpperCase())))? ServerType.valueOf(raw.getRawString("type").toUpperCase()): ServerType.CUSTOM;
|
||||
}
|
||||
@ -86,15 +87,13 @@ public class SubCreator {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection tinfo = new YAMLSection();
|
||||
tinfo.set("enabled", isEnabled());
|
||||
tinfo.set("name", getName());
|
||||
tinfo.set("display", getDisplayName());
|
||||
tinfo.set("icon", getIcon());
|
||||
tinfo.set("type", getType().toString());
|
||||
return tinfo.toJSON();
|
||||
/**
|
||||
* Get whether this Template requires the Version argument
|
||||
*
|
||||
* @return Version Requirement
|
||||
*/
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
@ -116,16 +115,16 @@ public class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -139,8 +138,8 @@ public class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
@ -153,8 +152,8 @@ public class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
@ -165,8 +164,8 @@ public class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
@ -200,10 +199,4 @@ public class SubCreator {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
return raw.toJSON().toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package net.ME1312.SubServers.Sync.Network.API;
|
||||
|
||||
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.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketCommandServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketEditServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketStartServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
@ -24,6 +26,7 @@ public class SubServer extends Server {
|
||||
NONE,
|
||||
RESTART,
|
||||
REMOVE_SERVER,
|
||||
RECYCLE_SERVER,
|
||||
DELETE_SERVER;
|
||||
|
||||
@Override
|
||||
@ -37,7 +40,7 @@ public class SubServer extends Server {
|
||||
*
|
||||
* @param raw JSON representation of the Server
|
||||
*/
|
||||
public SubServer(YAMLSection raw) {
|
||||
public SubServer(ObjectMap<String> raw) {
|
||||
super(raw);
|
||||
}
|
||||
|
||||
@ -47,7 +50,7 @@ public class SubServer extends Server {
|
||||
* @param host Host
|
||||
* @param raw JSON representation of the Server
|
||||
*/
|
||||
SubServer(Host host, YAMLSection raw) {
|
||||
SubServer(Host host, ObjectMap<String> raw) {
|
||||
super(raw);
|
||||
this.host = host;
|
||||
}
|
||||
@ -73,9 +76,9 @@ public class SubServer extends Server {
|
||||
public void start(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStartServer(player, getName(), data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -118,9 +121,9 @@ public class SubServer extends Server {
|
||||
public void stop(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -163,9 +166,9 @@ public class SubServer extends Server {
|
||||
public void terminate(UUID player, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -209,9 +212,9 @@ public class SubServer extends Server {
|
||||
public void command(UUID player, String command, Callback<Integer> response) {
|
||||
if (Util.isNull(command, response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
||||
try {
|
||||
response.run(data.getInt("r"));
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
@ -249,6 +252,104 @@ public class SubServer extends Server {
|
||||
command(command, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void edit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(player, edit, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void edit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(null, edit, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void edit(UUID player, ObjectMap<String> edit) {
|
||||
edit(player, edit, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server
|
||||
*
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void edit(ObjectMap<String> edit) {
|
||||
edit(null, edit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void permaEdit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||
edit(player, edit, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param edit Edits
|
||||
* @param response Negative Response Code -or- Positive Success Status
|
||||
*/
|
||||
public void permaEdit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||
permaEdit(null, edit, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void permaEdit(UUID player, ObjectMap<String> edit) {
|
||||
permaEdit(player, edit, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the Server (& Saves Changes)
|
||||
*
|
||||
* @param edit Edits
|
||||
*/
|
||||
public void permaEdit(ObjectMap<String> edit) {
|
||||
permaEdit(null, edit);
|
||||
}
|
||||
|
||||
private void edit(UUID player, ObjectMap<String> edit, boolean perma, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
|
||||
try {
|
||||
if (data.getInt(0x0001) != 0) {
|
||||
response.run(data.getInt(0x0001) * -1);
|
||||
} else {
|
||||
response.run(data.getInt(0x0002));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Running
|
||||
*
|
||||
@ -304,6 +405,31 @@ public class SubServer extends Server {
|
||||
return raw.getBoolean("enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Enabled
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setEnabled(boolean value) {
|
||||
setEnabled(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Enabled
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setEnabled(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("enabled", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("enabled", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is accepting requests to edit()
|
||||
*
|
||||
@ -322,6 +448,31 @@ public class SubServer extends Server {
|
||||
return raw.getBoolean("log");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Logging
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setLogging(boolean value) {
|
||||
setLogging(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the Server is Logging
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setLogging(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("log", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("log", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Directory Path
|
||||
*
|
||||
@ -349,6 +500,31 @@ public class SubServer extends Server {
|
||||
return raw.getRawString("stop-cmd");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Command that Stops the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setStopCommand(String value) {
|
||||
setStopCommand(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Command that Stops the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setStopCommand(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("stop-cmd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("stop-cmd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the action the Server will take when it stops
|
||||
*
|
||||
@ -358,6 +534,31 @@ public class SubServer extends Server {
|
||||
return Util.getDespiteException(() -> StopAction.valueOf(raw.getRawString("stop-action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action the Server will take when it stops
|
||||
*
|
||||
* @param action Stop Action
|
||||
*/
|
||||
public void setStopAction(StopAction action) {
|
||||
setStopAction(action, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the action the Server will take when it stops
|
||||
*
|
||||
* @param action Stop Action
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setStopAction(StopAction action, Callback<Boolean> response) {
|
||||
if (Util.isNull(action, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("stop-action", action.toString());
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("stop-action", action.toString());
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
|
@ -1,34 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import org.msgpack.value.Value;
|
||||
|
||||
/**
|
||||
* SubData Cipher Layout Class
|
||||
*/
|
||||
public interface Cipher {
|
||||
/**
|
||||
* Get the name of this Cipher
|
||||
*
|
||||
* @return Cipher Name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Encrypt JSON Data
|
||||
*
|
||||
* @param key Key to Encrypt Data with
|
||||
* @param data Data to Encrypt
|
||||
* @return Encrypted Data Array
|
||||
*/
|
||||
Value encrypt(String key, YAMLSection data) throws Exception;
|
||||
|
||||
/**
|
||||
* Decrypt Encrypted JSON Data
|
||||
*
|
||||
* @param key Key to Decrypt Data with
|
||||
* @param data Encrypted Data Array
|
||||
* @return JSON Data
|
||||
*/
|
||||
YAMLSection decrypt(String key, Value data) throws Exception;
|
||||
}
|
@ -1,332 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Encryption;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import org.msgpack.core.MessagePack;
|
||||
import org.msgpack.core.MessagePacker;
|
||||
import org.msgpack.value.Value;
|
||||
import org.msgpack.value.ValueFactory;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.InvalidParameterSpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A class to perform password-based AES encryption and decryption in CBC mode.
|
||||
* 128, 192, and 256-bit encryption are supported, provided that the latter two
|
||||
* are permitted by the Java runtime's jurisdiction policy files.
|
||||
* <br/>
|
||||
* The public interface for this class consists of the static methods
|
||||
* {@link #encrypt} and {@link #decrypt}, which encrypt and decrypt arbitrary
|
||||
* streams of data, respectively.
|
||||
*
|
||||
* @author dweymouth@gmail.com
|
||||
*/
|
||||
public final class AES implements net.ME1312.SubServers.Sync.Network.Cipher {
|
||||
|
||||
// AES specification
|
||||
private static final String CIPHER_SPEC = "AES/CBC/PKCS5Padding";
|
||||
|
||||
// Key derivation specification
|
||||
private static final String KEYGEN_SPEC = "PBKDF2WithHmacSHA1";
|
||||
private static final int SALT_LENGTH = 16; // in bytes
|
||||
private static final int AUTH_KEY_LENGTH = 8; // in bytes
|
||||
private static final int ITERATIONS = 32768;
|
||||
|
||||
// Process input/output streams in chunks
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
// Hold Data for use by SubData Cipher methods
|
||||
private final int keyLength;
|
||||
|
||||
/**
|
||||
* Constructor for use as a SubData Cipher
|
||||
*/
|
||||
public AES(int keyLength) {
|
||||
this.keyLength = keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new pseudorandom salt of the specified length
|
||||
*/
|
||||
private static byte[] generateSalt(int length) {
|
||||
Random r = new SecureRandom();
|
||||
byte[] salt = new byte[length];
|
||||
r.nextBytes(salt);
|
||||
return salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive an AES encryption key and authentication key from given password and salt,
|
||||
* using PBKDF2 key stretching. The authentication key is 64 bits long.
|
||||
* @param keyLength
|
||||
* length of the AES key in bits (128, 192, or 256)
|
||||
* @param password
|
||||
* the password from which to derive the keys
|
||||
* @param salt
|
||||
* the salt from which to derive the keys
|
||||
* @return a Keys object containing the two generated keys
|
||||
*/
|
||||
private static Keys keygen(int keyLength, char[] password, byte[] salt) {
|
||||
SecretKeyFactory factory;
|
||||
try {
|
||||
factory = SecretKeyFactory.getInstance(KEYGEN_SPEC);
|
||||
} catch (NoSuchAlgorithmException impossible) { return null; }
|
||||
// derive a longer key, then split into AES key and authentication key
|
||||
KeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, keyLength + AUTH_KEY_LENGTH * 8);
|
||||
SecretKey tmp = null;
|
||||
try {
|
||||
tmp = factory.generateSecret(spec);
|
||||
} catch (InvalidKeySpecException impossible) { }
|
||||
byte[] fullKey = tmp.getEncoded();
|
||||
SecretKey authKey = new SecretKeySpec( // key for password authentication
|
||||
Arrays.copyOfRange(fullKey, 0, AUTH_KEY_LENGTH), "AES");
|
||||
SecretKey encKey = new SecretKeySpec( // key for AES encryption
|
||||
Arrays.copyOfRange(fullKey, AUTH_KEY_LENGTH, fullKey.length), "AES");
|
||||
return new Keys(encKey, authKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a stream of data. The encrypted stream consists of a header
|
||||
* followed by the raw AES data. The header is broken down as follows:<br/>
|
||||
* <ul>
|
||||
* <li><b>keyLength</b>: AES key length in bytes (valid for 16, 24, 32) (1 byte)</li>
|
||||
* <li><b>salt</b>: pseudorandom salt used to derive keys from password (16 bytes)</li>
|
||||
* <li><b>authentication key</b> (derived from password and salt, used to
|
||||
* check validity of password upon decryption) (8 bytes)</li>
|
||||
* <li><b>IV</b>: pseudorandom AES initialization vector (16 bytes)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param keyLength
|
||||
* key length to use for AES encryption (must be 128, 192, or 256)
|
||||
* @param password
|
||||
* password to use for encryption
|
||||
* @param input
|
||||
* an arbitrary byte stream to encrypt
|
||||
* @param output
|
||||
* stream to which encrypted data will be written
|
||||
* @throws AES.InvalidKeyLengthException
|
||||
* if keyLength is not 128, 192, or 256
|
||||
* @throws AES.StrongEncryptionNotAvailableException
|
||||
* if keyLength is 192 or 256, but the Java runtime's jurisdiction
|
||||
* policy files do not allow 192- or 256-bit encryption
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void encrypt(int keyLength, String password, InputStream input, OutputStream output)
|
||||
throws InvalidKeyLengthException, StrongEncryptionNotAvailableException, IOException {
|
||||
// Check validity of key length
|
||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
||||
throw new InvalidKeyLengthException(keyLength);
|
||||
}
|
||||
|
||||
// generate salt and derive keys for authentication and encryption
|
||||
byte[] salt = generateSalt(SALT_LENGTH);
|
||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
||||
|
||||
// initialize AES encryption
|
||||
Cipher encrypt = null;
|
||||
try {
|
||||
encrypt = Cipher.getInstance(CIPHER_SPEC);
|
||||
encrypt.init(Cipher.ENCRYPT_MODE, keys.encryption);
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException impossible) { }
|
||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
||||
}
|
||||
|
||||
// get initialization vector
|
||||
byte[] iv = null;
|
||||
try {
|
||||
iv = encrypt.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
|
||||
} catch (InvalidParameterSpecException impossible) { }
|
||||
|
||||
// write authentication and AES initialization data
|
||||
output.write(keyLength / 8);
|
||||
output.write(salt);
|
||||
output.write(keys.authentication.getEncoded());
|
||||
output.write(iv);
|
||||
|
||||
// read data from input into buffer, encrypt and write to output
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int numRead;
|
||||
byte[] encrypted = null;
|
||||
while ((numRead = input.read(buffer)) > 0) {
|
||||
encrypted = encrypt.update(buffer, 0, numRead);
|
||||
if (encrypted != null) {
|
||||
output.write(encrypted);
|
||||
}
|
||||
}
|
||||
try { // finish encryption - do final block
|
||||
encrypted = encrypt.doFinal();
|
||||
} catch (IllegalBlockSizeException | BadPaddingException impossible) { }
|
||||
if (encrypted != null) {
|
||||
output.write(encrypted);
|
||||
}
|
||||
output.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls to {@link #encrypt(int, String, InputStream, OutputStream)}, simplified for the {@link net.ME1312.SubServers.Sync.Network.Cipher} interface.
|
||||
*
|
||||
* @param key Key to Encrypt Data with
|
||||
* @param data Data to Encrypt
|
||||
* @return Encrypted Data Array
|
||||
*/
|
||||
public Value encrypt(String key, YAMLSection data) throws Exception {
|
||||
ByteArrayOutputStream unencrypted = new ByteArrayOutputStream();
|
||||
MessagePacker packer = MessagePack.newDefaultPacker(unencrypted);
|
||||
packer.packValue(data.msgPack());
|
||||
packer.close();
|
||||
|
||||
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
|
||||
encrypt(keyLength, key, new ByteArrayInputStream(unencrypted.toByteArray()), encrypted);
|
||||
return ValueFactory.newBinary(encrypted.toByteArray(), true);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "AES_" + keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a stream of data that was encrypted by {@link #encrypt}.
|
||||
* @param password
|
||||
* the password used to encrypt/decrypt the stream
|
||||
* @param input
|
||||
* stream of encrypted data to be decrypted
|
||||
* @param output
|
||||
* stream to which decrypted data will be written
|
||||
* @return the key length for the decrypted stream (128, 192, or 256)
|
||||
* @throws AES.InvalidPasswordException
|
||||
* if the given password was not used to encrypt the data
|
||||
* @throws AES.InvalidAESStreamException
|
||||
* if the given input stream is not a valid AES-encrypted stream
|
||||
* @throws AES.StrongEncryptionNotAvailableException
|
||||
* if the stream is 192 or 256-bit encrypted, and the Java runtime's
|
||||
* jurisdiction policy files do not allow for AES-192 or 256
|
||||
* @throws IOException
|
||||
*/
|
||||
public static int decrypt(String password, InputStream input, OutputStream output)
|
||||
throws InvalidPasswordException, InvalidAESStreamException, IOException,
|
||||
StrongEncryptionNotAvailableException {
|
||||
int keyLength = input.read() * 8;
|
||||
// Check validity of key length
|
||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
||||
throw new InvalidAESStreamException();
|
||||
}
|
||||
|
||||
// read salt, generate keys, and authenticate password
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
input.read(salt);
|
||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
||||
byte[] authRead = new byte[AUTH_KEY_LENGTH];
|
||||
input.read(authRead);
|
||||
if (!Arrays.equals(keys.authentication.getEncoded(), authRead)) {
|
||||
throw new InvalidPasswordException();
|
||||
}
|
||||
|
||||
// initialize AES decryption
|
||||
byte[] iv = new byte[16]; // 16-byte I.V. regardless of key size
|
||||
input.read(iv);
|
||||
Cipher decrypt = null;
|
||||
try {
|
||||
decrypt = Cipher.getInstance(CIPHER_SPEC);
|
||||
decrypt.init(Cipher.DECRYPT_MODE, keys.encryption, new IvParameterSpec(iv));
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException
|
||||
| InvalidAlgorithmParameterException impossible) { }
|
||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
||||
}
|
||||
|
||||
// read data from input into buffer, decrypt and write to output
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int numRead;
|
||||
byte[] decrypted;
|
||||
while ((numRead = input.read(buffer)) > 0) {
|
||||
decrypted = decrypt.update(buffer, 0, numRead);
|
||||
if (decrypted != null) {
|
||||
output.write(decrypted);
|
||||
}
|
||||
}
|
||||
try { // finish decryption - do final block
|
||||
decrypted = decrypt.doFinal();
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new InvalidAESStreamException(e);
|
||||
}
|
||||
if (decrypted != null) {
|
||||
output.write(decrypted);
|
||||
}
|
||||
|
||||
output.flush();
|
||||
return keyLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls to {@link #decrypt(String, InputStream, OutputStream)}), simplified for the {@link net.ME1312.SubServers.Sync.Network.Cipher} interface.
|
||||
*
|
||||
* @param key Key to Decrypt Data with
|
||||
* @param data Encrypted Data Array
|
||||
* @return JSON Data
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection decrypt(String key, Value data) throws Exception {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
decrypt(key, new ByteArrayInputStream(data.asBinaryValue().asByteArray()), bytes);
|
||||
return new YAMLSection(MessagePack.newDefaultUnpacker(bytes.toByteArray()).unpackValue().asMapValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* A tuple of encryption and authentication keys returned by {@link #keygen}
|
||||
*/
|
||||
private static class Keys {
|
||||
public final SecretKey encryption, authentication;
|
||||
public Keys(SecretKey encryption, SecretKey authentication) {
|
||||
this.encryption = encryption;
|
||||
this.authentication = authentication;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to decrypt a stream with an incorrect password.
|
||||
*/
|
||||
public static class InvalidPasswordException extends Exception { }
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to encrypt a stream with an invalid AES key length.
|
||||
*/
|
||||
public static class InvalidKeyLengthException extends Exception {
|
||||
InvalidKeyLengthException(int length) {
|
||||
super("Invalid AES key length: " + length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if 192- or 256-bit AES encryption or decryption is attempted,
|
||||
* but not available on the particular Java platform.
|
||||
*/
|
||||
public static class StrongEncryptionNotAvailableException extends Exception {
|
||||
public StrongEncryptionNotAvailableException(int keySize) {
|
||||
super(keySize + "-bit AES encryption is not available on this Java platform.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown if an attempt is made to decrypt an invalid AES stream.
|
||||
*/
|
||||
public static class InvalidAESStreamException extends Exception {
|
||||
public InvalidAESStreamException() { super(); };
|
||||
public InvalidAESStreamException(Exception e) { super(e); }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Add Server Packet
|
||||
*/
|
||||
public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private ObjectMap<String> opt;
|
||||
private boolean subserver;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketAddServer (In)
|
||||
*/
|
||||
public PacketAddServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer [Server] (Out)
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketAddServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, ip, port, motd, hidden, restricted)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.subserver = false;
|
||||
|
||||
ObjectMap<String> opt = new ObjectMap<String>();
|
||||
opt.set("address", ip.getHostAddress() + ':' + port);
|
||||
opt.set("motd", motd);
|
||||
opt.set("restricted", restricted);
|
||||
opt.set("hidden", hidden);
|
||||
this.opt = opt;
|
||||
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketAddServer [SubServer] (Out)
|
||||
*
|
||||
* @param player Player who Added
|
||||
* @param name Name of Server
|
||||
* @param enabled Enabled Status
|
||||
* @param host Host of Server
|
||||
* @param port Port Number
|
||||
* @param motd Motd of the Server
|
||||
* @param log Logging Status
|
||||
* @param directory Directory
|
||||
* @param executable Executable String
|
||||
* @param stopcmd Command to Stop the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketAddServer(UUID player, String name, boolean enabled, String host, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.subserver = true;
|
||||
|
||||
ObjectMap<String> opt = new ObjectMap<String>();
|
||||
opt.set("enabled", enabled);
|
||||
opt.set("host", host);
|
||||
opt.set("port", port);
|
||||
opt.set("motd", motd);
|
||||
opt.set("log", log);
|
||||
opt.set("dir", directory);
|
||||
opt.set("exec", executable);
|
||||
opt.set("stop-cmd", stopcmd);
|
||||
opt.set("restricted", restricted);
|
||||
opt.set("hidden", hidden);
|
||||
this.opt = opt;
|
||||
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, subserver);
|
||||
data.set(0x0003, opt);
|
||||
if (player != null) data.set(0x0004, player);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
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 net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public PacketAuthorization(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("password", plugin.config.get().getSection("Settings").getSection("SubData").getString("Password"));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("init"), plugin.subdata));
|
||||
} else {
|
||||
System.out.println("SubServers > Could not authorize SubData connection: " + data.getRawString("m"));
|
||||
plugin.subdata.destroy(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Packet Check Permission
|
||||
*/
|
||||
public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<Boolean>[]> callbacks = new HashMap<UUID, Callback<Boolean>[]>();
|
||||
private String name;
|
||||
private UUID player;
|
||||
private String permission;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (In)
|
||||
*/
|
||||
public PacketCheckPermission() {}
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (Out)
|
||||
*
|
||||
* @param player Player to check on
|
||||
* @param permission Permission to check
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCheckPermission(UUID player, String permission, Callback<Boolean>... callback) {
|
||||
this(null, player, permission, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCheckPermission (Out)
|
||||
*
|
||||
* @param server Server to check on
|
||||
* @param player Player to check on
|
||||
* @param permission Permission to check
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCheckPermission(String server, UUID player, String permission, Callback<Boolean>... callback) {
|
||||
this.name = server;
|
||||
this.player = player;
|
||||
this.permission = permission;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, player);
|
||||
data.set(0x0002, permission);
|
||||
if (name != null) data.set(0x0003, name);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
|
||||
for (Callback<Boolean> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data.getBoolean(0x0001));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Callback;
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,12 +13,12 @@ import java.util.UUID;
|
||||
/**
|
||||
* Command Server Packet
|
||||
*/
|
||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String command;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCommandServer (In)
|
||||
@ -34,33 +34,33 @@ public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCommandServer(UUID player, String server, String command, Callback<YAMLSection>... callback) {
|
||||
public PacketCommandServer(UUID player, String server, String command, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, command, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.command = command;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
data.set("command", command);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, command);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
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"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,15 +14,16 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private String host;
|
||||
private String template;
|
||||
private Version version;
|
||||
private Integer port;
|
||||
private String id;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
@ -40,41 +42,58 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<YAMLSection>... callback) {
|
||||
if (Util.isNull(name, host, template, version, callback)) throw new NullPointerException();
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<ObjectMap<Integer>>... callback) {
|
||||
this(player, name, host, template, version, port, false, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param host Host to use
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param port Server Port
|
||||
* @param waitfor Wait until completion to send callback
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, host, template, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.host = host;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
YAMLSection creator = new YAMLSection();
|
||||
creator.set("name", name);
|
||||
creator.set("host", host);
|
||||
creator.set("template", template);
|
||||
creator.set("version", version.toString());
|
||||
if (port != null) creator.set("port", port);
|
||||
data.set("creator", creator);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, host);
|
||||
data.set(0x0003, template);
|
||||
if (version != null) data.set(0x0004, version);
|
||||
if (port != null) data.set(0x0005, port);
|
||||
if (player != null) data.set(0x0006, player);
|
||||
if (waitfor) data.set(0x0007, true);
|
||||
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"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Delete Server Packet
|
||||
*/
|
||||
public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private boolean recycle;
|
||||
private boolean force;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDeleteServer (In)
|
||||
*/
|
||||
public PacketDeleteServer() {}
|
||||
|
||||
/**
|
||||
* New PacketDeleteServer (Out)
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDeleteServer(UUID player, String server, boolean recycle, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.recycle = recycle;
|
||||
this.force = force;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, recycle);
|
||||
data.set(0x0003, force);
|
||||
if (player != null) data.set(0x0004, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,22 +1,23 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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>[]>();
|
||||
public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String group;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
@ -30,29 +31,30 @@ public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadGroupInfo(String group, Callback<ObjectMap<String>>... 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);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (group != null) json.set("group", group);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (group != null) json.set(0x0001, group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Host Info Packet
|
||||
*/
|
||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String host;
|
||||
private String id;
|
||||
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String group;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadHostInfo (In)
|
||||
@ -26,33 +27,34 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
/**
|
||||
* New PacketDownloadHostInfo (Out)
|
||||
*
|
||||
* @param host Host name (or null for all)
|
||||
* @param group Host name (or null for all)
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadHostInfo(String group, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.host = host;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.group = group;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (host != null) json.set("host", host);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (group != null) json.set(0x0001, group);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,23 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
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.PacketIn;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Download Lang Packet
|
||||
*/
|
||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
* New PacketDownloadLang (In)
|
||||
*/
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadLang (Out)
|
||||
*
|
||||
* @param plugin SubServers.Client
|
||||
*/
|
||||
@ -32,15 +26,15 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* New PacketDownloadLang (Out)
|
||||
*/
|
||||
public PacketDownloadLang() {}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getSection("Lang").get()));
|
||||
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
|
||||
System.out.println("SubData > Lang Settings Downloaded");
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
@ -48,7 +42,7 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
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 Network List Packet
|
||||
*/
|
||||
public class PacketDownloadNetworkList implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (In)
|
||||
*/
|
||||
public PacketDownloadNetworkList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (Out)
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadNetworkList(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() {
|
||||
if (id != null) {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
}
|
@ -1,49 +1,50 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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;
|
||||
|
||||
public class PacketDownloadPlatformInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private UUID tracker;
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlatformInfo(Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
return data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +1,51 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Player List Packet
|
||||
*/
|
||||
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
private String id;
|
||||
public class PacketDownloadPlayerList implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlayerList (In)
|
||||
*/
|
||||
public PacketDownloadPlayerList() {}
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlayerList (Out)
|
||||
* New PacketDownloadPlayerList
|
||||
*
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadPlayerList(Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadPlayerList(Callback<ObjectMap<String>>... 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() {
|
||||
if (id != null) {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
return data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>> callbacks = new HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>>();
|
||||
private String proxy;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
@ -30,29 +32,35 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadProxyInfo(String proxy, Callback<ObjectMap<String>>... 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);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, new NamedContainer<>(proxy != null && proxy.length() <= 0, callback));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (proxy != null) json.set("proxy", proxy);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (proxy != null) json.set(0x0001, proxy);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
boolean mode = callbacks.get(data.getUUID(0x0000)).name();
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000)).get()) {
|
||||
if (mode) {
|
||||
callback.run((data.contains(0x0002))?new ObjectMap<String>((Map<String, ?>) data.getObject(0x0002)):null);
|
||||
} else callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
}
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerInfo (In)
|
||||
@ -30,29 +31,30 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
||||
public PacketDownloadServerInfo(String server, Callback<ObjectMap<String>>... callback) {
|
||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("id", id);
|
||||
if (server != null) json.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, tracker);
|
||||
if (server != null) json.set(0x0001, server);
|
||||
return json;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getRawString("id"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Edit Server Packet
|
||||
*/
|
||||
public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private ObjectMap<String> edit;
|
||||
private boolean perma;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketEditServer (In)
|
||||
*/
|
||||
public PacketEditServer() {}
|
||||
|
||||
/**
|
||||
* New PacketEditServer (Out)
|
||||
*
|
||||
* @param player Player Editing
|
||||
* @param server Server
|
||||
* @param edit Edits
|
||||
* @param perma Save Changes
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketEditServer(UUID player, String server, ObjectMap<String> edit, boolean perma, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.edit = edit;
|
||||
this.perma = perma;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, edit);
|
||||
data.set(0x0003, perma);
|
||||
if (player != null) data.set(0x0004, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Client.Protocol.PacketIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
/**
|
||||
* Reset Packet
|
||||
*/
|
||||
public class PacketInExReset implements PacketIn {
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client) {
|
||||
SubAPI.getInstance().getInternals().servers.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,149 +1,151 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Event.*;
|
||||
import net.ME1312.SubServers.Sync.Library.Callback;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
import net.ME1312.SubServers.Sync.Event.*;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Run Event Packet
|
||||
*/
|
||||
public class PacketInRunEvent implements PacketIn {
|
||||
private static HashMap<String, List<Callback<YAMLSection>>> callbacks = new HashMap<String, List<Callback<YAMLSection>>>();
|
||||
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
private static HashMap<String, List<Callback<ObjectMap<String>>>> callbacks = new HashMap<String, List<Callback<ObjectMap<String>>>>();
|
||||
|
||||
/**
|
||||
* New PacketInRunEvent
|
||||
* New PacketInExRunEvent
|
||||
*/
|
||||
public PacketInRunEvent(SubPlugin plugin) {
|
||||
callback("SubAddHostEvent", new Callback<YAMLSection>() {
|
||||
public PacketInExRunEvent(SubPlugin plugin) {
|
||||
callback("SubAddHostEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubAddHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host")));
|
||||
callback("SubAddHostEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubAddProxyEvent", new Callback<YAMLSection>() {
|
||||
callback("SubAddProxyEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubAddProxyEvent(data.getRawString("proxy")));
|
||||
callback("SubAddProxyEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubAddServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubAddServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubAddServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
|
||||
callback("SubAddServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubCreateEvent", new Callback<YAMLSection>() {
|
||||
callback("SubCreateEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubSendCommandEvent", new Callback<YAMLSection>() {
|
||||
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), data.getRawString("command")));
|
||||
callback("SubSendCommandEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubEditServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
|
||||
callback("SubEditServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStartEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStartEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubStartEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server")));
|
||||
callback("SubStartEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubNetworkConnectEvent", new Callback<YAMLSection>() {
|
||||
callback("SubNetworkConnectEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
plugin.connect(plugin.servers.get(data.getRawString("server").toLowerCase()), data.getRawString("address"));
|
||||
public void run(ObjectMap<String> data) {
|
||||
plugin.connect(plugin.servers.get(data.getRawString("server").toLowerCase()), data.getInt("channel"), data.getUUID("id"));
|
||||
callback("SubNetworkConnectEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubNetworkDisconnectEvent", new Callback<YAMLSection>() {
|
||||
callback("SubNetworkDisconnectEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
plugin.disconnect(plugin.servers.get(data.getRawString("server").toLowerCase()));
|
||||
public void run(ObjectMap<String> data) {
|
||||
plugin.disconnect(plugin.servers.get(data.getRawString("server").toLowerCase()), data.getInt("channel"));
|
||||
callback("SubNetworkDisconnectEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStopEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStopEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubStopEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), data.getBoolean("force")));
|
||||
callback("SubStopEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubStoppedEvent", new Callback<YAMLSection>() {
|
||||
callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubStoppedEvent(data.getRawString("server")));
|
||||
callback("SubStoppedEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveServerEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveServerEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getRawString("server")));
|
||||
callback("SubRemoveServerEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveProxyEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveProxyEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubAddProxyEvent(data.getRawString("proxy")));
|
||||
callback("SubRemoveProxyEvent", this);
|
||||
}
|
||||
});
|
||||
callback("SubRemoveHostEvent", new Callback<YAMLSection>() {
|
||||
callback("SubRemoveHostEvent", new Callback<ObjectMap<String>>() {
|
||||
@Override
|
||||
public void run(YAMLSection data) {
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host")));
|
||||
callback("SubRemoveHostEvent", this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
if (callbacks.keySet().contains(data.getString("type"))) {
|
||||
List<Callback<YAMLSection>> callbacks = PacketInRunEvent.callbacks.get(data.getString("type"));
|
||||
PacketInRunEvent.callbacks.remove(data.getString("type"));
|
||||
for (Callback<YAMLSection> callback : callbacks) {
|
||||
callback.run(data.getSection("args"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
if (callbacks.keySet().contains(data.getString(0x0000))) {
|
||||
List<Callback<ObjectMap<String>>> callbacks = PacketInExRunEvent.callbacks.get(data.getString(0x0000));
|
||||
PacketInExRunEvent.callbacks.remove(data.getString(0x0000));
|
||||
for (Callback<ObjectMap<String>> callback : callbacks) {
|
||||
callback.run(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
|
||||
public static void callback(String event, Callback<YAMLSection> callback) {
|
||||
List<Callback<YAMLSection>> callbacks = (PacketInRunEvent.callbacks.keySet().contains(event))?PacketInRunEvent.callbacks.get(event):new ArrayList<Callback<YAMLSection>>();
|
||||
public static void callback(String event, Callback<ObjectMap<String>> callback) {
|
||||
List<Callback<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Callback<ObjectMap<String>>>();
|
||||
callbacks.add(callback);
|
||||
PacketInRunEvent.callbacks.put(event, callbacks);
|
||||
PacketInExRunEvent.callbacks.put(event, callbacks);
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
|
||||
/**
|
||||
* Update External Whitelist Packet
|
||||
*/
|
||||
public class PacketInExUpdateWhitelist implements PacketIn {
|
||||
public class PacketInExUpdateWhitelist implements PacketObjectIn<Integer> {
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
@ -19,16 +19,16 @@ public class PacketInExUpdateWhitelist implements PacketIn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) throws Throwable {
|
||||
if (data.getBoolean("mode")) {
|
||||
plugin.servers.get(data.getRawString("name")).whitelist(data.getUUID("value"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
if (data.getBoolean(0x0001)) {
|
||||
plugin.servers.get(data.getRawString(0x0000)).whitelist(data.getUUID(0x0002));
|
||||
} else {
|
||||
plugin.servers.get(data.getRawString("name")).unwhitelist(data.getUUID("value"));
|
||||
plugin.servers.get(data.getRawString(0x0000)).unwhitelist(data.getUUID(0x0002));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13.2c");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
/**
|
||||
* Reset Packet
|
||||
*/
|
||||
public class PacketInReset implements PacketIn {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
SubAPI.getInstance().getInternals().servers.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,57 +1,77 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
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 net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Link Proxy Packet
|
||||
*/
|
||||
public class PacketLinkProxy implements PacketIn, PacketOut {
|
||||
public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int channel;
|
||||
|
||||
/**
|
||||
* New PacketLinkProxy
|
||||
* New PacketLinkProxy (In)
|
||||
*
|
||||
* @param plugin SubServers.Sync
|
||||
* @param plugin SubServers.Client
|
||||
*/
|
||||
public PacketLinkProxy(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("name", plugin.subdata.getName());
|
||||
return data;
|
||||
/**
|
||||
* New PacketLinkProxy (Out)
|
||||
*
|
||||
* @param plugin SubServers.Client
|
||||
* @param channel Channel ID
|
||||
*/
|
||||
public PacketLinkProxy(SubPlugin plugin, int channel) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(YAMLSection data) {
|
||||
if (data.getInt("r") == 0) {
|
||||
if (data.contains("n")) Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredField("name"), data.getRawString("n")));
|
||||
} else {
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, plugin.api.getName());
|
||||
json.set(0x0001, channel);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
try {
|
||||
if (data.getInt("r") == 2) {
|
||||
if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
|
||||
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "undefined");
|
||||
if (data.contains(0x0000)) Util.reflect(SubAPI.class.getDeclaredField("name"), plugin.api, data.getRawString(0x0000));
|
||||
setReady(client, true);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("SubData > Could not link name with proxy" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||
try {
|
||||
if (data.getInt(0x0001) == 2) {
|
||||
if (!plugin.config.get().getMap("Settings").getMap("SubData").contains("Name")) {
|
||||
plugin.config.get().getMap("Settings").getMap("SubData").set("Name", "");
|
||||
plugin.config.save();
|
||||
}
|
||||
if (plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Name").length() <= 0)
|
||||
System.out.println("SubData > Use the proxy \"Name\" option to override auto-linking");
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
System.out.println("SubData > Could not link name with server: " + data.getRawString("m"));
|
||||
new IllegalStateException().printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Remove Server Packet
|
||||
*/
|
||||
public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private boolean force;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketRemoveServer (In)
|
||||
*/
|
||||
public PacketRemoveServer() {}
|
||||
|
||||
/**
|
||||
* New PacketRemoveServer (Out)
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param server Server
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketRemoveServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, force);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Restart Server Packet
|
||||
*/
|
||||
public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketRestartServer (In)
|
||||
@ -32,31 +32,31 @@ public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketRestartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
||||
public PacketRestartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
if (player != null) data.set(0x0002, player.toString());
|
||||
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"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Start Server Packet
|
||||
*/
|
||||
public class PacketStartServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketStartServer (In)
|
||||
@ -32,31 +32,31 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketStartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
||||
public PacketStartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, server);
|
||||
if (player != null) data.set(0x0002, player.toString());
|
||||
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"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
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 net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -13,12 +13,12 @@ import java.util.UUID;
|
||||
/**
|
||||
* Stop Server Packet
|
||||
*/
|
||||
public class PacketStopServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private boolean force;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID id;
|
||||
|
||||
/**
|
||||
* New PacketStopServer (In)
|
||||
@ -34,33 +34,33 @@ public class PacketStopServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketStopServer(UUID player, String server, boolean force, Callback<YAMLSection>... callback) {
|
||||
public PacketStopServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, force, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.server = server;
|
||||
this.force = force;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(id, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
if (player != null) data.set("player", player.toString());
|
||||
data.set("server", server);
|
||||
data.set("force", force);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, id);
|
||||
data.set(0x0001, server);
|
||||
data.set(0x0002, force);
|
||||
if (player != null) data.set(0x0003, player.toString());
|
||||
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"));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
|
||||
/**
|
||||
* PacketIn Layout Class
|
||||
*/
|
||||
public interface PacketIn {
|
||||
/**
|
||||
* Execute Incoming Packet
|
||||
*
|
||||
* @param data Incoming Data
|
||||
*/
|
||||
void execute(YAMLSection data) throws Throwable;
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
|
||||
/**
|
||||
* Check Compatibility with oncoming packet
|
||||
*
|
||||
* @param version Version of oncoming packet
|
||||
* @return Compatibility Status
|
||||
*/
|
||||
default boolean isCompatible(Version version) {
|
||||
return getVersion().equals(version);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
|
||||
/**
|
||||
* PacketOut Layout Class
|
||||
*/
|
||||
public interface PacketOut {
|
||||
/**
|
||||
* Generate Packet Contents
|
||||
*
|
||||
* @return Packet Contents
|
||||
*/
|
||||
YAMLSection generate() throws Throwable;
|
||||
|
||||
/**
|
||||
* Get Packet Version
|
||||
*
|
||||
* @return Packet Version
|
||||
*/
|
||||
Version getVersion();
|
||||
}
|
@ -1,495 +0,0 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
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;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.conf.Configuration;
|
||||
import org.msgpack.core.MessageInsufficientBufferException;
|
||||
import org.msgpack.core.MessagePack;
|
||||
import org.msgpack.core.MessagePacker;
|
||||
import org.msgpack.core.MessageUnpacker;
|
||||
import org.msgpack.value.Value;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* SubData Direct Client Class
|
||||
*/
|
||||
public final class SubDataClient {
|
||||
private static HashMap<Class<? extends PacketOut>, NamedContainer<String, String>> pOut = new HashMap<Class<? extends PacketOut>, NamedContainer<String, String>>();
|
||||
private static HashMap<String, HashMap<String, List<PacketIn>>> pIn = new HashMap<String, HashMap<String, List<PacketIn>>>();
|
||||
private static HashMap<String, Cipher> ciphers = new HashMap<String, Cipher>();
|
||||
private static boolean defaults = false;
|
||||
private MessagePacker out;
|
||||
private NamedContainer<Boolean, Socket> socket;
|
||||
private String name = null;
|
||||
private Cipher cipher;
|
||||
private SubPlugin plugin;
|
||||
private LinkedList<NamedContainer<String, PacketOut>> queue;
|
||||
|
||||
/**
|
||||
* SubServers Client Instance
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param address Address
|
||||
* @param port Port
|
||||
* @param cipher Cipher
|
||||
* @throws IOException
|
||||
*/
|
||||
public SubDataClient(SubPlugin plugin, String name, InetAddress address, int port, Cipher cipher) throws IOException {
|
||||
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
|
||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
||||
this.plugin = plugin;
|
||||
this.name = (name == null || name.length() > 0)?name:null;
|
||||
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
|
||||
this.cipher = (cipher != null)?cipher:new Cipher() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "NONE";
|
||||
}
|
||||
@Override
|
||||
public Value encrypt(String key, YAMLSection data) {
|
||||
return data.msgPack();
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection decrypt(String key, Value data) {
|
||||
return new YAMLSection(data.asMapValue());
|
||||
}
|
||||
};
|
||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
loop();
|
||||
|
||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin)));
|
||||
}
|
||||
|
||||
private void init() {
|
||||
plugin.subdata.sendPacket(new PacketDownloadLang(plugin));
|
||||
plugin.subdata.sendPacket(new PacketLinkProxy(plugin));
|
||||
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 = platform.getSection("subservers").getLong("last-reload");
|
||||
}
|
||||
try {
|
||||
LinkedList<ListenerInfo> listeners = new LinkedList<ListenerInfo>(plugin.getConfig().getListeners());
|
||||
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)) Util.reflect(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)) Util.reflect(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)) Util.reflect(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)) Util.reflect(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)) Util.reflect(Configuration.class.getDeclaredField("disabledCommands"), plugin.getConfig(), platform.getSection("bungee").getRawStringList("disabled-cmds"));
|
||||
if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) Util.reflect(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 (Server server : servers.values()) {
|
||||
plugin.merge(server);
|
||||
}
|
||||
})));
|
||||
while (queue.size() != 0) {
|
||||
sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
socket.rename(true);
|
||||
plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(this));
|
||||
}
|
||||
|
||||
static {
|
||||
addCipher("AES", new AES(128));
|
||||
addCipher("AES_128", new AES(128));
|
||||
addCipher("AES_192", new AES(192));
|
||||
addCipher("AES_256", new AES(256));
|
||||
} private void loadDefaults() {
|
||||
defaults = true;
|
||||
|
||||
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 PacketInExUpdateWhitelist(plugin), "SubServers", "ExUpdateWhitelist");
|
||||
registerPacket(new PacketInRunEvent(plugin), "SubServers", "RunEvent");
|
||||
registerPacket(new PacketInReset(), "SubServers", "Reset");
|
||||
registerPacket(new PacketLinkProxy(plugin), "SubServers", "LinkProxy");
|
||||
registerPacket(new PacketRestartServer(), "SubServers", "RestartServer");
|
||||
registerPacket(new PacketStartServer(), "SubServers", "StartServer");
|
||||
registerPacket(new PacketStopServer(), "SubServers", "StopServer");
|
||||
|
||||
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(PacketLinkProxy.class, "SubServers", "LinkProxy");
|
||||
registerPacket(PacketRestartServer.class, "SubServers", "RestartServer");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recieve(input);
|
||||
}
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "SubServers.Sync::SubData_Packet_Listener").start();
|
||||
}
|
||||
|
||||
private void recieve(Value input) {
|
||||
try {
|
||||
YAMLSection data = cipher.decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : decodePacket(data)) {
|
||||
try {
|
||||
packet.execute((data.contains("c")) ? data.getSection("c") : null);
|
||||
} catch (Throwable e) {
|
||||
new InvocationTargetException(e, "Exception while executing PacketIn").printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (JsonParseException | YAMLException e) {
|
||||
new IllegalPacketException("Unknown Packet Format: " + input).printStackTrace();
|
||||
} catch (IllegalPacketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Assigned Proxy Name
|
||||
*
|
||||
* @return Host Name
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getName() {
|
||||
if (name != null) {
|
||||
return name;
|
||||
} else if (plugin.redis) {
|
||||
try {
|
||||
return (String) plugin.redis("getServerId");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Socket
|
||||
*
|
||||
* @return Server Socket
|
||||
*/
|
||||
public Socket getClient() {
|
||||
return socket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Cipher for use by SubData
|
||||
*
|
||||
* @param cipher Cipher to Add
|
||||
* @param handle Handle to Bind
|
||||
*/
|
||||
public static void addCipher(String handle, Cipher cipher) {
|
||||
if (Util.isNull(cipher)) throw new NullPointerException();
|
||||
if (ciphers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Cipher already exists: " + handle);
|
||||
ciphers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), cipher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Ciphers
|
||||
*
|
||||
* @return Cipher Map
|
||||
*/
|
||||
public static Map<String, Cipher> getCiphers() {
|
||||
return new TreeMap<>(ciphers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Client's Cipher
|
||||
*
|
||||
* @return Cipher
|
||||
*/
|
||||
public Cipher getCipher() {
|
||||
return cipher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Cipher by Handle
|
||||
*
|
||||
* @param handle Handle
|
||||
* @return Cipher
|
||||
*/
|
||||
public static Cipher getCipher(String handle) {
|
||||
return getCiphers().get(handle.toUpperCase().replace('-', '_').replace(' ', '_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register PacketIn to the Network
|
||||
*
|
||||
* @param packet PacketIn to register
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle to Bind
|
||||
*/
|
||||
public static void registerPacket(PacketIn packet, String channel, String handle) {
|
||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
||||
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
|
||||
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
|
||||
if (!list.contains(packet)) {
|
||||
list.add(packet);
|
||||
map.put(handle, list);
|
||||
pIn.put(channel.toLowerCase(), map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister PacketIn from the Network
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param packet PacketIn to unregister
|
||||
*/
|
||||
public static void unregisterPacket(String channel, PacketIn packet) {
|
||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
||||
if (pIn.keySet().contains(channel.toLowerCase())) {
|
||||
List<String> search = new ArrayList<String>();
|
||||
search.addAll(pIn.get(channel.toLowerCase()).keySet());
|
||||
for (String handle : search) if (pIn.get(channel.toLowerCase()).get(handle).contains(packet)) {
|
||||
List<PacketIn> list = pIn.get(channel.toLowerCase()).get(handle);
|
||||
list.remove(packet);
|
||||
if (list.isEmpty()) {
|
||||
pIn.get(channel.toLowerCase()).remove(handle);
|
||||
if (pIn.get(channel.toLowerCase()).isEmpty()) pIn.remove(channel.toLowerCase());
|
||||
} else {
|
||||
pIn.get(channel.toLowerCase()).put(handle, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register PacketOut to the Network
|
||||
*
|
||||
* @param packet PacketOut to register
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle to bind
|
||||
*/
|
||||
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
|
||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
||||
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister PacketOut to the Network
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param packet PacketOut to unregister
|
||||
*/
|
||||
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
|
||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
||||
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab PacketIn Instances via handle
|
||||
*
|
||||
* @param channel Packet Channel
|
||||
* @param handle Handle
|
||||
* @return PacketIn
|
||||
*/
|
||||
public static List<? extends PacketIn> getPacket(String channel, String handle) {
|
||||
if (Util.isNull(channel, handle)) throw new NullPointerException();
|
||||
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Packet to Server
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(null, packet));
|
||||
} else {
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
||||
try {
|
||||
YAMLSection data = encodePacket(packet.get());
|
||||
if (packet.name() != null) data.set("f", packet.name());
|
||||
out.packValue(getCipher().encrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data));
|
||||
out.flush();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward Packet to Client
|
||||
*
|
||||
* @param packet Packet to send
|
||||
* @param location Where to send
|
||||
*/
|
||||
public void forwardPacket(PacketOut packet, String location) {
|
||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
||||
if (socket.get() == null || !socket.name()) {
|
||||
queue.add(new NamedContainer<>(location, packet));
|
||||
} else {
|
||||
sendPacket(new NamedContainer<>(null, packet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast packet to all Clients
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void broadcastPacket(PacketOut packet) {
|
||||
forwardPacket(packet, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode PacketOut
|
||||
*
|
||||
* @param packet PacketOut
|
||||
* @return JSON Formatted Packet
|
||||
* @throws IllegalPacketException
|
||||
*/
|
||||
private static YAMLSection encodePacket(PacketOut packet) throws IllegalPacketException, InvocationTargetException {
|
||||
YAMLSection json = new YAMLSection();
|
||||
|
||||
if (!pOut.keySet().contains(packet.getClass())) throw new IllegalPacketException("Unknown PacketOut Channel: " + packet.getClass().getCanonicalName());
|
||||
if (packet.getVersion() == null) throw new NullPointerException("PacketOut Version cannot be null: " + packet.getClass().getCanonicalName());
|
||||
|
||||
try {
|
||||
YAMLSection contents = packet.generate();
|
||||
json.set("n", pOut.get(packet.getClass()).name());
|
||||
json.set("h", pOut.get(packet.getClass()).get());
|
||||
json.set("v", packet.getVersion());
|
||||
if (contents != null) json.set("c", contents);
|
||||
return json;
|
||||
} catch (Throwable e) {
|
||||
throw new InvocationTargetException(e, "Exception while encoding packet");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode PacketIn
|
||||
*
|
||||
* @param data Data to Decode
|
||||
* @return PacketIn
|
||||
* @throws IllegalPacketException
|
||||
* @throws InvocationTargetException
|
||||
*/
|
||||
private static List<PacketIn> decodePacket(YAMLSection data) throws IllegalPacketException, InvocationTargetException {
|
||||
if (!data.contains("h") || !data.contains("v")) throw new IllegalPacketException("Unknown Packet Format: " + data.toString());
|
||||
if (!pIn.keySet().contains(data.getRawString("n")) || !pIn.get(data.getRawString("n")).keySet().contains(data.getRawString("h"))) throw new IllegalPacketException("Unknown PacketIn Channel: " + data.getRawString("n") + ':' + data.getRawString("h"));
|
||||
|
||||
List<PacketIn> list = new ArrayList<PacketIn>();
|
||||
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
|
||||
if (packet.isCompatible(data.getVersion("v"))) {
|
||||
list.add(packet);
|
||||
} else {
|
||||
new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toFullString()).printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops All Connections and Stops the SubData Listener
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void destroy(int reconnect) throws IOException {
|
||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
||||
if (socket.get() != null) {
|
||||
final Socket socket = this.socket.get();
|
||||
this.socket.set(null);
|
||||
if (!socket.isClosed()) socket.close();
|
||||
plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent());
|
||||
System.out.println("SubServers > The SubData Connection was closed");
|
||||
if (reconnect > 0) {
|
||||
System.out.println("SubServers > Attempting to reconnect in " + reconnect + " seconds");
|
||||
Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler");
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
plugin.subdata = new SubDataClient(plugin, name, socket.getInetAddress(), socket.getPort(), cipher);
|
||||
timer.cancel();
|
||||
while (queue.size() != 0) {
|
||||
if (queue.get(0).name() != null) {
|
||||
plugin.subdata.forwardPacket(queue.get(0).get(), queue.get(0).name());
|
||||
} else {
|
||||
plugin.subdata.sendPacket(queue.get(0).get());
|
||||
}
|
||||
queue.remove(0);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("SubServers > Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,221 @@
|
||||
package net.ME1312.SubServers.Sync.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataProtocol;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Sync.Network.API.Server;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.ME1312.SubServers.Sync.SubPlugin;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.conf.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
||||
|
||||
// 00-09: Object Link Packets
|
||||
instance.registerPacket(0x0000, PacketLinkProxy.class);
|
||||
instance.registerPacket(0x0000, new PacketLinkProxy(plugin));
|
||||
|
||||
|
||||
// 10-29: Download Packets
|
||||
instance.registerPacket(0x0010, PacketDownloadLang.class);
|
||||
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
|
||||
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
|
||||
instance.registerPacket(0x0013, PacketDownloadHostInfo.class);
|
||||
instance.registerPacket(0x0014, PacketDownloadGroupInfo.class);
|
||||
instance.registerPacket(0x0015, PacketDownloadServerInfo.class);
|
||||
instance.registerPacket(0x0016, PacketDownloadPlayerList.class);
|
||||
instance.registerPacket(0x0017, PacketCheckPermission.class);
|
||||
|
||||
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
|
||||
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo());
|
||||
instance.registerPacket(0x0012, new PacketDownloadProxyInfo());
|
||||
instance.registerPacket(0x0013, new PacketDownloadHostInfo());
|
||||
instance.registerPacket(0x0014, new PacketDownloadGroupInfo());
|
||||
instance.registerPacket(0x0015, new PacketDownloadServerInfo());
|
||||
instance.registerPacket(0x0016, new PacketDownloadPlayerList());
|
||||
instance.registerPacket(0x0017, new PacketCheckPermission());
|
||||
|
||||
|
||||
// 30-49: Control Packets
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
|
||||
//instance.registerPacket(0x0071, PacketInExReset.class);
|
||||
//instance.registerPacket(0x0073, PacketInExReload.class);
|
||||
|
||||
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
|
||||
instance.registerPacket(0x0071, new PacketInExReset());
|
||||
instance.registerPacket(0x0073, new PacketInExUpdateWhitelist(plugin));
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Logger getLogger(int channel) {
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
private String prefix = "SubData" + ((channel != 0)? "/Sub-"+channel:"");
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open)
|
||||
ProxyServer.getInstance().getLogger().log(record.getLevel(), prefix + " > " + record.getMessage(), record.getParameters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SubDataClient sub(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||
|
||||
int channel = 1;
|
||||
while (map.keySet().contains(channel)) channel++;
|
||||
final int fc = channel;
|
||||
|
||||
SubDataClient subdata = super.open(scheduler, getLogger(fc), address, port);
|
||||
map.put(fc, subdata);
|
||||
subdata.sendPacket(new PacketLinkProxy(plugin, fc));
|
||||
subdata.on.closed(client -> map.remove(fc));
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||
|
||||
subdata.sendPacket(new PacketLinkProxy(plugin, 0));
|
||||
subdata.sendPacket(new PacketDownloadLang());
|
||||
subdata.sendPacket(new PacketDownloadPlatformInfo(platform -> {
|
||||
if (plugin.lastReload != platform.getMap("subservers").getLong("last-reload")) {
|
||||
System.out.println("SubServers > Resetting Server Data");
|
||||
plugin.servers.clear();
|
||||
plugin.lastReload = platform.getMap("subservers").getLong("last-reload");
|
||||
}
|
||||
try {
|
||||
LinkedList<ListenerInfo> listeners = new LinkedList<ListenerInfo>(plugin.getConfig().getListeners());
|
||||
for (int i = 0; i < platform.getMap("bungee").getMapList("listeners").size(); i++) if (i < listeners.size()) {
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Forced-Hosts", true)) Util.reflect(ListenerInfo.class.getDeclaredField("forcedHosts"), listeners.get(i), platform.getMap("bungee").getMapList("listeners").get(i).getMap("forced-hosts").get());
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Motd", false)) Util.reflect(ListenerInfo.class.getDeclaredField("motd"), listeners.get(i), platform.getMap("bungee").getMapList("listeners").get(i).getRawString("motd"));
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Player-Limit", false)) Util.reflect(ListenerInfo.class.getDeclaredField("maxPlayers"), listeners.get(i), platform.getMap("bungee").getMapList("listeners").get(i).getInt("player-limit"));
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Server-Priorities", true)) Util.reflect(ListenerInfo.class.getDeclaredField("serverPriority"), listeners.get(i), platform.getMap("bungee").getMapList("listeners").get(i).getRawStringList("priorities"));
|
||||
}
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Disabled-Commands", false)) Util.reflect(Configuration.class.getDeclaredField("disabledCommands"), plugin.getConfig(), platform.getMap("bungee").getRawStringList("disabled-cmds"));
|
||||
if (plugin.config.get().getMap("Sync", new ObjectMap<>()).getBoolean("Player-Limit", false)) Util.reflect(Configuration.class.getDeclaredField("playerLimit"), plugin.getConfig(), platform.getMap("bungee").getInt("player-limit"));
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubServers > Problem syncing BungeeCord configuration options");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
plugin.api.getServers(servers -> {
|
||||
for (Server server : servers.values()) {
|
||||
plugin.merge(server);
|
||||
}
|
||||
});
|
||||
}));
|
||||
subdata.on.ready(client -> plugin.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
|
||||
subdata.on.closed(client -> {
|
||||
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
map.put(0, null);
|
||||
|
||||
int reconnect = plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
|
||||
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("reconnect"), plugin), false) && reconnect > 0
|
||||
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
|
||||
System.out.println("SubData > Attempting reconnect in " + reconnect + " seconds");
|
||||
Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler");
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Util.reflect(SubPlugin.class.getDeclaredMethod("connect"), plugin);
|
||||
timer.cancel();
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getTargetException() instanceof IOException) {
|
||||
System.out.println("SubData > Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||
} else e.printStackTrace();
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, TimeUnit.SECONDS.toMillis(reconnect), TimeUnit.SECONDS.toMillis(reconnect));
|
||||
}
|
||||
});
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
return open(getLogger(0), address, port);
|
||||
}
|
||||
}
|
@ -1,53 +1,64 @@
|
||||
package net.ME1312.SubServers.Sync.Server;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Server Class
|
||||
*/
|
||||
public class ServerContainer extends BungeeServerInfo {
|
||||
private String subdata;
|
||||
private HashMap<Integer, UUID> subdata = new HashMap<Integer, UUID>();
|
||||
private List<UUID> whitelist = new ArrayList<UUID>();
|
||||
private String nick = null;
|
||||
private boolean hidden;
|
||||
private final String signature;
|
||||
|
||||
public ServerContainer(String signature, String name, String display, InetSocketAddress address, String subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist) {
|
||||
public ServerContainer(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist) {
|
||||
super(name, address, motd, restricted);
|
||||
if (Util.isNull(name, address, motd, hidden, restricted)) throw new NullPointerException();
|
||||
this.signature = signature;
|
||||
this.subdata = subdata;
|
||||
this.whitelist.addAll(whitelist);
|
||||
this.hidden = hidden;
|
||||
setDisplayName(display);
|
||||
|
||||
for (int channel : subdata.keySet())
|
||||
setSubData(subdata.get(channel), channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client Address
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client Address (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public String getSubData() {
|
||||
return subdata;
|
||||
public UUID[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<UUID> channels = new LinkedList<UUID>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SubData Client Address
|
||||
* Link a SubData Client to this Object
|
||||
*
|
||||
* @param subdata SubData Client Address (null represents not linked)
|
||||
* @param client Client to Link
|
||||
* @param channel Channel ID
|
||||
*/
|
||||
public void setSubData(String subdata) {
|
||||
this.subdata = subdata;
|
||||
public void setSubData(UUID client, int channel) {
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (client != null || channel == 0) {
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && (client == null || subdata.get(channel) == null))) {
|
||||
subdata.put(channel, client);
|
||||
}
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package net.ME1312.SubServers.Sync.Server;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -10,7 +11,7 @@ import java.util.UUID;
|
||||
public class SubServerContainer extends ServerContainer {
|
||||
private boolean running;
|
||||
|
||||
public SubServerContainer(String signature, String name, String display, InetSocketAddress address, String subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist, boolean running) {
|
||||
public SubServerContainer(String signature, String name, String display, InetSocketAddress address, Map<Integer, UUID> subdata, String motd, boolean hidden, boolean restricted, Collection<UUID> whitelist, boolean running) {
|
||||
super(signature, name, display, address, subdata, motd, hidden, restricted, whitelist);
|
||||
this.running = running;
|
||||
}
|
||||
|
@ -1,25 +1,33 @@
|
||||
package net.ME1312.SubServers.Sync;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.DataClient;
|
||||
import net.ME1312.SubServers.Sync.Library.*;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.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.Network.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* SubAPI Class
|
||||
*/
|
||||
public final class SubAPI {
|
||||
LinkedList<NamedContainer<Runnable, Runnable>> listeners = new LinkedList<NamedContainer<Runnable, Runnable>>();
|
||||
LinkedList<Runnable> enableListeners = new LinkedList<Runnable>();
|
||||
LinkedList<Runnable> disableListeners = new LinkedList<Runnable>();
|
||||
private final SubPlugin plugin;
|
||||
private static SubAPI api;
|
||||
String name;
|
||||
|
||||
protected SubAPI(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -51,10 +59,31 @@ public final class SubAPI {
|
||||
* Adds a SubAPI Listener
|
||||
*
|
||||
* @param enable An Event that will be called when SubAPI is ready
|
||||
* @param disable An Event that will be called before SubAPI is disabled
|
||||
* @param disable An Event that will be called before SubAPI is disabled (your plugin should reset it's values in case this is a hard-reset instead of a shutdown)
|
||||
*/
|
||||
public void addListener(Runnable enable, Runnable disable) {
|
||||
listeners.add(new NamedContainer<Runnable, Runnable>(enable, disable));
|
||||
if (enable != null) enableListeners.add(enable);
|
||||
if (disable != null) disableListeners.add(disable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server Name
|
||||
*
|
||||
* @return Server Name
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getName() {
|
||||
if (name != null) {
|
||||
return name;
|
||||
} else if (plugin.redis) {
|
||||
try {
|
||||
return (String) plugin.redis("getServerId");
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,10 +94,10 @@ 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 PacketDownloadHostInfo(null, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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)));
|
||||
for (String host : data.getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -90,10 +119,10 @@ public final class SubAPI {
|
||||
public void getHost(String name, Callback<Host> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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()));
|
||||
if (data.getKeys().size() > 0) {
|
||||
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -114,15 +143,15 @@ 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 PacketDownloadGroupInfo(null, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||
for (String group : data.getSection("groups").getKeys()) {
|
||||
for (String group : data.getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
||||
if (data.getSection("groups").getSection(group).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getSection("groups").getSection(group).getSection(server)));
|
||||
for (String server : data.getMap(group).getKeys()) {
|
||||
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getMap(group).getMap(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(group).getSection(server)));
|
||||
servers.add(new Server(data.getMap(group).getMap(server)));
|
||||
}
|
||||
}
|
||||
if (servers.size() > 0) groups.put(group, servers);
|
||||
@ -163,16 +192,16 @@ public final class SubAPI {
|
||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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();
|
||||
if (data.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.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)));
|
||||
for (String server : data.getMap(key).getKeys()) {
|
||||
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.add(new SubServer(data.getMap(key).getMap(server)));
|
||||
} else {
|
||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
||||
servers.add(new Server(data.getMap(key).getMap(server)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -195,13 +224,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 PacketDownloadServerInfo(null, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||
for (String server : data.getSection("servers").getKeys()) {
|
||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
||||
for (String server : data.getKeys()) {
|
||||
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
servers.put(server.toLowerCase(), new SubServer(data.getMap(server)));
|
||||
} else {
|
||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
||||
servers.put(server.toLowerCase(), new Server(data.getMap(server)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,14 +253,14 @@ public final class SubAPI {
|
||||
public void getServer(String name, Callback<Server> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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));
|
||||
if (data.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||
if (data.getMap(key).getRawString("type", "Server").equals("SubServer")) {
|
||||
server = new SubServer(data.getMap(key));
|
||||
} else {
|
||||
server = new Server(data.getSection("servers").getSection(key));
|
||||
server = new Server(data.getMap(key));
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,6 +274,174 @@ public final class SubAPI {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
addServer(null, name, ip, port, motd, hidden, restricted, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, ip, port, motd, hidden, restricted, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden if the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
*/
|
||||
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
addServer(null, name, ip, port, motd, hidden, restricted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Server to the Network
|
||||
*
|
||||
* @param player Player who added
|
||||
* @param name Name of the Server
|
||||
* @param ip IP of the Server
|
||||
* @param port Port of the Server
|
||||
* @param motd MOTD of the Server
|
||||
* @param hidden If the server should be hidden from players
|
||||
* @param restricted Players will need a permission to join if true
|
||||
*/
|
||||
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||
addServer(player, name, ip, port, motd, hidden, restricted, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeServer(String name, Callback<Integer> response) {
|
||||
removeServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void removeServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, false, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void removeServer(String name) {
|
||||
removeServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void removeServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveServer(String name, Callback<Integer> response) {
|
||||
forceRemoveServer(null, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void forceRemoveServer(UUID player, String name, Callback<Integer> response) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
removeServer(player, name, true, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void forceRemoveServer(String name) {
|
||||
forceRemoveServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force Remove a Server from the Network
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name Name of the Server
|
||||
*/
|
||||
public void forceRemoveServer(UUID player, String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
forceRemoveServer(player, name, i -> {});
|
||||
}
|
||||
|
||||
private void removeServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubServers
|
||||
*
|
||||
@ -280,10 +477,10 @@ public final class SubAPI {
|
||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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)));
|
||||
for (String proxy : data.getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -305,10 +502,10 @@ public final class SubAPI {
|
||||
public void getProxy(String name, Callback<Proxy> callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).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()));
|
||||
if (data.getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -329,10 +526,10 @@ public final class SubAPI {
|
||||
public void getMasterProxy(Callback<Proxy> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||
Proxy proxy = null;
|
||||
if (data.getKeys().contains("master")) {
|
||||
proxy = new Proxy(data.getSection("master"));
|
||||
if (data != null) {
|
||||
proxy = new Proxy(data);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -354,10 +551,10 @@ public final class SubAPI {
|
||||
public void getGlobalPlayers(Callback<Collection<NamedContainer<String, UUID>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new PacketDownloadPlayerList(data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerList(data -> {
|
||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||
for (String id : data.getSection("players").getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(data.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
||||
for (String id : data.getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(data.getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
}
|
||||
|
||||
try {
|
||||
@ -375,8 +572,12 @@ public final class SubAPI {
|
||||
*
|
||||
* @return SubData Network Manager
|
||||
*/
|
||||
public SubDataClient getSubDataNetwork() {
|
||||
return plugin.subdata;
|
||||
public DataClient[] getSubDataNetwork() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(plugin.subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(plugin.subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -421,9 +622,9 @@ public final class SubAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubServers.Sync Version
|
||||
* Gets the SubServers Version
|
||||
*
|
||||
* @return SubServers.Sync Version
|
||||
* @return SubServers Version
|
||||
*/
|
||||
public Version getWrapperVersion() {
|
||||
return plugin.version;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,21 +2,25 @@ package net.ME1312.SubServers.Sync;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubData.Client.Encryption.AES;
|
||||
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubServers.Sync.Event.*;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Sync.Library.Fallback.SmartReconnectHandler;
|
||||
import net.ME1312.SubServers.Sync.Library.Metrics;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.Cipher;
|
||||
import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Library.Updates.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Sync.Network.SubProtocol;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -40,6 +44,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* Main Plugin Class
|
||||
*/
|
||||
public final class SubPlugin extends BungeeCord implements Listener {
|
||||
protected HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public final Map<String, ServerContainer> servers = new TreeMap<String, ServerContainer>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
@ -49,11 +54,12 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public YAMLConfig config;
|
||||
public boolean redis = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
public SubDataClient subdata = null;
|
||||
public SubProtocol subprotocol;
|
||||
public static final Version version = Version.fromString("2.14a");
|
||||
|
||||
public final boolean isPatched;
|
||||
public long lastReload = -1;
|
||||
private boolean reconnect = false;
|
||||
private boolean posted = false;
|
||||
|
||||
protected SubPlugin(PrintStream out, boolean isPatched) throws IOException {
|
||||
@ -70,17 +76,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
UniversalFile dir = new UniversalFile(this.dir, "SubServers");
|
||||
dir.mkdir();
|
||||
if (!(new UniversalFile(dir, "sync.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());
|
||||
System.out.println("SubServers > Created ./SubServers/sync.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "sync.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "sync.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());
|
||||
System.out.println("SubServers > Updated ./SubServers/sync.yml");
|
||||
}
|
||||
ConfigUpdater.updateConfig(new UniversalFile(dir, "sync.yml"));
|
||||
config = new YAMLConfig(new UniversalFile(dir, "sync.yml"));
|
||||
|
||||
subprotocol = SubProtocol.get();
|
||||
getPluginManager().registerListener(null, this);
|
||||
|
||||
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
||||
@ -93,26 +93,41 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public void startListeners() {
|
||||
try {
|
||||
redis = getPluginManager().getPlugin("RedisBungee") != null;
|
||||
ConfigUpdater.updateConfig(new UniversalFile(dir, "SubServers:sync.yml"));
|
||||
config.reload();
|
||||
|
||||
Cipher cipher = null;
|
||||
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
|
||||
if (config.get().getSection("Settings").getSection("SubData").getRawString("Password", "").length() == 0) {
|
||||
System.out.println("SubData > Cannot encrypt connection without a password");
|
||||
} else if (!SubDataClient.getCiphers().keySet().contains(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption").toUpperCase().replace('-', '_').replace(' ', '_'))) {
|
||||
System.out.println("SubData > Unknown encryption type: " + config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
} else {
|
||||
cipher = SubDataClient.getCipher(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
||||
subprotocol.unregisterCipher("AES");
|
||||
subprotocol.unregisterCipher("AES-128");
|
||||
subprotocol.unregisterCipher("AES-192");
|
||||
subprotocol.unregisterCipher("AES-256");
|
||||
subprotocol.unregisterCipher("RSA");
|
||||
api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", null);
|
||||
|
||||
if (config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) {
|
||||
subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||
|
||||
System.out.println("SubData > AES Encryption Available");
|
||||
}
|
||||
if (new UniversalFile(dir, "SubServers:subdata.rsa.key").exists()) {
|
||||
try {
|
||||
subprotocol.registerCipher("RSA", new RSA(new UniversalFile(dir, "SubServers:subdata.rsa.key")));
|
||||
System.out.println("SubData > RSA Encryption Available");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
subdata = new SubDataClient(this, config.get().getSection("Settings").getSection("SubData").getRawString("Name", null),
|
||||
InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
||||
|
||||
reconnect = true;
|
||||
System.out.println("SubData > ");
|
||||
connect();
|
||||
|
||||
super.startListeners();
|
||||
|
||||
if (UPnP.isUPnPAvailable()) {
|
||||
if (config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true)) for (ListenerInfo listener : getConfig().getListeners()) {
|
||||
if (config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Proxy", true)) for (ListenerInfo listener : getConfig().getListeners()) {
|
||||
UPnP.openPortTCP(listener.getHost().getPort());
|
||||
}
|
||||
} else {
|
||||
@ -128,8 +143,13 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void connect() throws IOException {
|
||||
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
|
||||
}
|
||||
|
||||
private void post() {
|
||||
if (config.get().getSection("Settings").getBoolean("Override-Bungee-Commands", true)) {
|
||||
if (config.get().getMap("Settings").getBoolean("Override-Bungee-Commands", true)) {
|
||||
getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get());
|
||||
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
|
||||
}
|
||||
@ -143,12 +163,12 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
ObjectMap<String> tags = new ObjectMap<String>(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
List<Version> versions = new LinkedList<Version>();
|
||||
|
||||
Version updversion = version;
|
||||
int updcount = 0;
|
||||
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||
for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||
Collections.sort(versions);
|
||||
for (Version version : versions) {
|
||||
if (version.compareTo(updversion) > 0) {
|
||||
@ -232,7 +252,15 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
System.out.println("SubServers > Resetting Server Data");
|
||||
servers.clear();
|
||||
|
||||
subdata.destroy(0);
|
||||
reconnect = false;
|
||||
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
|
||||
tmp.addAll(subdata.values());
|
||||
for (SubDataClient client : tmp) if (client != null) {
|
||||
client.close();
|
||||
Util.isException(client::waitFor);
|
||||
}
|
||||
subdata.clear();
|
||||
subdata.put(0, null);
|
||||
|
||||
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||
@ -301,7 +329,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallback(ServerKickEvent e) {
|
||||
if (e.getPlayer() instanceof UserConnection && config.get().getSection("Settings").getBoolean("Smart-Fallback", true)) {
|
||||
if (e.getPlayer() instanceof UserConnection && config.get().getMap("Settings").getBoolean("Smart-Fallback", true)) {
|
||||
Map<String, ServerInfo> fallbacks;
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
fallbacks = SmartReconnectHandler.getFallbackServers(e.getPlayer().getPendingConnection().getListener());
|
||||
@ -339,6 +367,15 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void resetLimbo(PlayerDisconnectEvent e) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
SubCommand.players.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Integer, UUID> getSubDataAsMap(net.ME1312.SubServers.Sync.Network.API.Server server) {
|
||||
HashMap<Integer, UUID> map = new HashMap<Integer, UUID>();
|
||||
ObjectMap<Integer> subdata = new ObjectMap<Integer>((Map<Integer, ?>) server.getRaw().getObject("subdata"));
|
||||
for (Integer channel : subdata.getKeys()) map.put(channel, subdata.getUUID(channel));
|
||||
return map;
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
@ -347,11 +384,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
if (server != null) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getSubData(), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
System.out.println("SubServers > Added SubServer: " + e.getServer());
|
||||
} else {
|
||||
servers.put(server.getName().toLowerCase(), new ServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getSubData(), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
System.out.println("SubServers > Added Server: " + e.getServer());
|
||||
}
|
||||
} else System.out.println("PacketDownloadServerInfo(" + e.getServer() + ") returned with an invalid response");
|
||||
@ -364,10 +401,10 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
if (current == null || !current.getSignature().equals(server.getSignature())) {
|
||||
if (server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer) {
|
||||
servers.put(server.getName().toLowerCase(), new SubServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getSubData(), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist(), ((net.ME1312.SubServers.Sync.Network.API.SubServer) server).isRunning()));
|
||||
} else {
|
||||
servers.put(server.getName().toLowerCase(), new ServerContainer(server.getSignature(), server.getName(), server.getDisplayName(), server.getAddress(),
|
||||
server.getSubData(), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
getSubDataAsMap(server), server.getMotd(), server.isHidden(), server.isRestricted(), server.getWhitelist()));
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Added "+((server instanceof net.ME1312.SubServers.Sync.Network.API.SubServer)?"Sub":"")+"Server: " + server.getName());
|
||||
@ -402,7 +439,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
server.setDisplayName(e.getEdit().get().asString());
|
||||
break;
|
||||
case "motd":
|
||||
server.setMotd(e.getEdit().get().asColoredString('&'));
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', e.getEdit().get().asString()));
|
||||
break;
|
||||
case "restricted":
|
||||
server.setRestricted(e.getEdit().get().asBoolean());
|
||||
@ -420,12 +457,16 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
((SubServerContainer) servers.get(e.getServer().toLowerCase())).setRunning(true);
|
||||
}
|
||||
|
||||
public void connect(ServerContainer server, String address) {
|
||||
if (server != null) server.setSubData(address);
|
||||
public void connect(ServerContainer server, int channel, UUID address) {
|
||||
if (server != null) {
|
||||
server.setSubData(address, channel);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect(ServerContainer server) {
|
||||
if (server != null) server.setSubData(null);
|
||||
public void disconnect(ServerContainer server, int channel) {
|
||||
if (server != null) {
|
||||
server.setSubData(null, channel);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
|
Loading…
Reference in New Issue
Block a user