mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-01-25 09:01:23 +01:00
Implement Multi-Channel SubData
This commit is contained in:
parent
1952e7b940
commit
504dc7bac4
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w16a</version>
|
||||
<version>19w19b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w18a</version>
|
||||
<version>19w19c</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.SerializableClientHandler;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||
@ -11,7 +11,6 @@ import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExAddServer;
|
||||
@ -26,14 +25,15 @@ import java.util.*;
|
||||
/**
|
||||
* External Host Class
|
||||
*/
|
||||
public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
public class ExternalHost extends Host implements ClientHandler {
|
||||
private HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
private HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
private String name;
|
||||
protected boolean available;
|
||||
private boolean enabled;
|
||||
private InetAddress address;
|
||||
private SubCreator creator;
|
||||
private String directory;
|
||||
protected NamedContainer<Boolean, SubDataClient> client;
|
||||
private LinkedList<PacketObjectOut> queue;
|
||||
private boolean clean;
|
||||
protected SubPlugin plugin;
|
||||
@ -54,51 +54,69 @@ public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
super(plugin, name, enabled, ports, log, address, directory, gitBash);
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
this.available = false;
|
||||
this.enabled = enabled;
|
||||
this.address = address;
|
||||
this.client = new NamedContainer<Boolean, SubDataClient>(false, null);
|
||||
this.creator = new ExternalSubCreator(this, ports, log, gitBash);
|
||||
this.directory = directory;
|
||||
this.queue = new LinkedList<PacketObjectOut>();
|
||||
this.clean = false;
|
||||
|
||||
setSubData(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataClient getSubData() {
|
||||
return client.get();
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubData(DataClient client) {
|
||||
this.client = new NamedContainer<Boolean, SubDataClient>(false, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
public void removeSubData(DataClient client) {
|
||||
for (Integer channel : Util.getBackwards(subdata, (SubDataClient) client)) setSubData(null, channel);
|
||||
}
|
||||
|
||||
protected void queue(PacketObjectOut... packet) {
|
||||
for (PacketObjectOut p : packet) if (client.get() == null || client.name() == false) {
|
||||
for (PacketObjectOut p : packet) if (getSubData()[0] == null || !available) {
|
||||
queue.add(p);
|
||||
} else {
|
||||
client.get().sendPacket(p);
|
||||
((SubDataClient) getSubData()[0]).sendPacket(p);
|
||||
}
|
||||
}
|
||||
private void requeue() {
|
||||
SubDataClient client = (SubDataClient) getSubData()[0];
|
||||
if (!clean) {
|
||||
client.get().sendPacket(new PacketOutExReset("Prevent Desync"));
|
||||
client.sendPacket(new PacketOutExReset("Prevent Desync"));
|
||||
clean = true;
|
||||
}
|
||||
for (SubServer server : servers.values()) {
|
||||
client.get().sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||
client.sendPacket(new PacketExAddServer(server.getName(), server.isEnabled(), server.getAddress().getPort(), server.isLogging(), server.getPath(), ((ExternalSubServer) server).exec, server.getStopCommand(), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null));
|
||||
}
|
||||
while (queue.size() != 0) {
|
||||
client.get().sendPacket(queue.get(0));
|
||||
client.sendPacket(queue.get(0));
|
||||
queue.remove(0);
|
||||
}
|
||||
client.rename(true);
|
||||
available = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return this.client.name();
|
||||
return available;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +66,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (host.client.name()) host.queue(new PacketExConfigureHost(host.plugin, host));
|
||||
if (host.available) host.queue(new PacketExConfigureHost(host.plugin, host));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,7 +195,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
@Override
|
||||
public void terminate(String name) {
|
||||
if (this.thread.keySet().contains(name.toLowerCase())) {
|
||||
((SubDataClient) host.getSubData()).sendPacket(new PacketExCreateServer(name.toLowerCase()));
|
||||
((SubDataClient) host.getSubData()[0]).sendPacket(new PacketExCreateServer(name.toLowerCase()));
|
||||
thread.remove(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
@ -211,7 +211,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
|
||||
@Override
|
||||
public void waitFor(String name) throws InterruptedException {
|
||||
while (this.thread.keySet().contains(name.toLowerCase()) && host.client.get() != null) {
|
||||
while (this.thread.keySet().contains(name.toLowerCase()) && host.getSubData()[0] != null) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
|
||||
@Override
|
||||
public void waitFor() throws InterruptedException {
|
||||
while (running && host.client.get() != null) {
|
||||
while (running && host.getSubData()[0] != null) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.ME1312.SubServers.Bungee.Host;
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.Galaxi.Library.ExtraDataHandler;
|
||||
@ -12,6 +13,7 @@ import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -448,7 +450,11 @@ public abstract class Host implements ExtraDataHandler {
|
||||
servers.set(server.getName(), server.forSubData());
|
||||
}
|
||||
hinfo.set("servers", servers);
|
||||
if (this instanceof ClientHandler && ((ClientHandler) this).getSubData() != null) hinfo.set("subdata", ((ClientHandler) this).getSubData().getID());
|
||||
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;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.SerializableClientHandler;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
@ -19,11 +18,11 @@ import java.util.*;
|
||||
/**
|
||||
* Proxy Class
|
||||
*/
|
||||
public class Proxy implements SerializableClientHandler, ExtraDataHandler {
|
||||
public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
private HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
private ObjectMap<String> extra = new ObjectMap<String>();
|
||||
private final String signature;
|
||||
private boolean persistent = true;
|
||||
private SubDataClient client = null;
|
||||
private String nick = null;
|
||||
private final String name;
|
||||
|
||||
@ -36,22 +35,41 @@ public class Proxy implements SerializableClientHandler, ExtraDataHandler {
|
||||
if (name.contains(" ")) throw new IllegalArgumentException("Proxy names cannot have spaces: " + name);
|
||||
this.name = name;
|
||||
this.signature = SubAPI.getInstance().signAnonymousObject();
|
||||
|
||||
setSubData(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataClient getSubData() {
|
||||
return client;
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setSubData(DataClient client) {
|
||||
this.client = (SubDataClient) client;
|
||||
if (client == null && !persistent) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
|
||||
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
|
||||
DataClient[] subdata = getSubData();
|
||||
if (subdata[0] == null && subdata.length <= 1 && !persistent) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubRemoveProxyEvent(this));
|
||||
SubAPI.getInstance().getInternals().proxies.remove(getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubData(DataClient client) {
|
||||
for (Integer channel : Util.getBackwards(subdata, (SubDataClient) client)) setSubData(null, channel);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +184,9 @@ public class Proxy implements SerializableClientHandler, ExtraDataHandler {
|
||||
}
|
||||
info.set("players", players);
|
||||
info.set("redis", isRedis());
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getID());
|
||||
LinkedList<UUID> subdata = new LinkedList<UUID>();
|
||||
for (DataClient client : getSubData()) subdata.add((client == null)?null:client.getID());
|
||||
info.set("subdata", subdata);
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
return info;
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Bungee.Host;
|
||||
import net.ME1312.Galaxi.Library.ExtraDataHandler;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.ME1312.SubData.Server.SerializableClientHandler;
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -13,7 +13,15 @@ import java.util.UUID;
|
||||
/**
|
||||
* Server Interface
|
||||
*/
|
||||
public interface Server extends ServerInfo, SerializableClientHandler, ExtraDataHandler {
|
||||
public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler {
|
||||
|
||||
/**
|
||||
* Link a SubData Client to this Object
|
||||
*
|
||||
* @param client Client to Link
|
||||
* @param channel Channel ID
|
||||
*/
|
||||
void setSubData(DataClient client, int channel);
|
||||
|
||||
/**
|
||||
* Get the Display Name of this Server
|
||||
|
@ -25,8 +25,8 @@ import java.util.*;
|
||||
* Server Class
|
||||
*/
|
||||
public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
private HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
private ObjectMap<String> extra = new ObjectMap<String>();
|
||||
private SubDataClient client = null;
|
||||
private String nick = null;
|
||||
private List<String> groups = new ArrayList<String>();
|
||||
private List<UUID> whitelist = new ArrayList<UUID>();
|
||||
@ -40,23 +40,42 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
signature = SubAPI.getInstance().signAnonymousObject();
|
||||
SubAPI.getInstance().getSubDataNetwork().getProtocol().whitelist(getAddress().getAddress().getHostAddress());
|
||||
this.hidden = hidden;
|
||||
|
||||
setSubData(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataClient getSubData() {
|
||||
return client;
|
||||
public DataClient[] getSubData() {
|
||||
LinkedList<Integer> keys = new LinkedList<Integer>(subdata.keySet());
|
||||
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||
Collections.sort(keys);
|
||||
for (Integer channel : keys) channels.add(subdata.get(channel));
|
||||
return channels.toArray(new DataClient[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubData(DataClient client) {
|
||||
this.client = (SubDataClient) client;
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
((SubDataClient) proxy.getSubData()).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
public void setSubData(DataClient client, int channel) {
|
||||
if (channel < 0) throw new IllegalArgumentException("Subchannel ID cannot be less than zero");
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(channel) == null)) {
|
||||
if (client != null || channel == 0) {
|
||||
subdata.put(channel, (SubDataClient) client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
} else {
|
||||
subdata.remove(channel);
|
||||
}
|
||||
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
args.set("channel", channel);
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
}
|
||||
}
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubData(DataClient client) {
|
||||
for (Integer channel : Util.getBackwards(subdata, (SubDataClient) client)) setSubData(null, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -174,14 +193,14 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
public void whitelist(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
whitelist.add(player);
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) ((SubDataClient) proxy.getSubData()).sendPacket(new PacketOutExUpdateWhitelist(getName(), true, player));
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) ((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExUpdateWhitelist(getName(), true, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unwhitelist(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
whitelist.remove(player);
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) ((SubDataClient) proxy.getSubData()).sendPacket(new PacketOutExUpdateWhitelist(getName(), false, player));
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) ((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExUpdateWhitelist(getName(), false, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -237,7 +256,9 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
players.set(player.get().toString(), pinfo);
|
||||
}
|
||||
info.set("players", players);
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getID());
|
||||
LinkedList<UUID> subdata = new LinkedList<UUID>();
|
||||
for (DataClient client : getSubData()) subdata.add((client == null)?null:client.getID());
|
||||
info.set("subdata", subdata);
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
return info;
|
||||
|
@ -77,7 +77,7 @@ public class SmartReconnectHandler implements ReconnectHandler {
|
||||
if (server instanceof Server) {
|
||||
if (!((Server) server).isHidden()) confidence++;
|
||||
if (!((Server) server).isRestricted()) confidence++;
|
||||
if (((Server) server).getSubData() != null) confidence++;
|
||||
if (((Server) server).getSubData()[0] != null) confidence++;
|
||||
} if (server instanceof SubServer) {
|
||||
if (!((SubServer) server).isRunning()) valid = false;
|
||||
}
|
||||
|
@ -1,14 +1,17 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.External.ExternalHost;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.Host.ServerContainer;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -50,10 +53,12 @@ public class PacketLinkExHost implements PacketObjectIn<Integer>, PacketObjectOu
|
||||
Map<String, Host> hosts = plugin.api.getHosts();
|
||||
if (hosts.keySet().contains(data.getRawString(0x0000).toLowerCase())) {
|
||||
Host host = hosts.get(data.getRawString(0x0000).toLowerCase());
|
||||
if (host instanceof ClientHandler) {
|
||||
if (((ClientHandler) host).getSubData() == null) {
|
||||
client.setHandler((ClientHandler) host);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Host: " + host.getName());
|
||||
if (host instanceof ExternalHost) {
|
||||
Integer channel = data.getInt(0x0001);
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ExternalHost.class.getDeclaredField("subdata"), host), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
((ExternalHost) host).setSubData(client, channel);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" (Sub "+channel+")":""));
|
||||
client.sendPacket(new PacketLinkExHost(0));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(3));
|
||||
|
@ -8,8 +8,10 @@ import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.Host.ServerContainer;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -54,18 +56,24 @@ public class PacketLinkProxy implements PacketObjectIn<Integer>, PacketObjectOut
|
||||
try {
|
||||
Map<String, Proxy> proxies = plugin.api.getProxies();
|
||||
String name = ((data.contains(0x0000))?data.getRawString(0x0000):null);
|
||||
Integer channel = data.getInt(0x0001);
|
||||
Proxy proxy;
|
||||
if (name != null && proxies.keySet().contains(name.toLowerCase()) && proxies.get(name.toLowerCase()).getSubData() == null) {
|
||||
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));
|
||||
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);
|
||||
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));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 2));
|
||||
|
||||
client.setHandler(proxy);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName());
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketLinkProxy(null, 1));
|
||||
e.printStackTrace();
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.ServerContainer;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
@ -10,6 +12,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -64,15 +67,16 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
String name = (data.contains(0x0000))?data.getRawString(0x0000):null;
|
||||
Integer port = (data.contains(0x0001))?data.getInt(0x0001):null;
|
||||
Integer channel = data.getInt(0x0002);
|
||||
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
Server server;
|
||||
if (name != null && servers.keySet().contains(name.toLowerCase())) {
|
||||
link(client, servers.get(name.toLowerCase()));
|
||||
link(client, servers.get(name.toLowerCase()), channel);
|
||||
} else if (port != null) {
|
||||
if ((server = search(new InetSocketAddress(client.getAddress().getAddress(), port))) != null) {
|
||||
link(client, server);
|
||||
link(client, server, channel);
|
||||
} else {
|
||||
throw new ServerLinkException("There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + port);
|
||||
}
|
||||
@ -91,10 +95,11 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
|
||||
}
|
||||
}
|
||||
|
||||
private void link(SubDataClient client, Server server) {
|
||||
if (server.getSubData() == null) {
|
||||
client.setHandler(server);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName());
|
||||
private void link(SubDataClient client, Server server, int channel) {
|
||||
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ServerContainer.class.getDeclaredField("subdata"), server), null);
|
||||
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
|
||||
server.setSubData(client, channel);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName() + ((channel > 0)?" (Sub "+channel+")":""));
|
||||
if (server instanceof SubServer && !((SubServer) server).isRunning()) {
|
||||
System.out.println("SubServers > Sending shutdown signal to rogue SubServer: " + server.getName());
|
||||
client.sendPacket(new PacketOutExReset("Rogue SubServer Detected"));
|
||||
|
@ -247,9 +247,9 @@ public final class SubCommand extends CommandX {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : plugin.api.getProxies().values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (proxy.getSubData() != null) {
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
@ -280,7 +280,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage(" -> Address: " + ChatColor.WHITE + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(" -> Running: " + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Players: " + ChatColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(" -> MOTD: " + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
|
||||
@ -325,7 +325,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage(" -> Available: " + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Address: " + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host instanceof ClientHandler && ((ClientHandler) host).getSubData() != null) sender.sendMessage(" -> Connected: " + ChatColor.GREEN + "yes");
|
||||
if (host instanceof ClientHandler && ((ClientHandler) host).getSubData()[0] != null) sender.sendMessage(" -> Connected: " + ChatColor.GREEN + "yes" + ((((ClientHandler) host).getSubData().length > 1)?ChatColor.AQUA+" +"+(((ClientHandler) host).getSubData().length-1):""));
|
||||
sender.sendMessage(" -> SubServers: " + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" - " + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(" -> Templates: " + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
@ -344,7 +344,7 @@ public final class SubCommand extends CommandX {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage("SubServers > Info on Proxy: " + ChatColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Connected: " + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Redis: " + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(" -> Players: " + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(" -> Signature: " + ChatColor.AQUA + proxy.getSignature());
|
||||
|
@ -46,6 +46,7 @@ import java.nio.file.Files;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -424,8 +425,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
if (bungee.get().getMap("servers").getMap(name).getKeys().contains("extra"))
|
||||
for (String extra : config.get().getMap("servers").getMap(name).getMap("extra").getKeys()) server.addExtra(extra, config.get().getMap("servers").getMap(name).getMap("extra").getObject(extra));
|
||||
if (server.getSubData() != null)
|
||||
((SubDataClient) server.getSubData()).sendPacket(new PacketOutExReload(null));
|
||||
if (server.getSubData()[0] != null)
|
||||
((SubDataClient) server.getSubData()[0]).sendPacket(new PacketOutExReload(null));
|
||||
ukeys.add(name.toLowerCase());
|
||||
servers++;
|
||||
}
|
||||
@ -563,8 +564,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
if (status) {
|
||||
for (Host host : api.getHosts().values()) if (host instanceof ClientHandler && ((ClientHandler) host).getSubData() != null) ((SubDataClient) ((ClientHandler) host).getSubData()).sendPacket(new PacketOutExReload(null));
|
||||
for (Server server : api.getServers().values()) if (server.getSubData() != null) ((SubDataClient) server.getSubData()).sendPacket(new PacketOutExReload(null));
|
||||
for (Host host : api.getHosts().values()) if (host instanceof ClientHandler && ((ClientHandler) host).getSubData()[0] != null) ((SubDataClient) ((ClientHandler) host).getSubData()[0]).sendPacket(new PacketOutExReload(null));
|
||||
for (Server server : api.getServers().values()) if (server.getSubData()[0] != null) ((SubDataClient) server.getSubData()[0]).sendPacket(new PacketOutExReload(null));
|
||||
}
|
||||
|
||||
System.out.println("SubServers > " + ((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + ((proxies > 1)?proxies+" Proxies, ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
||||
@ -586,7 +587,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
server.start();
|
||||
if (ar.size() > 0 && scd > 0) {
|
||||
long sleep = Calendar.getInstance().getTime().getTime();
|
||||
while (running && begin == resetDate && server.getSubData() == null && Calendar.getInstance().getTime().getTime() - sleep < scd) {
|
||||
while (running && begin == resetDate && server.getSubData()[0] == null && Calendar.getInstance().getTime().getTime() - sleep < scd) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
}
|
||||
|
@ -48,13 +48,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w16a</version>
|
||||
<version>19w19b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w18a</version>
|
||||
<version>19w19c</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -6,6 +6,7 @@ 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.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
@ -62,7 +63,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
String title = event.getView().getTitle();
|
||||
|
||||
if (gui.open && event.getClickedInventory() != null && title != null) {
|
||||
if (plugin.subdata == null) {
|
||||
if (plugin.api.getSubDataNetwork()[0] == null) {
|
||||
new IllegalStateException("SubData is not connected").printStackTrace();
|
||||
} else if (Util.isException(() -> plugin.api.getLangChannels())) {
|
||||
new IllegalStateException("There are no lang options available at this time").printStackTrace();
|
||||
@ -109,7 +110,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + ((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]).getHost().toLowerCase())) {
|
||||
player.closeInventory();
|
||||
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
|
||||
plugin.subdata.sendPacket(new PacketCreateServer(player.getUniqueId(), ((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]), data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player.getUniqueId(), ((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]), data -> {
|
||||
gui.back();
|
||||
}));
|
||||
} else {
|
||||
@ -319,7 +320,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.start.*") || player.hasPermission("subservers.subserver.start." + ((String) gui.lastVisitedObjects[0]).toLowerCase())) {
|
||||
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
|
||||
plugin.subdata.sendPacket(new PacketStartServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], data -> {
|
||||
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start.Title"));
|
||||
Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 30);
|
||||
}));
|
||||
@ -341,7 +342,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], false, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], false, data -> {
|
||||
if (data.getInt(0x0001) != 0) {
|
||||
gui.reopen();
|
||||
listening.set(false);
|
||||
@ -365,7 +366,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], false, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], false, data -> {
|
||||
if (data.getInt(0x0001) != 0) {
|
||||
gui.reopen();
|
||||
listening.set(false);
|
||||
@ -379,7 +380,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
player.sendMessage(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command.Message"));
|
||||
input.put(player.getUniqueId(), m -> {
|
||||
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
|
||||
plugin.subdata.sendPacket(new PacketCommandServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player.getUniqueId(), (String) gui.lastVisitedObjects[0], (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), data -> {
|
||||
gui.reopen();
|
||||
}));
|
||||
});
|
||||
|
@ -396,7 +396,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
block = createItem("STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", (short) 5);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GREEN + plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Version"));
|
||||
blockMeta.setLore(Arrays.asList(ChatColor.GRAY + ((options.getVersion() == null)?"Auto Select":"Minecraft "+options.getVersion().toString())));
|
||||
blockMeta.setLore(Arrays.asList(ChatColor.GRAY + ((options.getVersion() == null)?"Unspecified":"Minecraft "+options.getVersion().toString())));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(32, block);
|
||||
|
@ -311,7 +311,7 @@ public class BungeeChat {
|
||||
hoverm = new LinkedList<TextComponent>();
|
||||
message = new TextComponent(proxy.getDisplayName());
|
||||
hover = new TextComponent(proxy.getDisplayName());
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
hover.setColor(ChatColor.GREEN);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
@ -321,7 +321,7 @@ public class BungeeChat {
|
||||
}
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size())));
|
||||
} else if (proxy.getSubData() != null) {
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
message.setColor(ChatColor.AQUA);
|
||||
hover.setColor(ChatColor.AQUA);
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||
|
@ -49,16 +49,16 @@ public class Host {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()).sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getMap(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client ID
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client ID (or null if unlinked/unsupported)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public UUID getSubData() {
|
||||
return raw.getUUID("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,7 +275,7 @@ public class Host {
|
||||
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()).sendPacket(new PacketAddServer(player, name, enabled, getName(), port, motd, log, directory, executable, stopcmd, hidden, restricted, data -> {
|
||||
((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) {
|
||||
@ -412,7 +412,7 @@ public class Host {
|
||||
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()).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -598,7 +598,7 @@ public class Host {
|
||||
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()).sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
|
@ -38,16 +38,16 @@ public class Proxy {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()).sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getMap(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client ID
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client ID (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public UUID getSubData() {
|
||||
return raw.getUUID("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,16 +37,16 @@ public class Server {
|
||||
*/
|
||||
public void refresh() {
|
||||
String name = getName();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()).sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getMap(name))));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getMap(name))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the SubData Client ID
|
||||
* Gets the SubData Client Channel IDs
|
||||
*
|
||||
* @return SubData Client ID (or null if not linked)
|
||||
* @return SubData Client Channel ID Array
|
||||
*/
|
||||
public UUID getSubData() {
|
||||
return raw.getUUID("subdata", null);
|
||||
public UUID[] getSubData() {
|
||||
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +122,7 @@ public class SubCreator {
|
||||
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();
|
||||
((SubDataClient) 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(0x0001));
|
||||
} catch (Throwable e) {
|
||||
|
@ -71,7 +71,7 @@ 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();
|
||||
((SubDataClient) 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(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -116,7 +116,7 @@ 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();
|
||||
((SubDataClient) 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(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -161,7 +161,7 @@ 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();
|
||||
((SubDataClient) 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(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -207,7 +207,7 @@ 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();
|
||||
((SubDataClient) 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(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -330,7 +330,7 @@ public class SubServer extends Server {
|
||||
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()).sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
|
||||
((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);
|
||||
|
@ -15,9 +15,10 @@ import org.bukkit.Bukkit;
|
||||
*/
|
||||
public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int channel;
|
||||
|
||||
/**
|
||||
* New PacketLinkServer
|
||||
* New PacketLinkServer (In)
|
||||
*
|
||||
* @param plugin SubServers.Client
|
||||
*/
|
||||
@ -25,12 +26,24 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
/**
|
||||
* New PacketLinkServer (Out)
|
||||
*
|
||||
* @param plugin SubServers.Client
|
||||
* @param channel Channel ID
|
||||
*/
|
||||
public PacketLinkServer(SubPlugin plugin, int channel) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
if (plugin.api.getName() != null) json.set(0x0000, plugin.api.getName());
|
||||
json.set(0x0001, Bukkit.getServer().getPort());
|
||||
json.set(0x0002, channel);
|
||||
return json;
|
||||
}
|
||||
|
||||
@ -41,8 +54,10 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
|
||||
if (data.contains(0x0000)) {
|
||||
Util.reflect(SubAPI.class.getDeclaredField("name"), plugin.api, data.getRawString(0x0000));
|
||||
}
|
||||
client.sendPacket(new PacketDownloadLang());
|
||||
Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent(client));
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] == client) {
|
||||
client.sendPacket(new PacketDownloadLang());
|
||||
Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent(client));
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
} else {
|
||||
Bukkit.getLogger().info("SubData > Could not link name with server" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
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.Client.Bukkit.Event.SubNetworkDisconnectEvent;
|
||||
@ -11,7 +13,9 @@ import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
@ -110,16 +114,56 @@ public class SubProtocol extends SubDataProtocol {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SubDataClient openChannel(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);
|
||||
|
||||
int channel = 1;
|
||||
while (map.keySet().contains(channel)) channel++;
|
||||
final int fc = channel;
|
||||
|
||||
map.put(fc, subdata);
|
||||
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(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 {
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
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.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin)));
|
||||
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin, 0)));
|
||||
subdata.on.closed(client -> {
|
||||
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
|
||||
if (plugin.isEnabled()) Bukkit.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) {
|
||||
Bukkit.getLogger().info("SubData > Attempting reconnect in " + reconnect + " seconds");
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Util.reflect(SubPlugin.class.getDeclaredMethod("connect"), plugin);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getTargetException() instanceof IOException) {
|
||||
Bukkit.getLogger().info("SubData > Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this, reconnect * 20);
|
||||
} else e.printStackTrace();
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, reconnect * 20);
|
||||
}
|
||||
});
|
||||
|
||||
return subdata;
|
||||
|
@ -14,7 +14,6 @@ import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import javax.xml.ws.Response;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
@ -80,7 +79,7 @@ public final class SubAPI {
|
||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new 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.getKeys()) {
|
||||
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
|
||||
@ -105,7 +104,7 @@ 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.getKeys().size() > 0) {
|
||||
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
@ -129,7 +128,7 @@ public final class SubAPI {
|
||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||
if (Util.isNull(callback)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
plugin.subdata.sendPacket(new 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.getKeys()) {
|
||||
ArrayList<Server> servers = new ArrayList<Server>();
|
||||
@ -178,7 +177,7 @@ 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.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||
@ -210,7 +209,7 @@ 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.getKeys()) {
|
||||
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||
@ -239,7 +238,7 @@ 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.getKeys().size() > 0) {
|
||||
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||
@ -290,7 +289,7 @@ public final class SubAPI {
|
||||
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()).sendPacket(new PacketAddServer(player, name, ip, port, motd, hidden, restricted, data -> {
|
||||
((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) {
|
||||
@ -417,7 +416,7 @@ public final class SubAPI {
|
||||
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()).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
@ -463,7 +462,7 @@ 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.getKeys()) {
|
||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
|
||||
@ -488,7 +487,7 @@ 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.getKeys().size() > 0) {
|
||||
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||
@ -512,7 +511,7 @@ 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 != null) {
|
||||
proxy = new Proxy(data);
|
||||
@ -537,7 +536,7 @@ 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.getKeys()) {
|
||||
players.add(new NamedContainer<String, UUID>(data.getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||
@ -558,8 +557,12 @@ public final class SubAPI {
|
||||
*
|
||||
* @return SubData Network Manager
|
||||
*/
|
||||
public DataClient 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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
@ -43,7 +44,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
label = "/" + label;
|
||||
if (plugin.subdata == null) {
|
||||
if (plugin.api.getSubDataNetwork()[0] == null) {
|
||||
new IllegalStateException("SubData is not connected").printStackTrace();
|
||||
if (!(sender instanceof ConsoleCommandSender)) sender.sendMessage(ChatColor.RED + "An exception has occurred while running this command");
|
||||
} else if (plugin.lang == null) {
|
||||
@ -201,9 +202,9 @@ public final class SubCommand extends BukkitCommand {
|
||||
message = " (master)";
|
||||
for (Proxy proxy : proxies.values()) {
|
||||
message += div;
|
||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
||||
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||
message += ChatColor.GREEN;
|
||||
} else if (proxy.getSubData() != null) {
|
||||
} else if (proxy.getSubData()[0] != null) {
|
||||
message += ChatColor.AQUA;
|
||||
} else if (proxy.isRedis()) {
|
||||
message += ChatColor.WHITE;
|
||||
@ -236,7 +237,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port") + ChatColor.AQUA.toString() + server.getAddress().getPort());
|
||||
if (server instanceof SubServer) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running") + ((((SubServer) server).isRunning())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((server.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((server.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((server.getSubData().length > 1)?ChatColor.AQUA+" +"+(server.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + server.getPlayers().size() + " online");
|
||||
}
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD") + ChatColor.WHITE + ChatColor.stripColor(server.getMotd()));
|
||||
@ -279,7 +280,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available") + ((host.isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((host.isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address") + ChatColor.WHITE + host.getAddress().getHostAddress());
|
||||
if (host.getSubData() != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ChatColor.GREEN + "yes");
|
||||
if (host.getSubData()[0] != null) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ChatColor.GREEN + "yes" + ((host.getSubData().length > 1)?ChatColor.AQUA+" +"+(host.getSubData().length-1):""));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers") + ((host.getSubServers().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getSubServers().keySet().size()));
|
||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ((subserver.isEnabled())?ChatColor.WHITE:ChatColor.GRAY) + subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')'));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates") + ((host.getCreator().getTemplates().keySet().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + host.getCreator().getTemplates().keySet().size()));
|
||||
@ -297,7 +298,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
if (proxy != null) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy") + ChatColor.WHITE + proxy.getDisplayName());
|
||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + proxy.getName());
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData() != null)?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected") + ((proxy.getSubData()[0] != null)?ChatColor.GREEN+"yes"+((proxy.getSubData().length > 1)?ChatColor.AQUA+" +"+(proxy.getSubData().length-1):""):ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") + ((proxy.isRedis())?ChatColor.GREEN:ChatColor.RED+"un") + "available");
|
||||
if (proxy.isRedis()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players") + ChatColor.AQUA + proxy.getPlayers().size() + " online");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature") + ChatColor.AQUA + proxy.getSignature());
|
||||
@ -341,7 +342,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else if (args[0].equalsIgnoreCase("start")) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission("subservers.subserver.start.*") || sender.hasPermission("subservers.subserver.start." + args[1].toLowerCase())) {
|
||||
plugin.subdata.sendPacket(new PacketStartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Unknown"));
|
||||
@ -379,7 +380,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else if (args[0].equalsIgnoreCase("restart")) {
|
||||
if (args.length > 1) {
|
||||
if ((sender.hasPermission("subservers.subserver.stop.*") || sender.hasPermission("subservers.subserver.stop." + args[1].toLowerCase())) && (sender.hasPermission("subservers.subserver.start.*") || sender.hasPermission("subservers.subserver.start." + args[1].toLowerCase()))) {
|
||||
Runnable starter = () -> plugin.subdata.sendPacket(new PacketStartServer(null, args[1], data -> {
|
||||
Runnable starter = () -> ((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, args[1], data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
@ -440,9 +441,9 @@ public final class SubCommand extends BukkitCommand {
|
||||
|
||||
if (plugin.api.getName().equalsIgnoreCase(args[1])) {
|
||||
listening.set(false);
|
||||
plugin.subdata.sendPacket(new PacketRestartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], stopper));
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], stopper));
|
||||
} else {
|
||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], false, stopper));
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], false, stopper));
|
||||
}
|
||||
} else if (!(sender.hasPermission("subservers.subserver.stop.*") || sender.hasPermission("subservers.subserver.stop." + args[1].toLowerCase()))) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.stop." + args[1].toLowerCase()));
|
||||
@ -455,7 +456,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission("subservers.subserver.stop.*") || sender.hasPermission("subservers.subserver.stop." + args[1].toLowerCase())) {
|
||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], false, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], false, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Unknown"));
|
||||
@ -481,7 +482,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else if (args[0].equalsIgnoreCase("kill") || args[0].equalsIgnoreCase("terminate")) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission("subservers.subserver.terminate.*") || sender.hasPermission("subservers.subserver.terminate." + args[1].toLowerCase())) {
|
||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], true, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], true, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Unknown"));
|
||||
@ -516,7 +517,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} while ((i + 1) != args.length);
|
||||
}
|
||||
final String cmd = str;
|
||||
plugin.subdata.sendPacket(new PacketCommandServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], cmd, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketCommandServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], cmd, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Unknown"));
|
||||
@ -545,7 +546,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
if (args.length > 5 && Util.isException(() -> Integer.parseInt(args[5]))) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"));
|
||||
} else {
|
||||
plugin.subdata.sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], args[2], args[3], (args.length > 4)?new Version(args[4]):null, (args.length > 5)?Integer.parseInt(args[5]):null, data -> {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], args[2], args[3], (args.length > 4)?new Version(args[4]):null, (args.length > 5)?Integer.parseInt(args[5]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
|
@ -3,6 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.Encryption.AES;
|
||||
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.DefaultUIHandler;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
@ -25,25 +26,24 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* SubServers Client Plugin Class
|
||||
*/
|
||||
public final class SubPlugin extends JavaPlugin {
|
||||
protected HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public YAMLConfig config;
|
||||
public SubDataClient subdata = null;
|
||||
public SubProtocol subprotocol;
|
||||
|
||||
public UIHandler gui = null;
|
||||
public final Version version;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
|
||||
private boolean reconnect = false;
|
||||
|
||||
public SubPlugin() {
|
||||
super();
|
||||
version = Version.fromString(getDescription().getVersion());
|
||||
@ -120,8 +120,14 @@ public final class SubPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reload(boolean notifyPlugins) throws IOException {
|
||||
if (subdata != null)
|
||||
subdata.close();
|
||||
reconnect = false;
|
||||
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
|
||||
tmp.addAll(subdata.values());
|
||||
for (SubDataClient client : tmp) {
|
||||
client.close();
|
||||
Util.isException(client::waitFor);
|
||||
}
|
||||
subdata.clear();
|
||||
|
||||
config.reload();
|
||||
|
||||
@ -149,9 +155,9 @@ public final class SubPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
reconnect = true;
|
||||
System.out.println("SubData > ");
|
||||
subdata = 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]));
|
||||
connect();
|
||||
|
||||
if (notifyPlugins) {
|
||||
List<Runnable> listeners = api.reloadListeners;
|
||||
@ -167,6 +173,11 @@ public final class SubPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
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])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Plugin
|
||||
*/
|
||||
@ -174,8 +185,15 @@ public final class SubPlugin extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
if (subdata != null) try {
|
||||
setEnabled(false);
|
||||
subdata.close();
|
||||
subdata.waitFor();
|
||||
reconnect = false;
|
||||
|
||||
ArrayList<SubDataClient> temp = new ArrayList<SubDataClient>();
|
||||
temp.addAll(subdata.values());
|
||||
for (SubDataClient client : temp) {
|
||||
client.close();
|
||||
client.waitFor();
|
||||
}
|
||||
subdata.clear();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user