mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-22 10:15:52 +01:00
Begin rewrite for SubData 2
This commit is contained in:
parent
463861744c
commit
3dab84c0eb
@ -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>19w16a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w16b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -136,6 +142,8 @@
|
||||
<reportOutputDirectory>${basedir}/../Javadoc/SubServers.Bungee</reportOutputDirectory>
|
||||
<additionalOptions>-Xdoclint:none</additionalOptions>
|
||||
<links>
|
||||
<link>https://src.me1312.net/jenkins/job/GalaxiEngine/javadoc/GalaxiUtil/</link>
|
||||
<link>https://src.me1312.net/jenkins/job/SubData/javadoc/Server/</link>
|
||||
<link>https://ci.md-5.net/job/BungeeCord/ws/api/target/apidocs/</link>
|
||||
</links>
|
||||
</configuration>
|
||||
|
@ -1,9 +1,8 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -3,8 +3,8 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
@ -33,7 +33,7 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, Host host, String name, SubCreator.ServerTemplate template, Version version, int port) {
|
||||
if (Util.isNull(host, name, template, version, port)) throw new NullPointerException();
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Bungee.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.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
@ -18,7 +18,7 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private Server server;
|
||||
private NamedContainer<String, YAMLValue> edit;
|
||||
private NamedContainer<String, ObjectMapValue> edit;
|
||||
private boolean perm;
|
||||
|
||||
/**
|
||||
@ -31,11 +31,11 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
|
||||
*/
|
||||
public SubEditServerEvent(UUID player, Server 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>(edit.name(), section.get("."));
|
||||
this.perm = permanent;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
|
||||
*
|
||||
* @return Edit to be made
|
||||
*/
|
||||
public NamedContainer<String, YAMLValue> getEdit() {
|
||||
public NamedContainer<String, ObjectMapValue> getEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.DataServer;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataServer;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
@ -13,16 +16,16 @@ import java.net.InetAddress;
|
||||
*/
|
||||
public class SubNetworkConnectEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private SubDataServer network;
|
||||
private InetAddress address;
|
||||
private DataServer network;
|
||||
private DataClient client;
|
||||
|
||||
/**
|
||||
* SubData Network Connect Event
|
||||
*/
|
||||
public SubNetworkConnectEvent(SubDataServer network, InetAddress address) {
|
||||
if (Util.isNull(network, address)) throw new NullPointerException();
|
||||
public SubNetworkConnectEvent(DataServer network, DataClient client) {
|
||||
if (Util.isNull(network, client)) throw new NullPointerException();
|
||||
this.network = network;
|
||||
this.address = address;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,17 +33,17 @@ public class SubNetworkConnectEvent extends Event implements SubEvent, Cancellab
|
||||
*
|
||||
* @return SubData Network
|
||||
*/
|
||||
public SubDataServer getNetwork() {
|
||||
public DataServer getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the address of the connecting client
|
||||
* Get the connecting client
|
||||
*
|
||||
* @return Client address
|
||||
* @return Client
|
||||
*/
|
||||
public InetAddress getAddress() {
|
||||
return address;
|
||||
public DataClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,25 +1,30 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.DataServer;
|
||||
import net.ME1312.SubData.Server.Library.DisconnectReason;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataServer;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public class SubNetworkDisconnectEvent extends Event implements SubEvent {
|
||||
private SubDataServer network;
|
||||
private Client client;
|
||||
private DataServer network;
|
||||
private DataClient client;
|
||||
private DisconnectReason reason;
|
||||
|
||||
/**
|
||||
* SubData Network Disconnect Event
|
||||
*/
|
||||
public SubNetworkDisconnectEvent(SubDataServer network, Client client) {
|
||||
if (Util.isNull(network, client)) throw new NullPointerException();
|
||||
public SubNetworkDisconnectEvent(DataServer network, DataClient client, DisconnectReason reason) {
|
||||
if (Util.isNull(network, client, reason)) throw new NullPointerException();
|
||||
this.network = network;
|
||||
this.client = client;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +32,7 @@ public class SubNetworkDisconnectEvent extends Event implements SubEvent {
|
||||
*
|
||||
* @return SubData Network
|
||||
*/
|
||||
public SubDataServer getNetwork() {
|
||||
public DataServer getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
@ -36,8 +41,16 @@ public class SubNetworkDisconnectEvent extends Event implements SubEvent {
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
public Client getClient() {
|
||||
public DataClient getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reason the client disconnected
|
||||
*
|
||||
* @return Disconnect Reason
|
||||
*/
|
||||
public DisconnectReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Cancellable;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
/**
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.JNA;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Executable Handler Class
|
||||
|
@ -1,23 +1,23 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
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;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
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;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExDeleteServer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExRemoveServer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutReset;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReset;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -26,15 +26,15 @@ import java.util.*;
|
||||
/**
|
||||
* External Host Class
|
||||
*/
|
||||
public class ExternalHost extends Host implements ClientHandler {
|
||||
public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
private HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private InetAddress address;
|
||||
private SubCreator creator;
|
||||
private String directory;
|
||||
protected NamedContainer<Boolean, Client> client;
|
||||
private LinkedList<PacketOut> queue;
|
||||
protected NamedContainer<Boolean, SubDataClient> client;
|
||||
private LinkedList<PacketObjectOut> queue;
|
||||
private boolean clean;
|
||||
protected SubPlugin plugin;
|
||||
|
||||
@ -56,26 +56,26 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
this.address = address;
|
||||
this.client = new NamedContainer<Boolean, Client>(false, null);
|
||||
this.client = new NamedContainer<Boolean, SubDataClient>(false, null);
|
||||
this.creator = new ExternalSubCreator(this, ports, log, gitBash);
|
||||
this.directory = directory;
|
||||
this.queue = new LinkedList<PacketOut>();
|
||||
this.queue = new LinkedList<PacketObjectOut>();
|
||||
this.clean = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client getSubData() {
|
||||
public DataClient getSubData() {
|
||||
return client.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubData(Client client) {
|
||||
this.client = new NamedContainer<Boolean, Client>(false, client);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) client.setHandler(this);
|
||||
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);
|
||||
}
|
||||
|
||||
protected void queue(PacketOut... packet) {
|
||||
for (PacketOut p : packet) if (client.get() == null || client.name() == false) {
|
||||
protected void queue(PacketObjectOut... packet) {
|
||||
for (PacketObjectOut p : packet) if (client.get() == null || client.name() == false) {
|
||||
queue.add(p);
|
||||
} else {
|
||||
client.get().sendPacket(p);
|
||||
@ -83,7 +83,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}
|
||||
private void requeue() {
|
||||
if (!clean) {
|
||||
client.get().sendPacket(new PacketOutReset("Prevent Desync"));
|
||||
client.get().sendPacket(new PacketOutExReset("Prevent Desync"));
|
||||
clean = true;
|
||||
}
|
||||
for (SubServer server : servers.values()) {
|
||||
@ -170,7 +170,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
getSubServer(server).waitFor();
|
||||
}
|
||||
queue(new PacketExRemoveServer(server, data -> {
|
||||
if (data.getInt("r") == 0) {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
servers.remove(server.toLowerCase());
|
||||
}
|
||||
}));
|
||||
@ -189,13 +189,89 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
getSubServer(server).terminate();
|
||||
}
|
||||
queue(new PacketExRemoveServer(server, data -> {
|
||||
if (data.getInt("r") == 0) {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
servers.remove(server.toLowerCase());
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
String server = servers.get(name.toLowerCase()).getName();
|
||||
|
||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
if (getSubServer(server).isRunning()) {
|
||||
getSubServer(server).stop();
|
||||
getSubServer(server).waitFor();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
queue(new PacketExDeleteServer(server, info, true, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
} else {
|
||||
System.out.println("SubServers > Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceRecycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
String server = servers.get(name.toLowerCase()).getName();
|
||||
|
||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (getSubServer(server).isRunning()) {
|
||||
getSubServer(server).terminate();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
queue(new PacketExDeleteServer(server, info, true, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
for (String group : getSubServer(server).getGroups()) getSubServer(server).removeGroup(group);
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
} else {
|
||||
System.out.println("SubServers > Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
@ -210,12 +286,12 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getSection("Servers").getKeys().contains(server))?plugin.config.get().getSection("Servers").getSection(server).clone():new YAMLSection();
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getSection("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getSection("Servers").remove(server);
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -223,8 +299,8 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
queue(new PacketExDeleteServer(server, info, data -> {
|
||||
if (data.getInt("r") == 0) {
|
||||
queue(new PacketExDeleteServer(server, info, false, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
} else {
|
||||
@ -247,12 +323,12 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getSection("Servers").getKeys().contains(server))?plugin.config.get().getSection("Servers").getSection(server).clone():new YAMLSection();
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getSection("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getSection("Servers").remove(server);
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -260,8 +336,8 @@ public class ExternalHost extends Host implements ClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Removing Files...");
|
||||
queue(new PacketExDeleteServer(server, info, data -> {
|
||||
if (data.getInt("r") == 0) {
|
||||
queue(new PacketExDeleteServer(server, info, false, data -> {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
for (String group : getSubServer(server).getGroups()) getSubServer(server).removeGroup(group);
|
||||
servers.remove(server.toLowerCase());
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
|
@ -1,17 +1,18 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.Galaxi.Library.*;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.Internal.InternalSubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Library.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExConfigureHost;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExCreateServer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -55,8 +56,8 @@ public class ExternalSubCreator extends SubCreator {
|
||||
if (new UniversalFile(host.plugin.dir, "SubServers:Templates").exists()) for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
|
||||
try {
|
||||
if (file.isDirectory() && !file.getName().endsWith(".x")) {
|
||||
YAMLSection config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getSection("Template", new YAMLSection()):new YAMLSection();
|
||||
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getSection("Build", new YAMLSection()), config.getSection("Settings", new YAMLSection()));
|
||||
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()):new ObjectMap<String>();
|
||||
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
|
||||
templates.put(file.getName().toLowerCase(), template);
|
||||
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
|
||||
}
|
||||
@ -70,7 +71,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
|
||||
@Override
|
||||
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, template, version)) throw new NullPointerException();
|
||||
if (Util.isNull(name, template)) throw new NullPointerException();
|
||||
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name)) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
@ -94,15 +95,15 @@ public class ExternalSubCreator extends SubCreator {
|
||||
logger.start();
|
||||
host.queue(new PacketExCreateServer(name, template, version, port, logger.getExternalAddress(), data -> {
|
||||
try {
|
||||
if (data.getInt("r") == 0) {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
System.out.println(name + "/Creator > Saving...");
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
|
||||
host.plugin.exServers.remove(name.toLowerCase());
|
||||
|
||||
YAMLSection server = new YAMLSection();
|
||||
YAMLSection config = new YAMLSection((Map<String, ?>) convert(data.getSection("c").get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
|
||||
new NamedContainer<>("$address$", data.getSection("c").getRawString("\033address", "null")), new NamedContainer<>("$port$", Integer.toString(fport))));
|
||||
ObjectMap<String> server = new ObjectMap<String>();
|
||||
ObjectMap<String> config = new ObjectMap<String>((Map<String, ?>) convert(data.getMap(0x0002).get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", (version != null)?version.toString().replace(" ", "@"):""),
|
||||
new NamedContainer<>("$address$", new ObjectMap<String>((Map<String, ?>) data.getObject(0x0002)).getRawString("\033address", "null")), new NamedContainer<>("$port$", Integer.toString(fport))));
|
||||
|
||||
config.remove("\033address");
|
||||
|
||||
@ -123,15 +124,15 @@ public class ExternalSubCreator extends SubCreator {
|
||||
server.set("Hidden", false);
|
||||
server.setAll(config);
|
||||
|
||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), fport, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), fport, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||
server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
||||
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
||||
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) subserver.setStopAction(action);
|
||||
if (server.contains("Extra")) for (String extra : server.getSection("Extra").getKeys())
|
||||
subserver.addExtra(extra, server.getSection("Extra").getObject(extra));
|
||||
host.plugin.config.get().getSection("Servers").set(name, server);
|
||||
if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys())
|
||||
subserver.addExtra(extra, server.getMap("Extra").getObject(extra));
|
||||
host.plugin.config.get().getMap("Servers").set(name, server);
|
||||
host.plugin.config.save();
|
||||
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
|
||||
subserver.start();
|
||||
@ -144,7 +145,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + "/Creator > " + data.getString("m"));
|
||||
System.out.println(name + "/Creator > " + data.getString(0x0003));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -194,7 +195,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
@Override
|
||||
public void terminate(String name) {
|
||||
if (this.thread.keySet().contains(name.toLowerCase())) {
|
||||
host.getSubData().sendPacket(new PacketExCreateServer(name.toLowerCase()));
|
||||
((SubDataClient) host.getSubData()).sendPacket(new PacketExCreateServer(name.toLowerCase()));
|
||||
thread.remove(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketInExLogMessage;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -14,7 +14,6 @@ import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
@ -1,18 +1,18 @@
|
||||
package net.ME1312.SubServers.Bungee.Host.External;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
|
||||
import net.ME1312.SubServers.Bungee.Event.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExUpdateServer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -111,14 +111,16 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
history.clear();
|
||||
running = false;
|
||||
|
||||
if (stopaction == StopAction.REMOVE_SERVER || stopaction == StopAction.DELETE_SERVER) {
|
||||
if (stopaction == StopAction.REMOVE_SERVER || stopaction == StopAction.RECYCLE_SERVER || stopaction == StopAction.DELETE_SERVER) {
|
||||
try {
|
||||
if (stopaction == StopAction.DELETE_SERVER) {
|
||||
if (stopaction == StopAction.RECYCLE_SERVER) {
|
||||
host.recycleSubServer(getName());
|
||||
} else if (stopaction == StopAction.DELETE_SERVER) {
|
||||
host.deleteSubServer(getName());
|
||||
} else {
|
||||
try {
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").remove(getName());
|
||||
if (host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -175,16 +177,16 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int edit(UUID player, YAMLSection edit) {
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
public int edit(UUID player, ObjectMap<String> edit) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
YAMLSection pending = edit.clone();
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
YAMLValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, YAMLValue>(key, value), true);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), true);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
@ -193,10 +195,10 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
YAMLSection config = this.host.plugin.config.get().getSection("Servers").getSection(getName());
|
||||
this.host.plugin.config.get().getSection("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getSection("Servers").set(server.getName(), config);
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.config.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -215,11 +217,11 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).remove("Display");
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Display", getDisplayName());
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
@ -230,8 +232,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isBoolean()) {
|
||||
if (enabled != value.asBoolean()) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_ENABLED, (Boolean) value.asBoolean()));
|
||||
enabled = value.asBoolean();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Enabled", isEnabled());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -240,8 +242,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Group", value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -252,8 +254,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", server.getHost().getName());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -266,8 +268,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Port", server.getAddress().getPort());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -277,9 +279,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, value.asColoredString('&'));
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Motd", value.asString());
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -289,8 +291,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isBoolean()) {
|
||||
if (log.get() != value.asBoolean()) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_LOGGING, (Boolean) value.asBoolean()));
|
||||
log.set(value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Log", isLogging());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -301,8 +303,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", server.getPath());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Directory", server.getPath());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -315,8 +317,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -333,8 +335,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isString()) {
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_STOP_COMMAND, value.asRawString()));
|
||||
stopcmd = value.asRawString();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Command", getStopCommand());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -345,8 +347,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Action", getStopAction().toString());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -355,8 +357,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "auto-run":
|
||||
if (value.isBoolean()) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -364,12 +366,12 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (String oname : value.asStringList()) {
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Incompatible", value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -378,8 +380,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Restricted", isRestricted());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -388,8 +390,8 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Hidden", isHidden());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -422,7 +424,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
}
|
||||
if (!isRunning() && forward == null && state) start(player);
|
||||
return c;
|
||||
} private <V> void waitFor(Util.ReturnRunnable<V> method, V value) throws InterruptedException {
|
||||
} private <V> void waitFor(ReturnRunnable<V> method, V value) throws InterruptedException {
|
||||
while (method.run() != value) {
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.ExtraDataHandler;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.ME1312.Galaxi.Library.ExtraDataHandler;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -21,7 +19,7 @@ import java.util.UUID;
|
||||
* Host Layout Class
|
||||
*/
|
||||
public abstract class Host implements ExtraDataHandler {
|
||||
private YAMLSection extra = new YAMLSection();
|
||||
private ObjectMap<String> extra = new ObjectMap<String>();
|
||||
private final String signature;
|
||||
private String nick = null;
|
||||
|
||||
@ -42,7 +40,7 @@ public abstract class Host implements ExtraDataHandler {
|
||||
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new InvalidHostException("Port range is not bound");
|
||||
if (Util.isNull(plugin, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
|
||||
signature = plugin.api.signAnonymousObject();
|
||||
SubDataServer.allowConnection(address.getHostAddress());
|
||||
SubAPI.getInstance().getSubDataNetwork().getProtocol().whitelist(address.getHostAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,13 +303,51 @@ public abstract class Host implements ExtraDataHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Removal of a SubServer
|
||||
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Removing
|
||||
* @param name SubServer Name
|
||||
*/
|
||||
public abstract boolean forceRemoveSubServer(UUID player, String name) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Delete a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean recycleSubServer(String name) throws InterruptedException {
|
||||
return recycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean recycleSubServer(UUID player, String name) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean forceRecycleSubServer(String name) throws InterruptedException {
|
||||
return forceRecycleSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||
*
|
||||
* @param player Player Deleting
|
||||
* @param name SubServer Name
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean forceRecycleSubServer(UUID player, String name) throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Delete a SubServer
|
||||
*
|
||||
@ -338,7 +374,7 @@ public abstract class Host implements ExtraDataHandler {
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean forceDeleteSubServer(String name) throws InterruptedException {
|
||||
return deleteSubServer(null, name);
|
||||
return forceDeleteSubServer(null, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -372,13 +408,13 @@ public abstract class Host implements ExtraDataHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return extra.get(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection getExtra() {
|
||||
public ObjectMap<String> getExtra() {
|
||||
return extra.clone();
|
||||
}
|
||||
|
||||
@ -388,10 +424,8 @@ public abstract class Host implements ExtraDataHandler {
|
||||
extra.remove(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String toString() {
|
||||
YAMLSection hinfo = new YAMLSection();
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> hinfo = new ObjectMap<String>();
|
||||
hinfo.set("type", "Host");
|
||||
hinfo.set("name", getName());
|
||||
hinfo.set("display", getDisplayName());
|
||||
@ -400,21 +434,21 @@ public abstract class Host implements ExtraDataHandler {
|
||||
hinfo.set("address", getAddress().getHostAddress());
|
||||
hinfo.set("dir", getPath());
|
||||
|
||||
YAMLSection cinfo = new YAMLSection();
|
||||
YAMLSection templates = new YAMLSection();
|
||||
ObjectMap<String> cinfo = new ObjectMap<String>();
|
||||
ObjectMap<String> templates = new ObjectMap<String>();
|
||||
for (SubCreator.ServerTemplate template : getCreator().getTemplates().values())
|
||||
templates.set(template.getName(), new YAMLSection(new Gson().fromJson(template.toString(), Map.class)));
|
||||
templates.set(template.getName(), template.forSubData());
|
||||
cinfo.set("templates", templates);
|
||||
hinfo.set("creator", cinfo);
|
||||
|
||||
YAMLSection servers = new YAMLSection();
|
||||
ObjectMap<String> servers = new ObjectMap<String>();
|
||||
for (SubServer server : getSubServers().values()) {
|
||||
servers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
servers.set(server.getName(), server.forSubData());
|
||||
}
|
||||
hinfo.set("servers", servers);
|
||||
if (this instanceof ClientHandler && ((ClientHandler) this).getSubData() != null) hinfo.set("subdata", ((ClientHandler) this).getSubData().getAddress().toString());
|
||||
if (this instanceof ClientHandler && ((ClientHandler) this).getSubData() != null) hinfo.set("subdata", ((ClientHandler) this).getSubData().getID());
|
||||
hinfo.set("signature", signature);
|
||||
hinfo.set("extra", getExtra());
|
||||
return hinfo.toJSON();
|
||||
return hinfo;
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,16 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.io.File;
|
||||
@ -103,7 +104,7 @@ public class InternalHost extends Host {
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
servers.put(name.toLowerCase(), server);
|
||||
if (UPnP.isUPnPAvailable() && plugin.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(port);
|
||||
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(port);
|
||||
return server;
|
||||
} else {
|
||||
return null;
|
||||
@ -143,6 +144,96 @@ public class InternalHost extends Host {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
String server = servers.get(name.toLowerCase()).getName();
|
||||
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
|
||||
if (removeSubServer(player, server)) {
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + server.toLowerCase());
|
||||
try {
|
||||
if (from.exists()) {
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
if (to.exists()) {
|
||||
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.copyDirectory(from, to);
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
}, "SubServers.Bungee::Internal_Server_Recycler(" + name + ')').start();
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forceRecycleSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
String server = servers.get(name.toLowerCase()).getName();
|
||||
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
|
||||
if (forceRemoveSubServer(player, server)) {
|
||||
new Thread(() -> {
|
||||
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + server.toLowerCase());
|
||||
try {
|
||||
if (from.exists()) {
|
||||
System.out.println("SubServers > Moving Files...");
|
||||
if (to.exists()) {
|
||||
if (to.isDirectory()) Util.deleteDirectory(to);
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.copyDirectory(from, to);
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"), false);
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("SubServers > Deleted SubServer: " + server);
|
||||
}, "SubServers.Bungee::Internal_Server_Recycler(" + name + ')').start();
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSubServer(UUID player, String name) throws InterruptedException {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
@ -159,7 +250,6 @@ public class InternalHost extends Host {
|
||||
else to.delete();
|
||||
}
|
||||
to.mkdirs();
|
||||
Util.copyDirectory(from, to);
|
||||
Util.deleteDirectory(from);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -167,17 +257,17 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getSection("Servers").getKeys().contains(server))?plugin.config.get().getSection("Servers").getSection(server).clone():new YAMLSection();
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getSection("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getSection("Servers").remove(server);
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
writer.write(info.toJSON());
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -212,17 +302,17 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getSection("Servers").getKeys().contains(server))?plugin.config.get().getSection("Servers").getSection(server).clone():new YAMLSection();
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getSection("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getSection("Servers").remove(server);
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"), false);
|
||||
writer.write(info.toJSON());
|
||||
writer.write(info.toJSON().toString());
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -2,27 +2,27 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.Galaxi.Library.*;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.SubCreatorException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -59,8 +59,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||
YAMLSection server = new YAMLSection();
|
||||
private ObjectMap<String> build(File dir, ServerTemplate template, List<ServerTemplate> history) throws SubCreatorException {
|
||||
ObjectMap<String> server = new ObjectMap<String>();
|
||||
Version version = this.version;
|
||||
HashMap<String, String> var = new HashMap<String, String>();
|
||||
boolean error = false;
|
||||
@ -69,7 +69,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
for (String other : template.getBuildOptions().getStringList("Import", new ArrayList<String>())) {
|
||||
if (templates.keySet().contains(other.toLowerCase())) {
|
||||
if (templates.get(other.toLowerCase()).isEnabled()) {
|
||||
YAMLSection config = build(dir, templates.get(other.toLowerCase()), history);
|
||||
ObjectMap<String> config = build(dir, templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
} else {
|
||||
@ -89,34 +89,36 @@ public class InternalSubCreator extends SubCreator {
|
||||
var.put("name", name);
|
||||
var.put("template", template.getName());
|
||||
var.put("type", template.getType().toString().toUpperCase());
|
||||
var.put("version", version.toString());
|
||||
if (version != null) var.put("version", version.toString());
|
||||
var.put("address", host.getAddress().getHostAddress());
|
||||
var.put("port", Integer.toString(port));
|
||||
switch (template.getType()) {
|
||||
case SPONGE:
|
||||
case FORGE:
|
||||
System.out.println(name + File.separator + "Creator > Searching Versions...");
|
||||
YAMLSection spversionmanifest = new YAMLSection(new Gson().fromJson("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
if (version != null) {
|
||||
System.out.println(name + File.separator + "Creator > Searching Versions...");
|
||||
ObjectMap<String> spversionmanifest = new ObjectMap<String>(new Gson().fromJson("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
|
||||
YAMLSection spprofile = null;
|
||||
Version spversion = null;
|
||||
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
|
||||
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
||||
spprofile = profile;
|
||||
spversion = new Version(profile.getRawString("version"));
|
||||
ObjectMap<String> spprofile = null;
|
||||
Version spversion = null;
|
||||
for (ObjectMap<String> profile : spversionmanifest.getMapList("versions")) {
|
||||
if (profile.getMap("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
|
||||
spprofile = profile;
|
||||
spversion = new Version(profile.getRawString("version"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (spversion == null)
|
||||
throw new InvalidServerException("Cannot find Sponge version for Minecraft " + version.toString());
|
||||
System.out.println(name + File.separator + "Creator > Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||
if (spversion == null)
|
||||
throw new InvalidServerException("Cannot find Sponge version for Minecraft " + version.toString());
|
||||
System.out.println(name + File.separator + "Creator > Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||
|
||||
if (template.getType() == ServerType.FORGE) {
|
||||
Version mcfversion = new Version(spprofile.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
|
||||
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
|
||||
if (template.getType() == ServerType.FORGE) {
|
||||
Version mcfversion = new Version(((spprofile.getMap("dependencies").getRawString("forge").contains("-"))?"":spprofile.getMap("dependencies").getRawString("minecraft") + '-') + spprofile.getMap("dependencies").getRawString("forge"));
|
||||
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
|
||||
|
||||
var.put("mcf_version", mcfversion.toString());
|
||||
var.put("mcf_version", mcfversion.toString());
|
||||
}
|
||||
var.put("sp_version", spversion.toString());
|
||||
}
|
||||
var.put("sp_version", spversion.toString());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -141,7 +143,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, template.getBuildOptions().getRawString("Executable"))).directory(dir);
|
||||
pb.environment().putAll(var);
|
||||
process = pb.start();
|
||||
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString() + ".log");
|
||||
log.file = new File(dir, "SubCreator-" + template.getName() + ((version != null)?"-"+version.toString():"") + ".log");
|
||||
log.process = process;
|
||||
log.start();
|
||||
|
||||
@ -173,8 +175,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
public void run() {
|
||||
UniversalFile dir = new UniversalFile(new File(host.getPath()), name);
|
||||
dir.mkdirs();
|
||||
YAMLSection server = new YAMLSection();
|
||||
YAMLSection config;
|
||||
ObjectMap<String> server = new ObjectMap<String>();
|
||||
ObjectMap<String> config;
|
||||
try {
|
||||
config = build(dir, template, new LinkedList<>());
|
||||
generateProperties(dir, port);
|
||||
@ -192,7 +194,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
|
||||
host.plugin.exServers.remove(name.toLowerCase());
|
||||
|
||||
config = new YAMLSection((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
config = new ObjectMap<String>((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
|
||||
new NamedContainer<>("$address$", host.getAddress().getHostAddress()), new NamedContainer<>("$port$", Integer.toString(port))));
|
||||
|
||||
@ -213,15 +215,15 @@ public class InternalSubCreator extends SubCreator {
|
||||
server.set("Hidden", false);
|
||||
server.setAll(config);
|
||||
|
||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||
SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), server.getRawString("Directory"),
|
||||
server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
|
||||
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
|
||||
for (String group : server.getStringList("Group")) subserver.addGroup(group);
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) subserver.setStopAction(action);
|
||||
if (server.contains("Extra")) for (String extra : server.getSection("Extra").getKeys())
|
||||
subserver.addExtra(extra, server.getSection("Extra").getObject(extra));
|
||||
host.plugin.config.get().getSection("Servers").set(name, server);
|
||||
if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys())
|
||||
subserver.addExtra(extra, server.getMap("Extra").getObject(extra));
|
||||
host.plugin.config.get().getMap("Servers").set(name, server);
|
||||
host.plugin.config.save();
|
||||
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
|
||||
subserver.start();
|
||||
@ -287,8 +289,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
|
||||
try {
|
||||
if (file.isDirectory() && !file.getName().endsWith(".x")) {
|
||||
YAMLSection config = (new UniversalFile(file, "template.yml").exists()) ? new YAMLConfig(new UniversalFile(file, "template.yml")).get().getSection("Template", new YAMLSection()) : new YAMLSection();
|
||||
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getSection("Build", new YAMLSection()), config.getSection("Settings", new YAMLSection()));
|
||||
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists()) ? new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()) : new ObjectMap<String>();
|
||||
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
|
||||
templates.put(file.getName().toLowerCase(), template);
|
||||
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
|
||||
}
|
||||
@ -302,7 +304,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
|
||||
if (Util.isNull(name, template, version)) throw new NullPointerException();
|
||||
if (Util.isNull(name, template)) throw new NullPointerException();
|
||||
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name)) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
@ -450,6 +452,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
private void generateClient(File dir, ServerType type, String name) throws IOException {
|
||||
if (new UniversalFile(dir, "subservers.client").exists()) {
|
||||
Files.delete(new UniversalFile(dir, "subservers.client").toPath());
|
||||
if (type == ServerType.SPIGOT) {
|
||||
if (!new UniversalFile(dir, "plugins").exists()) new UniversalFile(dir, "plugins").mkdirs();
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
@ -458,13 +461,16 @@ public class InternalSubCreator extends SubCreator {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
}
|
||||
YAMLSection config = new YAMLSection();
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subservers.client"), false);
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
|
||||
config.set("Name", name);
|
||||
config.set("Address", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1").replace("0.0.0.0", "127.0.0.1"));
|
||||
config.set("Password", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password", ""));
|
||||
config.set("Encryption", host.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE"));
|
||||
writer.write(config.toJSON());
|
||||
config.set("Address", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1").replace("0.0.0.0", "127.0.0.1"));
|
||||
config.set("Password", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password", ""));
|
||||
writer.write(config.toJSON().toString());
|
||||
writer.close();
|
||||
|
||||
if (new UniversalFile("SubServers:subdata.rsa.key").exists()) {
|
||||
Files.copy(new UniversalFile("SubServers:subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
private void generateProperties(File dir, int port) throws IOException {
|
||||
|
@ -2,16 +2,14 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubLogger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -2,20 +2,20 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Event.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
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.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -147,14 +147,16 @@ public class InternalSubServer extends SubServerContainer {
|
||||
command = null;
|
||||
history.clear();
|
||||
|
||||
if (stopaction == StopAction.REMOVE_SERVER || stopaction == StopAction.DELETE_SERVER) {
|
||||
if (stopaction == StopAction.REMOVE_SERVER || stopaction == StopAction.RECYCLE_SERVER || stopaction == StopAction.DELETE_SERVER) {
|
||||
try {
|
||||
if (stopaction == StopAction.DELETE_SERVER) {
|
||||
if (stopaction == StopAction.RECYCLE_SERVER) {
|
||||
host.recycleSubServer(getName());
|
||||
} else if (stopaction == StopAction.DELETE_SERVER) {
|
||||
host.deleteSubServer(getName());
|
||||
} else {
|
||||
try {
|
||||
if (host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getSection("Servers").remove(getName());
|
||||
if (host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
host.plugin.config.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -255,16 +257,16 @@ public class InternalSubServer extends SubServerContainer {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int edit(UUID player, YAMLSection edit) {
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
public int edit(UUID player, ObjectMap<String> edit) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
YAMLSection pending = edit.clone();
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
YAMLValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, YAMLValue>(key, value), true);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), true);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
@ -273,10 +275,10 @@ public class InternalSubServer extends SubServerContainer {
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
YAMLSection config = this.host.plugin.config.get().getSection("Servers").getSection(getName());
|
||||
this.host.plugin.config.get().getSection("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getSection("Servers").set(server.getName(), config);
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.config.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -295,11 +297,11 @@ public class InternalSubServer extends SubServerContainer {
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).remove("Display");
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Display", getDisplayName());
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
@ -309,8 +311,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
enabled = value.asBoolean();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Enabled", isEnabled());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -319,8 +321,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Group", value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -330,8 +332,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", server.getHost().getName());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -343,8 +345,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Port", server.getAddress().getPort());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
forward = server;
|
||||
@ -354,9 +356,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, value.asColoredString('&'));
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Motd", value.asString());
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -365,8 +367,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
log.set(value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Log", isLogging());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -380,8 +382,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
}
|
||||
dir = value.asRawString();
|
||||
directory = new File(getHost().getPath(), value.asRawString());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", getPath());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Directory", getPath());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -394,8 +396,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
waitFor();
|
||||
}
|
||||
executable = value.asRawString();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -404,8 +406,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "stop-cmd":
|
||||
if (value.isString()) {
|
||||
stopcmd = value.asRawString();
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Command", getStopCommand());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -416,8 +418,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Stop-Action", getStopAction().toString());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -431,8 +433,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "auto-run":
|
||||
if (value.isBoolean()) {
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -440,12 +442,12 @@ public class InternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (String oname : value.asStringList()) {
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Incompatible", value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -454,8 +456,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Restricted", isRestricted());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
@ -464,8 +466,8 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Hidden", isHidden());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.config.save();
|
||||
}
|
||||
c++;
|
||||
|
@ -1,13 +1,15 @@
|
||||
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.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Bungee.Library.ExtraDataHandler;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.ExtraDataHandler;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -17,11 +19,11 @@ import java.util.*;
|
||||
/**
|
||||
* Proxy Class
|
||||
*/
|
||||
public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
private YAMLSection extra = new YAMLSection();
|
||||
public class Proxy implements SerializableClientHandler, ExtraDataHandler {
|
||||
private ObjectMap<String> extra = new ObjectMap<String>();
|
||||
private final String signature;
|
||||
private boolean persistent = true;
|
||||
private Client client = null;
|
||||
private SubDataClient client = null;
|
||||
private String nick = null;
|
||||
private final String name;
|
||||
|
||||
@ -37,19 +39,19 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client getSubData() {
|
||||
public DataClient getSubData() {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setSubData(Client client) {
|
||||
this.client = client;
|
||||
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());
|
||||
}
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) client.setHandler(this);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,13 +136,13 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return extra.get(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection getExtra() {
|
||||
public ObjectMap<String> getExtra() {
|
||||
return extra.clone();
|
||||
}
|
||||
|
||||
@ -151,22 +153,22 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection info = new YAMLSection();
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> info = new ObjectMap<String>();
|
||||
info.set("type", "Proxy");
|
||||
info.set("name", getName());
|
||||
info.set("display", getDisplayName());
|
||||
YAMLSection players = new YAMLSection();
|
||||
ObjectMap<String> players = new ObjectMap<String>();
|
||||
for (NamedContainer<String, UUID> player : getPlayers()) {
|
||||
YAMLSection pinfo = new YAMLSection();
|
||||
ObjectMap<String> pinfo = new ObjectMap<String>();
|
||||
pinfo.set("name", player.name());
|
||||
players.set(player.get().toString(), pinfo);
|
||||
}
|
||||
info.set("players", players);
|
||||
info.set("redis", isRedis());
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getAddress().toString());
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getID());
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
return info.toJSON();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.ExtraDataHandler;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
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.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -12,7 +13,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* Server Interface
|
||||
*/
|
||||
public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler {
|
||||
public interface Server extends ServerInfo, SerializableClientHandler, ExtraDataHandler {
|
||||
|
||||
/**
|
||||
* Get the Display Name of this Server
|
||||
|
@ -1,24 +1,23 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubData.Server.DataClient;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubEditServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLValue;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExRunEvent;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExUpdateWhitelist;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutRunEvent;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
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.*;
|
||||
|
||||
@ -26,8 +25,8 @@ import java.util.*;
|
||||
* Server Class
|
||||
*/
|
||||
public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
private YAMLSection extra = new YAMLSection();
|
||||
private Client client = null;
|
||||
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>();
|
||||
@ -39,25 +38,25 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
if (Util.isNull(name, address, motd, hidden, restricted)) throw new NullPointerException();
|
||||
if (name.contains(" ")) throw new InvalidServerException("Server names cannot have spaces: " + name);
|
||||
signature = SubAPI.getInstance().signAnonymousObject();
|
||||
SubDataServer.allowConnection(getAddress().getAddress().getHostAddress());
|
||||
SubAPI.getInstance().getSubDataNetwork().getProtocol().whitelist(getAddress().getAddress().getHostAddress());
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client getSubData() {
|
||||
public DataClient getSubData() {
|
||||
return client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubData(Client client) {
|
||||
this.client = client;
|
||||
public void setSubData(DataClient client) {
|
||||
this.client = (SubDataClient) client;
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", getName());
|
||||
if (client != null) args.set("address", client.getAddress().toString());
|
||||
proxy.getSubData().sendPacket(new PacketOutRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
((SubDataClient) proxy.getSubData()).sendPacket(new PacketOutExRunEvent((client != null)?SubNetworkConnectEvent.class:SubNetworkDisconnectEvent.class, args));
|
||||
}
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) client.setHandler(this);
|
||||
if (client != null && (client.getHandler() == null || !equals(client.getHandler()))) ((SubDataClient) client).setHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -175,14 +174,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) proxy.getSubData().sendPacket(new PacketOutExUpdateWhitelist(getName(), true, player));
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) ((SubDataClient) proxy.getSubData()).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) proxy.getSubData().sendPacket(new PacketOutExUpdateWhitelist(getName(), false, player));
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData() != null) ((SubDataClient) proxy.getSubData()).sendPacket(new PacketOutExUpdateWhitelist(getName(), false, player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -203,13 +202,13 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLValue getExtra(String handle) {
|
||||
public ObjectMapValue getExtra(String handle) {
|
||||
if (Util.isNull(handle)) throw new NullPointerException();
|
||||
return extra.get(handle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection getExtra() {
|
||||
public ObjectMap<String> getExtra() {
|
||||
return extra.clone();
|
||||
}
|
||||
|
||||
@ -220,8 +219,8 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection info = new YAMLSection();
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> info = new ObjectMap<String>();
|
||||
info.set("type", "Server");
|
||||
info.set("name", getName());
|
||||
info.set("display", getDisplayName());
|
||||
@ -231,17 +230,16 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
info.set("whitelist", whitelist);
|
||||
info.set("restricted", isRestricted());
|
||||
info.set("hidden", isHidden());
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getAddress().toString());
|
||||
YAMLSection players = new YAMLSection();
|
||||
ObjectMap<String> players = new ObjectMap<String>();
|
||||
for (NamedContainer<String, UUID> player : getGlobalPlayers()) {
|
||||
YAMLSection pinfo = new YAMLSection();
|
||||
ObjectMap<String> pinfo = new ObjectMap<String>();
|
||||
pinfo.set("name", player.name());
|
||||
players.set(player.get().toString(), pinfo);
|
||||
}
|
||||
info.set("players", players);
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getAddress().toString());
|
||||
if (getSubData() != null) info.set("subdata", getSubData().getID());
|
||||
info.set("signature", signature);
|
||||
info.set("extra", getExtra());
|
||||
return info.toJSON();
|
||||
return info;
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidTemplateException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
|
||||
@ -24,8 +23,8 @@ public abstract class SubCreator {
|
||||
private String icon;
|
||||
private File directory;
|
||||
private ServerType type;
|
||||
private YAMLSection build;
|
||||
private YAMLSection options;
|
||||
private ObjectMap<String> build;
|
||||
private ObjectMap<String> options;
|
||||
|
||||
/**
|
||||
* Create a SubCreator Template
|
||||
@ -35,7 +34,7 @@ public abstract class SubCreator {
|
||||
* @param build Build Options
|
||||
* @param options Configuration Options
|
||||
*/
|
||||
public ServerTemplate(String name, boolean enabled, String icon, File directory, YAMLSection build, YAMLSection options) {
|
||||
public ServerTemplate(String name, boolean enabled, String icon, File directory, ObjectMap<String> build, ObjectMap<String> options) {
|
||||
if (Util.isNull(name, enabled, directory, build, options)) throw new NullPointerException();
|
||||
if (name.contains(" ")) throw new InvalidTemplateException("Template names cannot have spaces: " + name);
|
||||
this.name = name;
|
||||
@ -137,7 +136,7 @@ public abstract class SubCreator {
|
||||
*
|
||||
* @return Build Options
|
||||
*/
|
||||
public YAMLSection getBuildOptions() {
|
||||
public ObjectMap<String> getBuildOptions() {
|
||||
return build;
|
||||
}
|
||||
|
||||
@ -146,19 +145,19 @@ public abstract class SubCreator {
|
||||
*
|
||||
* @return Configuration Options
|
||||
*/
|
||||
public YAMLSection getConfigOptions() {
|
||||
public ObjectMap<String> getConfigOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection tinfo = new YAMLSection();
|
||||
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> tinfo = new ObjectMap<String>();
|
||||
tinfo.set("enabled", isEnabled());
|
||||
tinfo.set("name", getName());
|
||||
tinfo.set("display", getDisplayName());
|
||||
tinfo.set("icon", getIcon());
|
||||
tinfo.set("type", getType().toString());
|
||||
return tinfo.toJSON();
|
||||
return tinfo;
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
@ -180,7 +179,7 @@ public abstract class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @return Success Status
|
||||
*/
|
||||
@ -192,7 +191,7 @@ public abstract class SubCreator {
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @return Success Status
|
||||
*/
|
||||
@ -205,7 +204,7 @@ public abstract class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @return Success Status
|
||||
*/
|
||||
@ -218,7 +217,7 @@ public abstract class SubCreator {
|
||||
*
|
||||
* @param name Server Name
|
||||
* @param template Server Template
|
||||
* @param version Server Version
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @return Success Status
|
||||
*/
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -17,6 +17,7 @@ public interface SubServer extends Server {
|
||||
NONE,
|
||||
RESTART,
|
||||
REMOVE_SERVER,
|
||||
RECYCLE_SERVER,
|
||||
DELETE_SERVER;
|
||||
|
||||
@Override
|
||||
@ -169,7 +170,7 @@ public interface SubServer extends Server {
|
||||
* @param edit Edits
|
||||
* @return Success Status
|
||||
*/
|
||||
default int edit(UUID player, YAMLSection edit) {
|
||||
default int edit(UUID player, ObjectMap<String> edit) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -179,7 +180,7 @@ public interface SubServer extends Server {
|
||||
* @param edit Edits
|
||||
* @return Success Status
|
||||
*/
|
||||
default int edit(YAMLSection edit) {
|
||||
default int edit(ObjectMap<String> edit) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -221,12 +222,12 @@ public interface SubServer extends Server {
|
||||
/**
|
||||
* If the Server is accepting requests to edit()
|
||||
*
|
||||
* @see #edit(YAMLSection)
|
||||
* @see #edit(UUID, YAMLSection)
|
||||
* @see #edit(ObjectMap<String>)
|
||||
* @see #edit(UUID, ObjectMap<String>)
|
||||
* @return Edit Status
|
||||
*/
|
||||
default boolean isEditable() {
|
||||
return edit(new YAMLSection()) >= 0;
|
||||
return edit(new ObjectMap<String>()) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,8 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
@ -51,7 +50,7 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
}
|
||||
|
||||
@Override
|
||||
public int edit(YAMLSection edit) {
|
||||
public int edit(ObjectMap<String> edit) {
|
||||
return edit(null, edit);
|
||||
}
|
||||
|
||||
@ -109,8 +108,8 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
@Override
|
||||
public String toString() {
|
||||
YAMLSection sinfo = new YAMLSection(new Gson().fromJson(super.toString(), Map.class));
|
||||
public ObjectMap<String> forSubData() {
|
||||
ObjectMap<String> sinfo = super.forSubData();
|
||||
sinfo.set("type", "SubServer");
|
||||
sinfo.set("host", getHost().getName());
|
||||
sinfo.set("enabled", isEnabled());
|
||||
@ -121,13 +120,13 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
sinfo.set("running", isRunning());
|
||||
sinfo.set("stop-cmd", getStopCommand());
|
||||
sinfo.set("stop-action", getStopAction().toString());
|
||||
sinfo.set("auto-run", SubAPI.getInstance().getInternals().config.get().getSection("Servers").getSection(getName(), new YAMLSection()).getBoolean("Run-On-Launch", false));
|
||||
sinfo.set("auto-run", SubAPI.getInstance().getInternals().config.get().getMap("Servers").getMap(getName(), new ObjectMap<String>()).getBoolean("Run-On-Launch", false));
|
||||
List<String> incompatibleCurrent = new ArrayList<String>();
|
||||
List<String> incompatible = new ArrayList<String>();
|
||||
for (SubServer server : getCurrentIncompatibilities()) incompatibleCurrent.add(server.getName());
|
||||
for (SubServer server : getIncompatibilities()) incompatible.add(server.getName());
|
||||
sinfo.set("incompatible", incompatibleCurrent);
|
||||
sinfo.set("incompatible-list", incompatible);
|
||||
return sinfo.toJSON();
|
||||
return sinfo;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Host;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
|
||||
import java.util.*;
|
||||
@ -64,12 +64,12 @@ public abstract class SubServerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int edit(YAMLSection edit) {
|
||||
public int edit(ObjectMap<String> edit) {
|
||||
return SubServerController.this.edit(edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int edit(UUID player, YAMLSection edit) {
|
||||
public int edit(UUID player, ObjectMap<String> edit) {
|
||||
return SubServerController.this.edit(player, edit);
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ public abstract class SubServerController {
|
||||
* @param edit Edits
|
||||
* @return Success Status
|
||||
*/
|
||||
public int edit(UUID player, YAMLSection edit) {
|
||||
public int edit(UUID player, ObjectMap<String> edit) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -246,7 +246,7 @@ public abstract class SubServerController {
|
||||
* @param edit Edits
|
||||
* @return Success Status
|
||||
*/
|
||||
public int edit(YAMLSection edit) {
|
||||
public int edit(ObjectMap<String> edit) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -352,9 +352,4 @@ public abstract class SubServerController {
|
||||
* @param action Stop Action
|
||||
*/
|
||||
public abstract void setStopAction(SubServer.StopAction action);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return control.toString();
|
||||
}
|
||||
}
|
@ -1,11 +1,7 @@
|
||||
package net.ME1312.SubServers.Bungee;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.VersionType;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.Security;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
@ -1,13 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.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.Bungee.Library.Compatibility;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.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,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Compatibility;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.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.Bungee.Library.Config;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.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,397 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Config;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 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.Bungee.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,47 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Library;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.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);
|
||||
}
|
@ -7,9 +7,9 @@ Settings:
|
||||
Forward-SubData: false
|
||||
Forward-Servers: false
|
||||
SubData:
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'default'
|
||||
Encryption: 'AES'
|
||||
Address: '0.0.0.0:4391'
|
||||
Password: ''
|
||||
Encryption: 'RSA/AES'
|
||||
Allowed-Connections: []
|
||||
|
||||
Hosts:
|
||||
|
@ -1,52 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.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.Bungee.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, ':');
|
||||
}
|
||||
}
|
@ -1,476 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.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.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* SubServers Utility Class
|
||||
*/
|
||||
public final class Util {
|
||||
private Util(){}
|
||||
public interface ExceptionReturnRunnable<R> {
|
||||
R run() throws Throwable;
|
||||
}
|
||||
public interface ExceptionRunnable {
|
||||
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()) if (!insensitivity.keySet().contains(item.toLowerCase())) 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();
|
||||
}
|
||||
|
||||
String files[] = from.list();
|
||||
|
||||
for (String file : files) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> zipsearch(File origin, File file) {
|
||||
List<String> list = new LinkedList<String>();
|
||||
if (file.isFile()) {
|
||||
list.add(file.getAbsoluteFile().toString().substring(origin.getAbsoluteFile().toString().length()+1, file.getAbsoluteFile().toString().length()));
|
||||
}
|
||||
if (file.isDirectory()) for (File next : file.listFiles()) {
|
||||
list.addAll(zipsearch(origin, next));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void zip(File file, OutputStream zip) {
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
try{
|
||||
ZipOutputStream zos = new ZipOutputStream(zip);
|
||||
|
||||
for(String next : zipsearch(file, file)){
|
||||
ZipEntry ze= new ZipEntry(next);
|
||||
zos.putNextEntry(ze);
|
||||
|
||||
FileInputStream in = new FileInputStream(file.getAbsolutePath() + File.separator + next);
|
||||
|
||||
int len;
|
||||
while ((len = in.read(buffer)) > 0) {
|
||||
zos.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
zos.closeEntry();
|
||||
zos.close();
|
||||
} catch(IOException ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void unzip(InputStream zip, File dir) {
|
||||
byte[] buffer = new byte[1024];
|
||||
try{
|
||||
ZipInputStream zis = new ZipInputStream(zip);
|
||||
ZipEntry ze;
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
File newFile = new File(dir + File.separator + ze.getName());
|
||||
if (newFile.exists()) {
|
||||
if (newFile.isDirectory()) {
|
||||
Util.deleteDirectory(newFile);
|
||||
} else {
|
||||
newFile.delete();
|
||||
}
|
||||
}
|
||||
if (ze.isDirectory()) {
|
||||
newFile.mkdirs();
|
||||
continue;
|
||||
} else if (!newFile.getParentFile().exists()) {
|
||||
newFile.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream fos = new FileOutputStream(newFile);
|
||||
int len;
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
fos.close();
|
||||
}
|
||||
zis.closeEntry();
|
||||
zis.close();
|
||||
} catch(IOException ex) {
|
||||
ex.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.Bungee.Library.Version;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.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.Bungee.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.Bungee.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,34 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.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,225 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketAuthorization;
|
||||
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.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Network Client Class
|
||||
*/
|
||||
public class Client {
|
||||
private Socket socket;
|
||||
private InetSocketAddress address;
|
||||
private ClientHandler handler;
|
||||
private MessagePacker out;
|
||||
private Timer authorized;
|
||||
private SubDataServer subdata;
|
||||
boolean closed;
|
||||
|
||||
/**
|
||||
* Network Client
|
||||
*
|
||||
* @param subdata SubData Direct Server
|
||||
* @param client Socket to Bind
|
||||
*/
|
||||
public Client(SubDataServer subdata, Socket client) throws IOException {
|
||||
if (Util.isNull(subdata, client)) throw new NullPointerException();
|
||||
this.subdata = subdata;
|
||||
closed = false;
|
||||
socket = client;
|
||||
out = MessagePack.newDefaultPacker(client.getOutputStream());
|
||||
address = new InetSocketAddress(client.getInetAddress(), client.getPort());
|
||||
authorized = new Timer("SubServers.Bungee::SubData_Authorization_Timeout(" + address.toString() + ')');
|
||||
authorized.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!socket.isClosed()) try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 15000);
|
||||
loop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Network Loop
|
||||
*/
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.getInputStream());
|
||||
Value input;
|
||||
while ((input = in.unpackValue()) != null) {
|
||||
recievePacket(input);
|
||||
}
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
||||
try {
|
||||
subdata.removeClient(Client.this);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "SubServers.Bungee::SubData_Packet_Listener(" + address.toString() + ')').start();
|
||||
}
|
||||
|
||||
private void recievePacket(Value input) {
|
||||
try {
|
||||
YAMLSection data = subdata.getCipher().decrypt(subdata.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
||||
for (PacketIn packet : SubDataServer.decodePacket(this, data)) {
|
||||
boolean auth = authorized == null;
|
||||
if (auth || packet instanceof PacketAuthorization) {
|
||||
try {
|
||||
if (data.contains("f")) {
|
||||
if (data.getString("f").length() <= 0) {
|
||||
List<Client> clients = new ArrayList<Client>();
|
||||
clients.addAll(subdata.getClients());
|
||||
for (Client client : clients) {
|
||||
client.out.packValue(input);
|
||||
}
|
||||
} else {
|
||||
Client client = subdata.getClient(data.getString("f"));
|
||||
if (client != null) {
|
||||
client.out.packValue(input);
|
||||
} else {
|
||||
throw new IllegalPacketException(getAddress().toString() + ": Unknown Forward Address: " + data.getString("f"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
packet.execute(Client.this, (data.contains("c")) ? data.getSection("c") : null);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
new InvocationTargetException(e, getAddress().toString() + ": Exception while executing PacketIn").printStackTrace();
|
||||
}
|
||||
} else {
|
||||
sendPacket(new PacketAuthorization(-1, "Unauthorized"));
|
||||
throw new IllegalPacketException(getAddress().toString() + ": Unauthorized call to packet type: " + data.getSection("h"));
|
||||
}
|
||||
}
|
||||
} catch (YAMLException e) { // TODO
|
||||
new IllegalPacketException(getAddress().toString() + ": Unknown Packet Format: " + input).printStackTrace();
|
||||
} catch (IllegalPacketException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
new InvocationTargetException(e, getAddress().toString() + ": Exception while decoding packet").printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Packet to Client
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void sendPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
if (!isClosed()) try {
|
||||
out.packValue(subdata.getCipher().encrypt(subdata.plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), SubDataServer.encodePacket(this, packet)));
|
||||
out.flush();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorize Connection
|
||||
*/
|
||||
public void authorize() {
|
||||
if (authorized != null) {
|
||||
authorized.cancel();
|
||||
System.out.println("SubData > " + socket.getRemoteSocketAddress().toString() + " logged in");
|
||||
}
|
||||
authorized = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Raw Connection
|
||||
*
|
||||
* @return Socket
|
||||
*/
|
||||
public Socket getConnection() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the connection has been closed
|
||||
*
|
||||
* @return Closed Stauts
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return closed && socket.isClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Remote Address
|
||||
*
|
||||
* @return Address
|
||||
*/
|
||||
public InetSocketAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the connection is authorized
|
||||
*
|
||||
* @return Authorization Status
|
||||
*/
|
||||
public boolean isAuthorized() {
|
||||
return authorized == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Linked Handler
|
||||
*
|
||||
* @return Handler
|
||||
*/
|
||||
public ClientHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Handler
|
||||
*
|
||||
* @param obj Handler
|
||||
*/
|
||||
public void setHandler(ClientHandler obj) {
|
||||
if (handler != null && handler.getSubData() != null && equals(handler.getSubData())) handler.setSubData(null);
|
||||
handler = obj;
|
||||
if (handler != null && (handler.getSubData() == null || !equals(handler.getSubData()))) handler.setSubData(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the Client
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void disconnect() throws IOException {
|
||||
if (!socket.isClosed()) getConnection().close();
|
||||
if (handler != null) {
|
||||
setHandler(null);
|
||||
handler = null;
|
||||
}
|
||||
closed = true;
|
||||
if (subdata.getClients().contains(this)) subdata.removeClient(this);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
/**
|
||||
* Client Handler Layout Class
|
||||
*/
|
||||
public interface ClientHandler {
|
||||
/**
|
||||
* Gets the SubData Client
|
||||
*
|
||||
* @return SubData Client (or null if not linked)
|
||||
*/
|
||||
Client getSubData();
|
||||
|
||||
/**
|
||||
* Link a SubData Client to this Object
|
||||
*
|
||||
* @see Client#setHandler(ClientHandler)
|
||||
* @param client Client to Link
|
||||
*/
|
||||
void setSubData(Client client);
|
||||
}
|
@ -1,333 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Encryption;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import org.msgpack.core.MessageBufferPacker;
|
||||
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.Bungee.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.Bungee.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.Bungee.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); }
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
/**
|
||||
* Authorization Packet
|
||||
*/
|
||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketAuthorization (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketAuthorization(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketAuthorization (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketAuthorization(int response, String message) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
try {
|
||||
if (data.getRawString("password").equals(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"))) {
|
||||
client.authorize();
|
||||
client.sendPacket(new PacketAuthorization(0, "Successfully Logged in"));
|
||||
} else {
|
||||
client.sendPacket(new PacketAuthorization(2, "Invalid Password"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketAuthorization(1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
@ -16,11 +15,10 @@ import java.util.UUID;
|
||||
/**
|
||||
* Server Command Packet
|
||||
*/
|
||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCommandServer (In)
|
||||
@ -36,66 +34,67 @@ public class PacketCommandServer implements PacketIn, PacketOut {
|
||||
* New PacketCommandServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Tracker ID
|
||||
*/
|
||||
public PacketCommandServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketCommandServer(int response, UUID tracker) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
String server = data.getRawString(0x0001);
|
||||
String command = data.getRawString(0x0002);
|
||||
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
|
||||
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!data.getRawString("server").equals("*") && !servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketCommandServer(3, "There is no server with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!data.getRawString("server").equals("*") && !(servers.get(data.getRawString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketCommandServer(4, "That Server is not a SubServer", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!data.getRawString("server").equals("*") && !((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketCommandServer(5, "That SubServer is not running", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
if (!server.equals("*") && !servers.keySet().contains(server.toLowerCase())) {
|
||||
client.sendPacket(new PacketCommandServer(3, tracker));
|
||||
} else if (!server.equals("*") && !(servers.get(server.toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketCommandServer(4, tracker));
|
||||
} else if (!server.equals("*") && !((SubServer) servers.get(server.toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketCommandServer(5, tracker));
|
||||
} else {
|
||||
if (data.getRawString("server").equals("*")) {
|
||||
if (server.equals("*")) {
|
||||
boolean sent = false;
|
||||
for (Server server : servers.values()) {
|
||||
if (server instanceof SubServer && ((SubServer) server).isRunning()) {
|
||||
if (((SubServer) server).command((data.contains("player"))?data.getUUID("player"):null, data.getRawString("command"))) {
|
||||
for (Server next : servers.values()) {
|
||||
if (next instanceof SubServer && ((SubServer) next).isRunning()) {
|
||||
if (((SubServer) next).command(player, command)) {
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sent) {
|
||||
client.sendPacket(new PacketCommandServer(0, "Sending Command", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCommandServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketCommandServer(1, "Couldn't send command", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCommandServer(1, tracker));
|
||||
}
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).command((data.contains("player"))?data.getUUID("player"):null, data.getRawString("command"))) {
|
||||
client.sendPacket(new PacketCommandServer(0, "Sending Command", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
if (((SubServer) servers.get(server.toLowerCase())).command(player, command)) {
|
||||
client.sendPacket(new PacketCommandServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketCommandServer(1, "Couldn't send command", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCommandServer(1, tracker));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketCommandServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCommandServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -14,11 +13,10 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
@ -33,72 +31,76 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketCreateServer(int response, String message, String id) {
|
||||
public PacketCreateServer(int response, UUID id) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
if (data.getSection("creator").getString("name").contains(" ")) {
|
||||
client.sendPacket(new PacketCreateServer(3, "Server names cannot have spaces", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (plugin.api.getSubServers().keySet().contains(data.getSection("creator").getString("name").toLowerCase()) || SubCreator.isReserved(data.getSection("creator").getString("name"))) {
|
||||
client.sendPacket(new PacketCreateServer(4, "There is already a subserver with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!plugin.hosts.keySet().contains(data.getSection("creator").getString("host").toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(5, "There is no Host with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).isAvailable()) {
|
||||
client.sendPacket(new PacketStartServer(6, "That SubServer's Host is not available", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(7, "That SubServer's Host is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplates().keySet().contains(data.getSection("creator").getString("template").toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(8, "There is no template with that name", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")).isEnabled()) {
|
||||
client.sendPacket(new PacketCreateServer(8, "That Template is not enabled", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (new Version("1.8").compareTo(data.getSection("creator").getVersion("version")) > 0) {
|
||||
client.sendPacket(new PacketCreateServer(10, "SubCreator cannot create servers before Minecraft 1.8", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (data.getSection("creator").contains("port") && (data.getSection("creator").getInt("port") <= 0 || data.getSection("creator").getInt("port") > 65535)) {
|
||||
client.sendPacket(new PacketCreateServer(11, "Invalid Port Number", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
String name = data.getRawString(0x0001);
|
||||
String host = data.getRawString(0x0002);
|
||||
String template = data.getRawString(0x0003);
|
||||
Version version = (data.contains(0x0004)?data.getVersion(0x0004):null);
|
||||
Integer port = (data.contains(0x0005)?data.getInt(0x0005):null);
|
||||
UUID player = (data.contains(0x0006)?data.getUUID(0x0006):null);
|
||||
boolean waitfor = (data.contains(0x0007)?data.getBoolean(0x0007):false);
|
||||
|
||||
if (name.contains(" ")) {
|
||||
client.sendPacket(new PacketCreateServer(3, tracker));
|
||||
} else if (plugin.api.getSubServers().keySet().contains(name.toLowerCase()) || SubCreator.isReserved(name)) {
|
||||
client.sendPacket(new PacketCreateServer(4, tracker));
|
||||
} else if (!plugin.hosts.keySet().contains(host.toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(5, tracker));
|
||||
} else if (!plugin.hosts.get(host.toLowerCase()).isAvailable()) {
|
||||
client.sendPacket(new PacketCreateServer(6, tracker));
|
||||
} else if (!plugin.hosts.get(host.toLowerCase()).isEnabled()) {
|
||||
client.sendPacket(new PacketCreateServer(7, tracker));
|
||||
} else if (!plugin.hosts.get(host.toLowerCase()).getCreator().getTemplates().keySet().contains(template.toLowerCase())) {
|
||||
client.sendPacket(new PacketCreateServer(8, tracker));
|
||||
} else if (!plugin.hosts.get(host.toLowerCase()).getCreator().getTemplate(template).isEnabled()) {
|
||||
client.sendPacket(new PacketCreateServer(9, tracker));
|
||||
} else if (port != null && (port <= 0 || port > 65535)) {
|
||||
client.sendPacket(new PacketCreateServer(10, tracker));
|
||||
} else {
|
||||
if (plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().create((data.contains("player"))?data.getUUID("player"):null, data.getSection("creator").getString("name"), plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")), data.getSection("creator").getVersion("version"), (data.getSection("creator").contains("port"))?data.getSection("creator").getInt("port"):null)) {
|
||||
if (data.contains("wait") && data.getBoolean("wait")) {
|
||||
if (plugin.hosts.get(host.toLowerCase()).getCreator().create(player, name, plugin.hosts.get(host.toLowerCase()).getCreator().getTemplate(template), version, port)) {
|
||||
if (waitfor) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().waitFor();
|
||||
client.sendPacket(new PacketCreateServer(0, "Created SubServer", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
plugin.hosts.get(host.toLowerCase()).getCreator().waitFor();
|
||||
client.sendPacket(new PacketCreateServer(0, tracker));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "SubServers.Bungee::SubData_SubCreator_Handler(" + client.getAddress().toString() + ')').start();
|
||||
} else {
|
||||
client.sendPacket(new PacketCreateServer(0, "Creating SubServer", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(0, tracker));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketCreateServer(1, "Couldn't create SubServer", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(1, tracker));
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketCreateServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketCreateServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,22 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Group Info Packet
|
||||
*/
|
||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String host;
|
||||
private String group;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadGroupInfo (In)
|
||||
@ -38,43 +33,42 @@ public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param group Group (or null for all)
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadGroupInfo(SubPlugin plugin, String group, String id) {
|
||||
public PacketDownloadGroupInfo(SubPlugin plugin, String group, UUID tracker) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
this.group = group;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
|
||||
YAMLSection groups = new YAMLSection();
|
||||
ObjectMap<String> groups = new ObjectMap<String>();
|
||||
for (String group : plugin.api.getGroups().keySet()) {
|
||||
if (this.group == null || this.group.length() <= 0 || this.group.equalsIgnoreCase(group)) {
|
||||
YAMLSection servers = new YAMLSection();
|
||||
ObjectMap<String> servers = new ObjectMap<String>();
|
||||
for (Server server : plugin.api.getGroup(group)) {
|
||||
servers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
servers.set(server.getName(), server.forSubData());
|
||||
}
|
||||
groups.set(group, servers);
|
||||
}
|
||||
}
|
||||
data.set("groups", groups);
|
||||
data.set(0x0001, groups);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadGroupInfo(plugin, (data.contains("group"))?data.getRawString("group"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadGroupInfo(plugin, (data.contains(0x0001))?data.getRawString(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,22 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Host Info Packet
|
||||
*/
|
||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String host;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadHostInfo (In)
|
||||
@ -35,38 +33,38 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param host Host (or null for all)
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadHostInfo(SubPlugin plugin, String host, String id) {
|
||||
public PacketDownloadHostInfo(SubPlugin plugin, String host, UUID tracker) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
|
||||
YAMLSection hosts = new YAMLSection();
|
||||
ObjectMap<String> hosts = new ObjectMap<String>();
|
||||
for (Host host : plugin.api.getHosts().values()) {
|
||||
if (this.host == null || this.host.length() <= 0 || this.host.equalsIgnoreCase(host.getName())) {
|
||||
hosts.set(host.getName(), new YAMLSection(new Gson().fromJson(host.toString(), Map.class)));
|
||||
hosts.set(host.getName(), host.forSubData());
|
||||
}
|
||||
}
|
||||
data.set("hosts", hosts);
|
||||
data.set(0x0001, hosts);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains("host"))?data.getRawString("host"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains(0x0001))?data.getRawString(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
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.SubPlugin;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Lang Packet
|
||||
*/
|
||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadLang (In)
|
||||
@ -30,31 +30,31 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
||||
* New PacketDownloadLang (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadLang(SubPlugin plugin, String id) {
|
||||
public PacketDownloadLang(SubPlugin plugin, UUID tracker) {
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
LinkedHashMap<String, Map<String, String>> full = new LinkedHashMap<>();
|
||||
for (String channel : plugin.api.getLangChannels())
|
||||
full.put(channel, plugin.api.getLang(channel));
|
||||
data.set("Lang", full);
|
||||
data.set(0x0001, full);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadLang(plugin, (data != null && data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadLang(plugin, (data != null && data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Download Network List Packet
|
||||
*/
|
||||
public class PacketDownloadNetworkList implements PacketIn, PacketOut {
|
||||
private SubPlugin plugin;
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketDownloadNetworkList(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketDownloadNetworkList (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketDownloadNetworkList(SubPlugin plugin, String id) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
if (id != null) json.set("id", id);
|
||||
YAMLSection clients = new YAMLSection();
|
||||
for (Client client : plugin.subdata.getClients()) {
|
||||
try {
|
||||
clients.set(client.getAddress().toString(), new YAMLSection(new Gson().fromJson(client.getHandler().toString(), Map.class)));
|
||||
} catch (JsonParseException | NullPointerException e) {
|
||||
clients.set(client.getAddress().toString(), new YAMLSection());
|
||||
}
|
||||
}
|
||||
json.set("clients", clients);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadNetworkList(plugin, (data.contains("id"))?data.getRawString("id"):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,21 +1,22 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
public class PacketDownloadPlatformInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlatformInfo (In)
|
||||
@ -30,65 +31,67 @@ public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
||||
* New PacketDownloadPlatformInfo (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadPlatformInfo(SubPlugin plugin, String id) {
|
||||
public PacketDownloadPlatformInfo(SubPlugin plugin, UUID tracker) {
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
YAMLSection subservers = new YAMLSection();
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
ObjectMap<String> info = new ObjectMap<String>();
|
||||
ObjectMap<String> subservers = new ObjectMap<String>();
|
||||
subservers.set("version", plugin.api.getWrapperVersion().toString());
|
||||
if (plugin.api.getWrapperBuild() != null) subservers.set("build", plugin.api.getWrapperBuild().toString());
|
||||
subservers.set("last-reload", plugin.resetDate);
|
||||
subservers.set("hosts", plugin.api.getHosts().size());
|
||||
subservers.set("subservers", plugin.api.getSubServers().size());
|
||||
data.set("subservers", subservers);
|
||||
YAMLSection bungee = new YAMLSection();
|
||||
info.set("subservers", subservers);
|
||||
ObjectMap<String> bungee = new ObjectMap<String>();
|
||||
bungee.set("version", plugin.api.getProxyVersion().toString());
|
||||
bungee.set("disabled-cmds", plugin.getConfig().getDisabledCommands());
|
||||
bungee.set("player-limit", plugin.getConfig().getPlayerLimit());
|
||||
bungee.set("servers", plugin.api.getServers().size());
|
||||
LinkedList<YAMLSection> listeners = new LinkedList<YAMLSection>();
|
||||
for (ListenerInfo info : plugin.getConfig().getListeners()) {
|
||||
YAMLSection listener = new YAMLSection();
|
||||
listener.set("forced-hosts", info.getForcedHosts());
|
||||
listener.set("motd", info.getMotd());
|
||||
listener.set("priorities", info.getServerPriority());
|
||||
listener.set("player-limit", info.getMaxPlayers());
|
||||
LinkedList<ObjectMap<String>> listeners = new LinkedList<ObjectMap<String>>();
|
||||
for (ListenerInfo next : plugin.getConfig().getListeners()) {
|
||||
ObjectMap<String> listener = new ObjectMap<String>();
|
||||
listener.set("forced-hosts", next.getForcedHosts());
|
||||
listener.set("motd", next.getMotd());
|
||||
listener.set("priorities", next.getServerPriority());
|
||||
listener.set("player-limit", next.getMaxPlayers());
|
||||
listeners.add(listener);
|
||||
}
|
||||
bungee.set("listeners", listeners);
|
||||
data.set("bungee", bungee);
|
||||
YAMLSection minecraft = new YAMLSection();
|
||||
info.set("bungee", bungee);
|
||||
ObjectMap<String> minecraft = new ObjectMap<String>();
|
||||
LinkedList<String> mcversions = new LinkedList<String>();
|
||||
for (Version version : plugin.api.getGameVersion()) mcversions.add(version.toString());
|
||||
minecraft.set("version", mcversions);
|
||||
minecraft.set("players", plugin.api.getGlobalPlayers().size());
|
||||
data.set("minecraft", minecraft);
|
||||
YAMLSection system = new YAMLSection();
|
||||
YAMLSection os = new YAMLSection();
|
||||
info.set("minecraft", minecraft);
|
||||
ObjectMap<String> system = new ObjectMap<String>();
|
||||
ObjectMap<String> os = new ObjectMap<String>();
|
||||
os.set("name", System.getProperty("os.name"));
|
||||
os.set("version", System.getProperty("os.version"));
|
||||
system.set("os", os);
|
||||
YAMLSection java = new YAMLSection();
|
||||
ObjectMap<String> java = new ObjectMap<String>();
|
||||
java.set("version", System.getProperty("java.version"));
|
||||
system.set("java", java);
|
||||
data.set("system", system);
|
||||
info.set("system", system);
|
||||
data.set(0x0001, info);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadPlatformInfo(plugin, (data != null && data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadPlatformInfo(plugin, (data != null && data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
@ -15,9 +14,9 @@ import java.util.UUID;
|
||||
/**
|
||||
* Download Player List Packet
|
||||
*/
|
||||
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
public class PacketDownloadPlayerList implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadPlayerList (In)
|
||||
@ -33,22 +32,22 @@ public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
* New PacketDownloadPlayerList (Out)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadPlayerList(SubPlugin plugin, String id) {
|
||||
public PacketDownloadPlayerList(SubPlugin plugin, UUID tracker) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
YAMLSection players = new YAMLSection();
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
ObjectMap<String> players = new ObjectMap<String>();
|
||||
for (NamedContainer<String, UUID> player : plugin.api.getGlobalPlayers()) {
|
||||
YAMLSection pinfo = new YAMLSection();
|
||||
ObjectMap<String> pinfo = new ObjectMap<String>();
|
||||
pinfo.set("name", player.get());
|
||||
if (plugin.redis != null) {
|
||||
try {
|
||||
@ -61,17 +60,17 @@ public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
||||
}
|
||||
players.set(player.get().toString(), pinfo);
|
||||
}
|
||||
data.set("players", players);
|
||||
data.set(0x0001, players);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadPlayerList(plugin, (data != null && data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadPlayerList(plugin, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,22 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Proxy Info Packet
|
||||
*/
|
||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String proxy;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadProxyInfo (In)
|
||||
@ -37,39 +33,39 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param proxy Proxy (or null for all)
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadProxyInfo(SubPlugin plugin, String proxy, String id) {
|
||||
public PacketDownloadProxyInfo(SubPlugin plugin, String proxy, UUID tracker) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.proxy = proxy;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
|
||||
YAMLSection proxies = new YAMLSection();
|
||||
ObjectMap<String> proxies = new ObjectMap<String>();
|
||||
for (Proxy proxy : plugin.api.getProxies().values()) {
|
||||
if (this.proxy == null || this.proxy.equalsIgnoreCase(proxy.getName())) {
|
||||
proxies.set(proxy.getName(), new YAMLSection(new Gson().fromJson(proxy.toString(), Map.class)));
|
||||
proxies.set(proxy.getName(), proxy.forSubData());
|
||||
}
|
||||
}
|
||||
data.set("proxies", proxies);
|
||||
if ((this.proxy == null || this.proxy.length() <= 0) && plugin.api.getMasterProxy() != null) data.set("master", new YAMLSection(new Gson().fromJson(plugin.api.getMasterProxy().toString(), Map.class)));
|
||||
data.set(0x0001, proxies);
|
||||
if ((this.proxy == null || this.proxy.length() <= 0) && plugin.api.getMasterProxy() != null) data.set(0x0002, plugin.api.getMasterProxy().forSubData());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadProxyInfo(plugin, (data.contains("proxy"))?data.getRawString("proxy"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadProxyInfo(plugin, (data.contains(0x0001))?data.getRawString(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,22 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Download Server Info Packet
|
||||
*/
|
||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private String server;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketDownloadServerInfo (In)
|
||||
@ -37,38 +33,38 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param server Server (or null for all)
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketDownloadServerInfo(SubPlugin plugin, String server, String id) {
|
||||
public PacketDownloadServerInfo(SubPlugin plugin, String server, UUID tracker) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
if (id != null) data.set("id", id);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
|
||||
YAMLSection servers = new YAMLSection();
|
||||
ObjectMap<String> servers = new ObjectMap<String>();
|
||||
for (Server server : plugin.api.getServers().values()) {
|
||||
if (this.server == null || this.server.length() <= 0 || this.server.equalsIgnoreCase(server.getName())) {
|
||||
servers.set(server.getName(), new YAMLSection(new Gson().fromJson(server.toString(), Map.class)));
|
||||
servers.set(server.getName(), server.forSubData());
|
||||
}
|
||||
}
|
||||
data.set("servers", servers);
|
||||
data.set(0x0001, servers);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
client.sendPacket(new PacketDownloadServerInfo(plugin, (data.contains("server"))?data.getRawString("server"):null, (data.contains("id"))?data.getRawString("id"):null));
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
client.sendPacket(new PacketDownloadServerInfo(plugin, (data.contains(0x0001))?data.getRawString(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -14,8 +13,8 @@ import java.util.UUID;
|
||||
/**
|
||||
* Add Server External Host Packet
|
||||
*/
|
||||
public class PacketExAddServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private String name;
|
||||
private boolean enabled;
|
||||
private int port;
|
||||
@ -24,7 +23,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
||||
private String executable;
|
||||
private String stopcmd;
|
||||
private UUID running;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExAddServer (In)
|
||||
@ -41,7 +40,7 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
||||
* @param executable Executable
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd, UUID running, Callback<YAMLSection>... callback) {
|
||||
public PacketExAddServer(String name, boolean enabled, int port, boolean log, String directory, String executable, String stopcmd, UUID running, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, enabled, log, directory, executable, callback)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.enabled = enabled;
|
||||
@ -51,35 +50,33 @@ public class PacketExAddServer implements PacketIn, PacketOut {
|
||||
this.executable = executable;
|
||||
this.stopcmd = stopcmd;
|
||||
this.running = running;
|
||||
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();
|
||||
if (id != null) data.set("id", id);
|
||||
YAMLSection server = new YAMLSection();
|
||||
server.set("name", name);
|
||||
server.set("enabled", enabled);
|
||||
server.set("port", port);
|
||||
server.set("log", log);
|
||||
server.set("dir", directory);
|
||||
server.set("exec", executable);
|
||||
server.set("stopcmd", stopcmd);
|
||||
if (running != null) server.set("running", running.toString());
|
||||
data.set("server", server);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, enabled);
|
||||
data.set(0x0003, port);
|
||||
data.set(0x0004, log);
|
||||
data.set(0x0005, directory);
|
||||
data.set(0x0006, executable);
|
||||
data.set(0x0007, stopcmd);
|
||||
if (running != null) data.set(0x0008, running.toString());
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, 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.13.1b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -2,12 +2,11 @@ package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.External.ExternalHost;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import org.msgpack.value.ValueFactory;
|
||||
|
||||
@ -16,7 +15,7 @@ import java.io.*;
|
||||
/**
|
||||
* External Host Configuration Packet
|
||||
*/
|
||||
public class PacketExConfigureHost implements PacketIn, PacketOut {
|
||||
public class PacketExConfigureHost implements PacketIn, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private ExternalHost host;
|
||||
|
||||
@ -36,41 +35,33 @@ public class PacketExConfigureHost implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("host", plugin.config.get().getSection("Hosts").getSection(host.getName()).clone());
|
||||
YAMLSection templates = new YAMLSection();
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, plugin.config.get().getMap("Hosts").getMap(host.getName()).clone());
|
||||
ObjectMap<String> templates = new ObjectMap<String>();
|
||||
for (SubCreator.ServerTemplate template : host.getCreator().getTemplates().values()) {
|
||||
try {
|
||||
YAMLSection tinfo = new YAMLSection();
|
||||
tinfo.set("enabled", template.isEnabled());
|
||||
tinfo.set("display", template.getDisplayName());
|
||||
tinfo.set("icon", template.getIcon());
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
Util.zip(template.getDirectory(), bytes);
|
||||
tinfo.set("files", ValueFactory.newBinary(bytes.toByteArray(), true));
|
||||
tinfo.set("build", template.getBuildOptions().clone());
|
||||
tinfo.set("settings", template.getConfigOptions().clone());
|
||||
templates.set(template.getName(), tinfo);
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubServers > Problem encoding template files: " + template.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
ObjectMap<String> tinfo = new ObjectMap<String>();
|
||||
tinfo.set("enabled", template.isEnabled());
|
||||
tinfo.set("display", template.getDisplayName());
|
||||
tinfo.set("icon", template.getIcon());
|
||||
tinfo.set("build", template.getBuildOptions().clone());
|
||||
tinfo.set("settings", template.getConfigOptions().clone());
|
||||
templates.set(template.getName(), tinfo);
|
||||
}
|
||||
data.set("templates", templates);
|
||||
data.set(0x0001, templates);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getSection("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
|
||||
@Override
|
||||
public void receive(SubDataClient client) {
|
||||
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
|
||||
client.sendPacket(new PacketExConfigureHost(plugin, (ExternalHost) client.getHandler()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.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.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -15,14 +15,14 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server External Host Packet
|
||||
*/
|
||||
public class PacketExCreateServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private String name;
|
||||
private SubCreator.ServerTemplate template;
|
||||
private Version version;
|
||||
private int port;
|
||||
private UUID log;
|
||||
private String id = null;
|
||||
private UUID tracker = null;
|
||||
|
||||
/**
|
||||
* New PacketExCreateServer
|
||||
@ -42,45 +42,41 @@ public class PacketExCreateServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExCreateServer(String name, SubCreator.ServerTemplate template, Version version, int port, UUID log, Callback<YAMLSection>... callback) {
|
||||
public PacketExCreateServer(String name, SubCreator.ServerTemplate template, Version version, int port, UUID log, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, template, version, port, log, callback)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.log = log;
|
||||
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() {
|
||||
if (id == null) {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("thread", name);
|
||||
return data;
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker == null) {
|
||||
data.set(0x0001, name);
|
||||
} else {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
YAMLSection creator = new YAMLSection();
|
||||
creator.set("name", name);
|
||||
creator.set("template", template.getName());
|
||||
creator.set("version", version);
|
||||
creator.set("port", port);
|
||||
creator.set("log", log.toString());
|
||||
data.set("creator", creator);
|
||||
return data;
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0002, name);
|
||||
data.set(0x0003, template.getName());
|
||||
data.set(0x0004, version);
|
||||
data.set(0x0005, port);
|
||||
data.set(0x0006, log.toString());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, 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,12 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -14,11 +13,12 @@ import java.util.UUID;
|
||||
/**
|
||||
* Delete Server External Host Packet
|
||||
*/
|
||||
public class PacketExDeleteServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private String name;
|
||||
private YAMLSection info;
|
||||
private String id = null;
|
||||
private ObjectMap<String> info;
|
||||
private boolean recycle;
|
||||
private UUID tracker = null;
|
||||
|
||||
/**
|
||||
* New PacketExDeleteServer
|
||||
@ -33,35 +33,37 @@ public class PacketExDeleteServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExDeleteServer(String name, YAMLSection info, Callback<YAMLSection>... callback) {
|
||||
public PacketExDeleteServer(String name, ObjectMap<String> info, boolean recycle, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, info, callback)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.info = info;
|
||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
||||
callbacks.put(id, callback);
|
||||
this.recycle = recycle;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
if (id == null) {
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
if (tracker == null) {
|
||||
return null;
|
||||
} else {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("id", id);
|
||||
data.set("server", name);
|
||||
data.set("info", info);
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
data.set(0x0002, info);
|
||||
if (recycle) data.set(0x0003, true);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Host.External.ExternalHost;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketStreamOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* External Host Template Download Packet
|
||||
*/
|
||||
public class PacketExDownloadTemplates implements PacketIn, PacketStreamOut {
|
||||
private SubPlugin plugin;
|
||||
private ExternalHost host;
|
||||
|
||||
/**
|
||||
* New PacketExDownloadTemplates (In)
|
||||
*/
|
||||
public PacketExDownloadTemplates(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExDownloadTemplates (Out)
|
||||
*/
|
||||
public PacketExDownloadTemplates(SubPlugin plugin, ExternalHost host) {
|
||||
this.plugin = plugin;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(SubDataClient client, OutputStream stream) throws Throwable {
|
||||
try {
|
||||
Util.zip(new UniversalFile(plugin.dir, "SubServers:Templates"), stream);
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubData > Problem encoding template files for Host: " + host.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client) {
|
||||
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
|
||||
client.sendPacket(new PacketExDownloadTemplates(plugin, (ExternalHost) client.getHandler()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Callback;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -14,10 +13,10 @@ import java.util.UUID;
|
||||
/**
|
||||
* Create Server External Host Packet
|
||||
*/
|
||||
public class PacketExRemoveServer implements PacketIn, PacketOut {
|
||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
||||
public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private String name;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketExRemoveServer (In)
|
||||
@ -31,29 +30,29 @@ public class PacketExRemoveServer implements PacketIn, PacketOut {
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExRemoveServer(String name, Callback<YAMLSection>... callback) {
|
||||
public PacketExRemoveServer(String name, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
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();
|
||||
if (id != null) data.set("id", id);
|
||||
data.set("server", name);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, name);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
for (Callback<YAMLSection> callback : callbacks.get(data.getString("id"))) callback.run(data);
|
||||
callbacks.remove(data.getString("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,22 +1,21 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.External.ExternalSubServer;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Update External Server Packet
|
||||
*/
|
||||
public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private SubServer server;
|
||||
private UpdateType type;
|
||||
@ -78,24 +77,24 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("server", server.getName());
|
||||
data.set("type", type.getValue());
|
||||
data.set("args", Arrays.asList(args));
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, server.getName());
|
||||
data.set(0x0001, type.getValue());
|
||||
data.set(0x0002, Arrays.asList(args));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
ExternalSubServer server = (ExternalSubServer) plugin.api.getSubServer(data.getRawString("server"));
|
||||
switch (data.getInt("type")) {
|
||||
ExternalSubServer server = (ExternalSubServer) plugin.api.getSubServer(data.getRawString(0x0000));
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 1:
|
||||
Util.reflect(ExternalSubServer.class.getDeclaredMethod("falsestart"), server);
|
||||
break;
|
||||
case 2:
|
||||
Util.reflect(ExternalSubServer.class.getDeclaredMethod("stopped", Boolean.class), server, data.getList("args").get(1).asBoolean());
|
||||
Util.reflect(ExternalSubServer.class.getDeclaredMethod("stopped", Boolean.class), server, data.getList(0x0002).get(1).asBoolean());
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -104,7 +103,7 @@ public class PacketExUpdateServer implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,19 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.External.ExternalSubLogger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Message Log External Host Packet
|
||||
*/
|
||||
public class PacketInExLogMessage implements PacketIn {
|
||||
public class PacketInExLogMessage implements PacketObjectIn<Integer> {
|
||||
private static HashMap<UUID, ExternalSubLogger> loggers = new HashMap<UUID, ExternalSubLogger>();
|
||||
|
||||
/**
|
||||
@ -23,10 +22,10 @@ public class PacketInExLogMessage implements PacketIn {
|
||||
public PacketInExLogMessage() {}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
if (data.contains("h") && data.contains("m") && data.getRawString("m").length() != 0 && loggers.keySet().contains(data.getUUID("h"))) {
|
||||
Util.reflect(ExternalSubLogger.class.getDeclaredMethod("log", String.class), loggers.get(data.getUUID("h")), data.getRawString("m"));
|
||||
if (data.contains(0x0000) && data.contains(0x0001) && loggers.keySet().contains(data.getUUID(0x0000))) {
|
||||
Util.reflect(ExternalSubLogger.class.getDeclaredMethod("log", String.class), loggers.get(data.getUUID(0x0000)), data.getRawString(0x0001));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -34,8 +33,8 @@ public class PacketInExLogMessage implements PacketIn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,15 +1,12 @@
|
||||
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.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* External Host Queue Request Packet
|
||||
@ -25,8 +22,8 @@ public class PacketInExRequestQueue implements PacketIn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getSection("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
|
||||
public void receive(SubDataClient client) {
|
||||
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
|
||||
try {
|
||||
Util.reflect(ExternalHost.class.getDeclaredMethod("requeue"), client.getHandler());
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
@ -36,7 +33,7 @@ public class PacketInExRequestQueue implements PacketIn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
/**
|
||||
* Reload Packet
|
||||
*/
|
||||
public class PacketInReload implements PacketObjectIn<Integer> {
|
||||
private SubPlugin plugin;
|
||||
|
||||
/**
|
||||
* New PacketInReload
|
||||
*
|
||||
* @param plugin Plugin
|
||||
*/
|
||||
public PacketInReload(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
|
||||
if (data != null && data.contains(0x0000)) plugin.getLogger().warning("SubData > Received request for a proxy reload: " + data.getString(0x0000));
|
||||
else plugin.getLogger().warning("SubData > Received request for a proxy reload");
|
||||
try {
|
||||
plugin.reload();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
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.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
@ -15,10 +14,9 @@ import java.util.Map;
|
||||
/**
|
||||
* Link External Host Packet
|
||||
*/
|
||||
public class PacketLinkExHost implements PacketIn, PacketOut {
|
||||
public class PacketLinkExHost implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketLinkExHost (In)
|
||||
@ -34,50 +32,46 @@ public class PacketLinkExHost implements PacketIn, PacketOut {
|
||||
* New PacketLinkExHost (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketLinkExHost(int response, String message) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketLinkExHost(int response) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
Map<String, Host> hosts = plugin.api.getHosts();
|
||||
if (hosts.keySet().contains(data.getRawString("name").toLowerCase())) {
|
||||
Host host = hosts.get(data.getRawString("name").toLowerCase());
|
||||
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());
|
||||
client.sendPacket(new PacketLinkExHost(0, "Definition Successful"));
|
||||
client.sendPacket(new PacketLinkExHost(0));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(3, "Host already linked"));
|
||||
client.sendPacket(new PacketLinkExHost(3));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(4, "That host does not support a network interface"));
|
||||
client.sendPacket(new PacketLinkExHost(4));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkExHost(2, "There is no host with name: " + data.getRawString("name")));
|
||||
client.sendPacket(new PacketLinkExHost(2));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketLinkExHost(1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
client.sendPacket(new PacketLinkExHost(1));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -2,24 +2,22 @@ package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.Proxy;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
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.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Link Proxy Packet
|
||||
*/
|
||||
public class PacketLinkProxy implements PacketIn, PacketOut {
|
||||
public class PacketLinkProxy implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String name;
|
||||
|
||||
/**
|
||||
@ -37,48 +35,45 @@ public class PacketLinkProxy implements PacketIn, PacketOut {
|
||||
*
|
||||
* @param name The name that was generated
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketLinkProxy(String name, int response, String message) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketLinkProxy(String name, int response) {
|
||||
this.name = name;
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("n", name);
|
||||
json.set("r", response);
|
||||
json.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, name);
|
||||
json.set(0x0001, response);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
try {
|
||||
Map<String, Proxy> proxies = plugin.api.getProxies();
|
||||
String name = ((data.contains(0x0000))?data.getRawString(0x0000):null);
|
||||
Proxy proxy;
|
||||
if (data.contains("name") && proxies.keySet().contains(data.getRawString("name").toLowerCase()) && proxies.get(data.getRawString("name").toLowerCase()).getSubData() == null) {
|
||||
proxy = proxies.get(data.getRawString("name").toLowerCase());
|
||||
if (name != null && proxies.keySet().contains(name.toLowerCase()) && proxies.get(name.toLowerCase()).getSubData() == null) {
|
||||
proxy = proxies.get(name.toLowerCase());
|
||||
} else {
|
||||
proxy = new Proxy((data.contains("name") && !proxies.keySet().contains(data.getRawString("name").toLowerCase()))?data.getRawString("name"):null);
|
||||
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);
|
||||
}
|
||||
|
||||
client.setHandler(proxy);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName());
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0, "Definition Successful"));
|
||||
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0));
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketLinkProxy(null, 1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
client.sendPacket(new PacketLinkProxy(null, 1));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -16,7 +15,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Link Server Packet
|
||||
*/
|
||||
public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
@ -46,61 +45,64 @@ public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketLinkServer(String name, int response, String message) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
this.name = name;
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("n", name);
|
||||
data.set("r", response);
|
||||
data.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, name);
|
||||
data.set(0x0001, response);
|
||||
if (message != null) data.set(0x0002, message);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
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;
|
||||
|
||||
try {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
Server server;
|
||||
if (data.contains("name") && servers.keySet().contains(data.getRawString("name").toLowerCase())) {
|
||||
link(client, servers.get(data.getRawString("name").toLowerCase()));
|
||||
} else if (data.contains("port")) {
|
||||
if ((server = search(new InetSocketAddress(client.getAddress().getAddress(), data.getInt("port")))) != null) {
|
||||
if (name != null && servers.keySet().contains(name.toLowerCase())) {
|
||||
link(client, servers.get(name.toLowerCase()));
|
||||
} else if (port != null) {
|
||||
if ((server = search(new InetSocketAddress(client.getAddress().getAddress(), port))) != null) {
|
||||
link(client, server);
|
||||
} else {
|
||||
throw new ServerLinkException("There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + data.getInt("port"));
|
||||
throw new ServerLinkException("There is no server with address: " + client.getAddress().getAddress().getHostAddress() + ':' + port);
|
||||
}
|
||||
} else {
|
||||
throw new ServerLinkException("Not enough arguments");
|
||||
}
|
||||
} catch (ServerLinkException e) {
|
||||
if (data.contains("name")) {
|
||||
client.sendPacket(new PacketLinkServer(null, 2, "There is no server with name: " + data.getRawString("name")));
|
||||
if (name != null) {
|
||||
client.sendPacket(new PacketLinkServer(null, 3, "There is no server with name: " + name));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkServer(null, 2, e.getMessage()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
client.sendPacket(new PacketLinkServer(null, 1, e.getClass().getCanonicalName() + ": " + e.getMessage()));
|
||||
client.sendPacket(new PacketLinkServer(null, 1, null));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void link(Client client, Server server) {
|
||||
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());
|
||||
if (server instanceof SubServer && !((SubServer) server).isRunning()) {
|
||||
System.out.println("SubServers > Sending shutdown signal to rogue SubServer: " + server.getName());
|
||||
client.sendPacket(new PacketOutReset("Rogue SubServer Detected"));
|
||||
client.sendPacket(new PacketOutExReset("Rogue SubServer Detected"));
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkServer(server.getName(), 0, "Definition Successful"));
|
||||
client.sendPacket(new PacketLinkServer(server.getName(), 0, null));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketLinkServer(null, 3, "Server already linked"));
|
||||
client.sendPacket(new PacketLinkServer(null, 4, "Server already linked"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +118,7 @@ public class PacketLinkServer implements PacketIn, PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
|
||||
/**
|
||||
* Reload Packet
|
||||
*/
|
||||
public class PacketOutExReload implements PacketObjectOut<Integer> {
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketOutExReload
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketOutExReload(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
} else {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, message);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
|
||||
/**
|
||||
* Reset Packet
|
||||
*/
|
||||
public class PacketOutExReset implements PacketObjectOut<Integer> {
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketOutExReset
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketOutExReset(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
if (message == null) {
|
||||
return null;
|
||||
} else {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, message);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -1,175 +1,186 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Event.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Event Send Packet
|
||||
*/
|
||||
public class PacketOutRunEvent implements Listener, PacketOut {
|
||||
public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private YAMLSection args;
|
||||
private ObjectMap<String> args;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* New PacketOutRunEvent (Registerer)
|
||||
* New PacketOutExRunEvent (Registerer)
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public PacketOutRunEvent(SubPlugin plugin) {
|
||||
public PacketOutExRunEvent(SubPlugin plugin) {
|
||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketOutRunEvent (Out)
|
||||
* New PacketOutExRunEvent (Out)
|
||||
*
|
||||
* @param event Event to be run
|
||||
* @param args Arguments
|
||||
*/
|
||||
public PacketOutRunEvent(Class<? extends SubEvent> event, YAMLSection args) {
|
||||
public PacketOutExRunEvent(Class<? extends SubEvent> event, ObjectMap<String> args) {
|
||||
if (Util.isNull(event, args)) throw new NullPointerException();
|
||||
this.type = event.getSimpleName();
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("type", type);
|
||||
json.set("args", args);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
json.set(0x0000, type);
|
||||
json.set(0x0001, args);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
|
||||
private void broadcast(PacketOutExRunEvent packet) {
|
||||
List<SubDataClient> clients = new LinkedList<SubDataClient>();
|
||||
clients.addAll(plugin.subdata.getClients().values());
|
||||
for (SubDataClient client : clients) {
|
||||
client.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubAddProxyEvent event) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("proxy", event.getProxy().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubAddHostEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
if (event.getPlayer() != null) args.set("player",event.getPlayer().toString());
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubAddServerEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
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());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubCreateEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
args.set("name", event.getName());
|
||||
args.set("template", event.getTemplate().getName());
|
||||
args.set("version", event.getVersion());
|
||||
if (event.getVersion() != null) args.set("version", event.getVersion());
|
||||
args.set("port", event.getPort());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubSendCommandEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("server", event.getServer().getName());
|
||||
args.set("command", event.getCommand());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubEditServerEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("server", event.getServer().getName());
|
||||
args.set("edit", event.getEdit().name());
|
||||
args.set("value", event.getEdit().get().asObject());
|
||||
args.set("perm", event.isPermanent());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubStartEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("server", event.getServer().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubStopEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("server", event.getServer().getName());
|
||||
args.set("force", event.isForced());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubStoppedEvent event) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("server", event.getServer().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
|
||||
}
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubRemoveServerEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
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());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubRemoveHostEvent event) {
|
||||
if (!event.isCancelled()) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void event(SubRemoveProxyEvent event) {
|
||||
YAMLSection args = new YAMLSection();
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
args.set("proxy", event.getProxy().getName());
|
||||
plugin.subdata.broadcastPacket(new PacketOutRunEvent(event.getClass(), args));
|
||||
broadcast(new PacketOutExRunEvent(event.getClass(), args));
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Update External Whitelist Packet
|
||||
*/
|
||||
public class PacketOutExUpdateWhitelist implements PacketOut {
|
||||
public class PacketOutExUpdateWhitelist implements PacketObjectOut<Integer> {
|
||||
private String name;
|
||||
private boolean mode;
|
||||
private UUID value;
|
||||
@ -30,15 +31,16 @@ public class PacketOutExUpdateWhitelist implements PacketOut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("server", name);
|
||||
data.set("mode", mode);
|
||||
data.set("value", value);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
data.set(0x0000, name);
|
||||
data.set(0x0001, mode);
|
||||
data.set(0x0002, value);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13.2c");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
|
||||
/**
|
||||
* Reload Packet
|
||||
*/
|
||||
public class PacketOutReload implements PacketOut {
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketOutReload
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketOutReload(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
if (message == null) {
|
||||
return null;
|
||||
} else {
|
||||
YAMLSection data = new YAMLSection();
|
||||
data.set("m", message);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
|
||||
/**
|
||||
* Reset Packet
|
||||
*/
|
||||
public class PacketOutReset implements PacketOut {
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* New PacketOutReset
|
||||
*
|
||||
* @param message Message
|
||||
*/
|
||||
public PacketOutReset(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
if (message == null) {
|
||||
return null;
|
||||
} else {
|
||||
YAMLSection json = new YAMLSection();
|
||||
json.set("m", message);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
}
|
||||
}
|
@ -1,26 +1,24 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Restart Server Packet
|
||||
*/
|
||||
public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketRestartServer (In)
|
||||
@ -36,72 +34,72 @@ public class PacketRestartServer implements PacketIn, PacketOut {
|
||||
* New PacketRestartServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketRestartServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketRestartServer(int response, UUID tracker) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
if (id != null) json.set("id", id);
|
||||
json.set("r", response);
|
||||
json.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
if (tracker != null) json.set(0x0000, tracker);
|
||||
json.set(0x0001, response);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
String name = data.getRawString(0x0001);
|
||||
UUID player = (data.contains(0x0002)?data.getUUID(0x0002):null);
|
||||
|
||||
Runnable starter = () -> {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
} else if (!(servers.get(data.getRawString("server").toLowerCase()) instanceof SubServer)) {
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).getHost().isAvailable()) {
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).getHost().isEnabled()) {
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).isEnabled()) {
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
if (!servers.keySet().contains(name.toLowerCase())) {
|
||||
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
} else {
|
||||
((SubServer) servers.get(data.getRawString("server").toLowerCase())).start((data.contains("player"))?data.getUUID("player"):null);
|
||||
((SubServer) servers.get(name.toLowerCase())).start(player);
|
||||
}
|
||||
};
|
||||
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketRestartServer(3, "There is no server with that name", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!(servers.get(data.getRawString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketRestartServer(4, "That Server is not a SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (!servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketRestartServer(3, tracker));
|
||||
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketRestartServer(4, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketRestartServer(0, "Restarting SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketRestartServer(0, tracker));
|
||||
if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
((SubServer) servers.get(data.getRawString("server").toLowerCase())).stop();
|
||||
((SubServer) servers.get(data.getRawString("server").toLowerCase())).waitFor();
|
||||
((SubServer) servers.get(name.toLowerCase())).stop();
|
||||
((SubServer) servers.get(name.toLowerCase())).waitFor();
|
||||
Thread.sleep(100);
|
||||
starter.run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "SubServers.Bungee::Server_Restart_Packet_Handler(" + servers.get(data.getRawString("server").toLowerCase()).getName() + ')').start();
|
||||
}, "SubServers.Bungee::Server_Restart_Packet_Handler(" + servers.get(name.toLowerCase()).getName() + ')').start();
|
||||
} else {
|
||||
starter.run();
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketRestartServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketRestartServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
@ -16,11 +15,11 @@ import java.util.UUID;
|
||||
/**
|
||||
* Start Server Packet
|
||||
*/
|
||||
public class PacketStartServer implements PacketIn, PacketOut {
|
||||
public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private String extra;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketStartServer (In)
|
||||
@ -36,63 +35,75 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
||||
* New PacketStartServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketStartServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketStartServer(int response, UUID tracker) {
|
||||
this(response, null, tracker);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketStartServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketStartServer(int response, String extra, UUID tracker) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.extra = extra;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
if (id != null) json.set("id", id);
|
||||
json.set("r", response);
|
||||
json.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
if (tracker != null) json.set(0x0000, tracker);
|
||||
json.set(0x0001, response);
|
||||
if (extra != null) json.set(0x0002, extra);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
String name = data.getRawString(0x0001);
|
||||
UUID player = (data.contains(0x0002)?data.getUUID(0x0002):null);
|
||||
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketStartServer(3, "There is no server with that name", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!(servers.get(data.getRawString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStartServer(4, "That Server is not a SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).getHost().isAvailable()) {
|
||||
client.sendPacket(new PacketStartServer(5, "That SubServer's Host is not available", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(6, "That SubServer's Host is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!((SubServer) servers.get(data.getRawString("server").toLowerCase())).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(7, "That SubServer is not enabled", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStartServer(8, "That SubServer is already running", (data.contains("id")) ? data.getRawString("id") : null));
|
||||
} else if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
if (!servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketStartServer(3, tracker));
|
||||
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStartServer(4, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
|
||||
client.sendPacket(new PacketStartServer(5, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(6, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(7, tracker));
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStartServer(8, tracker));
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (SubServer server : ((SubServer) servers.get(data.getRawString("server").toLowerCase())).getCurrentIncompatibilities()) {
|
||||
for (SubServer server : ((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += server.getName();
|
||||
}
|
||||
client.sendPacket(new PacketStartServer(9, "Cannot start SubServer while these servers are running: " + list, (data.contains("id")) ? data.getRawString("id") : null));
|
||||
client.sendPacket(new PacketStartServer(9, list, tracker));
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).start((data.contains("player"))?data.getUUID("player"):null)) {
|
||||
client.sendPacket(new PacketStartServer(0, "Starting SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (((SubServer) servers.get(name.toLowerCase())).start(player)) {
|
||||
client.sendPacket(new PacketStartServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketStartServer(1, "Couldn't start SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStartServer(1, tracker));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketStartServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStartServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.13b");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,11 @@ package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Client;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketIn;
|
||||
import net.ME1312.SubServers.Bungee.Network.PacketOut;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
@ -16,11 +15,10 @@ import java.util.UUID;
|
||||
/**
|
||||
* Stop Server Packet
|
||||
*/
|
||||
public class PacketStopServer implements PacketIn, PacketOut {
|
||||
public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private String message;
|
||||
private String id;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketStopServer (In)
|
||||
@ -36,87 +34,88 @@ public class PacketStopServer implements PacketIn, PacketOut {
|
||||
* New PacketStopServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param message Message
|
||||
* @param id Receiver ID
|
||||
* @param tracker Receiver ID
|
||||
*/
|
||||
public PacketStopServer(int response, String message, String id) {
|
||||
if (Util.isNull(response, message)) throw new NullPointerException();
|
||||
public PacketStopServer(int response, UUID tracker) {
|
||||
this.response = response;
|
||||
this.message = message;
|
||||
this.id = id;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YAMLSection generate() {
|
||||
YAMLSection json = new YAMLSection();
|
||||
if (id != null) json.set("id", id);
|
||||
json.set("r", response);
|
||||
json.set("m", message);
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||
if (tracker != null) json.set(0x0000, tracker);
|
||||
json.set(0x0001, response);
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Client client, YAMLSection data) {
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
String name = data.getRawString(0x0001);
|
||||
boolean force = (data.contains(0x0002)?data.getBoolean(0x0002):false);
|
||||
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
|
||||
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!data.getRawString("server").equals("*") && !servers.keySet().contains(data.getRawString("server").toLowerCase())) {
|
||||
client.sendPacket(new PacketStopServer(3, "There is no server with that name", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!data.getRawString("server").equals("*") && !(servers.get(data.getRawString("server").toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStopServer(4, "That Server is not a SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (!data.getRawString("server").equals("*") && !((SubServer) servers.get(data.getRawString("server").toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStopServer(5, "That SubServer is not running", (data.contains("id"))?data.getRawString("id"):null));
|
||||
} else if (data.getRawString("server").equals("*")) {
|
||||
if (!name.equals("*") && !servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketStopServer(3, tracker));
|
||||
} else if (!name.equals("*") && !(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketStopServer(4, tracker));
|
||||
} else if (!name.equals("*") && !((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStopServer(5, tracker));
|
||||
} else if (name.equals("*")) {
|
||||
boolean sent = false;
|
||||
if (data.contains("force") && data.getBoolean("force")) {
|
||||
if (force) {
|
||||
for (Server server : servers.values()) {
|
||||
if (server instanceof SubServer && ((SubServer) server).isRunning()) {
|
||||
if (((SubServer) server).terminate((data.contains("player"))?data.getUUID("player"):null)) {
|
||||
if (((SubServer) server).terminate(player)) {
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sent) {
|
||||
client.sendPacket(new PacketStopServer(0, "Terminating SubServers", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't terminate SubServers", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(1, tracker));
|
||||
}
|
||||
} else {
|
||||
for (Server server : servers.values()) {
|
||||
if (server instanceof SubServer && ((SubServer) server).isRunning()) {
|
||||
if (((SubServer) server).stop((data.contains("player"))?data.getUUID("player"):null)) {
|
||||
if (((SubServer) server).stop(player)) {
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sent) {
|
||||
client.sendPacket(new PacketStopServer(0, "Stopping SubServers", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't stop SubServers", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(1, tracker));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (data.contains("force") && data.getBoolean("force")) {
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).terminate((data.contains("player"))?data.getUUID("player"):null)) {
|
||||
client.sendPacket(new PacketStopServer(0, "Terminating SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (force) {
|
||||
if (((SubServer) servers.get(name.toLowerCase())).terminate(player)) {
|
||||
client.sendPacket(new PacketStopServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't terminate SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(1, tracker));
|
||||
}
|
||||
} else {
|
||||
if (((SubServer) servers.get(data.getRawString("server").toLowerCase())).stop((data.contains("player"))?data.getUUID("player"):null)) {
|
||||
client.sendPacket(new PacketStopServer(0, "Stopping SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
if (((SubServer) servers.get(name.toLowerCase())).stop(player)) {
|
||||
client.sendPacket(new PacketStopServer(0, tracker));
|
||||
} else {
|
||||
client.sendPacket(new PacketStopServer(1, "Couldn't stop SubServer", (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(1, tracker));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketStopServer(2, e.getClass().getCanonicalName() + ": " + e.getMessage(), (data.contains("id"))?data.getRawString("id"):null));
|
||||
client.sendPacket(new PacketStopServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return new Version("2.11.0a");
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
|
||||
/**
|
||||
* PacketIn Layout Class
|
||||
*/
|
||||
public interface PacketIn {
|
||||
/**
|
||||
* Execute Incoming Packet
|
||||
*
|
||||
* @param client Client Accepting
|
||||
* @param data Incoming Data
|
||||
*/
|
||||
void execute(Client client, 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.Bungee.Network;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.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,486 +0,0 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import com.dosse.upnp.UPnP;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.IllegalPacketException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Encryption.AES;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import org.msgpack.value.Value;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* SubDataServer Class
|
||||
*/
|
||||
public final class SubDataServer {
|
||||
private static int MAX_QUEUE = 64;
|
||||
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 List<String> allowedAddresses = new ArrayList<String>();
|
||||
private static boolean defaults = false;
|
||||
private HashMap<String, Client> clients = new HashMap<String, Client>();
|
||||
private ServerSocket server;
|
||||
private Cipher cipher;
|
||||
protected SubPlugin plugin;
|
||||
|
||||
/**
|
||||
* SubData Server Instance
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
* @param port Port
|
||||
* @param address Bind
|
||||
* @param cipher Cipher (or null for none)
|
||||
* @throws IOException
|
||||
*/
|
||||
public SubDataServer(SubPlugin plugin, int port, InetAddress address, Cipher cipher) throws IOException {
|
||||
if (Util.isNull(plugin, port, MAX_QUEUE)) throw new NullPointerException();
|
||||
if (address == null) {
|
||||
server = new ServerSocket(port, MAX_QUEUE);
|
||||
allowConnection("127.0.0.1");
|
||||
} else {
|
||||
server = new ServerSocket(port, MAX_QUEUE, address);
|
||||
allowConnection(address.getHostAddress());
|
||||
}
|
||||
if (UPnP.isUPnPAvailable() && plugin.config.get().getSection("Settings").getSection("UPnP", new YAMLSection()).getBoolean("Forward-SubData", false)) UPnP.openPortTCP(port);
|
||||
this.plugin = plugin;
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
if (!defaults) loadDefaults();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
plugin.getPluginManager().registerListener(null, new PacketOutRunEvent(plugin));
|
||||
|
||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
||||
registerPacket(new PacketCommandServer(plugin), "SubServers", "CommandServer");
|
||||
registerPacket(new PacketCreateServer(plugin), "SubServers", "CreateServer");
|
||||
registerPacket(new PacketDownloadGroupInfo(plugin), "SubServers", "DownloadGroupInfo");
|
||||
registerPacket(new PacketDownloadHostInfo(plugin), "SubServers", "DownloadHostInfo");
|
||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
||||
registerPacket(new PacketDownloadNetworkList(plugin), "SubServers", "DownloadNetworkList");
|
||||
registerPacket(new PacketDownloadPlatformInfo(plugin), "SubServers", "DownloadPlatformInfo");
|
||||
registerPacket(new PacketDownloadPlayerList(plugin), "SubServers", "DownloadPlayerList");
|
||||
registerPacket(new PacketDownloadProxyInfo(plugin), "SubServers", "DownloadProxyInfo");
|
||||
registerPacket(new PacketDownloadServerInfo(plugin), "SubServers", "DownloadServerInfo");
|
||||
registerPacket(new PacketExAddServer(), "SubServers", "ExAddServer");
|
||||
registerPacket(new PacketExConfigureHost(plugin), "SubServers", "ExConfigureHost");
|
||||
registerPacket(new PacketExCreateServer(null), "SubServers", "ExCreateServer");
|
||||
registerPacket(new PacketExDeleteServer(), "SubServers", "ExDeleteServer");
|
||||
registerPacket(new PacketExRemoveServer(), "SubServers", "ExRemoveServer");
|
||||
registerPacket(new PacketExUpdateServer(plugin), "SubServers", "ExUpdateServer");
|
||||
registerPacket(new PacketInExLogMessage(), "SubServers", "ExLogMessage");
|
||||
registerPacket(new PacketInExRequestQueue(plugin), "SubServers", "ExRequestQueue");
|
||||
registerPacket(new PacketLinkExHost(plugin), "SubServers", "LinkExHost");
|
||||
registerPacket(new PacketLinkProxy(plugin), "SubServers", "LinkProxy");
|
||||
registerPacket(new PacketLinkServer(plugin), "SubServers", "LinkServer");
|
||||
registerPacket(new PacketRestartServer(plugin), "SubServers", "RestartServer");
|
||||
registerPacket(new PacketStartServer(plugin), "SubServers", "StartServer");
|
||||
registerPacket(new PacketStopServer(plugin), "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(PacketExAddServer.class, "SubServers", "ExAddServer");
|
||||
registerPacket(PacketExConfigureHost.class, "SubServers", "ExConfigureHost");
|
||||
registerPacket(PacketExCreateServer.class, "SubServers", "ExCreateServer");
|
||||
registerPacket(PacketExDeleteServer.class, "SubServers", "ExDeleteServer");
|
||||
registerPacket(PacketExRemoveServer.class, "SubServers", "ExRemoveServer");
|
||||
registerPacket(PacketExUpdateServer.class, "SubServers", "ExUpdateServer");
|
||||
registerPacket(PacketOutExUpdateWhitelist.class, "SubServers", "ExUpdateWhitelist");
|
||||
registerPacket(PacketLinkExHost.class, "SubServers", "LinkExHost");
|
||||
registerPacket(PacketLinkProxy.class, "SubServers", "LinkProxy");
|
||||
registerPacket(PacketLinkServer.class, "SubServers", "LinkServer");
|
||||
registerPacket(PacketOutRunEvent.class, "SubServers", "RunEvent");
|
||||
registerPacket(PacketOutReload.class, "SubServers", "Reload");
|
||||
registerPacket(PacketOutReset.class, "SubServers", "Reset");
|
||||
registerPacket(PacketRestartServer.class, "SubServers", "RestartServer");
|
||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Server Socket
|
||||
*
|
||||
* @return Server Socket
|
||||
*/
|
||||
public ServerSocket getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Server'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(' ', '_'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Client to the Network
|
||||
*
|
||||
* @param socket Client to add
|
||||
* @throws IOException
|
||||
*/
|
||||
public Client addClient(Socket socket) throws IOException {
|
||||
if (Util.isNull(socket)) throw new NullPointerException();
|
||||
if (checkConnection(socket.getInetAddress())) {
|
||||
Client client = new Client(this, socket);
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has connected");
|
||||
clients.put(client.getAddress().toString(), client);
|
||||
return client;
|
||||
} else {
|
||||
System.out.println("SubData > " + socket.getInetAddress().toString() + " attempted to connect, but isn't white-listed");
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs a Client from the Network
|
||||
*
|
||||
* @param socket Socket to search
|
||||
* @return Client
|
||||
*/
|
||||
public Client getClient(Socket socket) {
|
||||
if (Util.isNull(socket)) throw new NullPointerException();
|
||||
return getClient(new InetSocketAddress(socket.getInetAddress(), socket.getPort()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs a Client from the Network
|
||||
*
|
||||
* @param address Address to search
|
||||
* @return Client
|
||||
*/
|
||||
public Client getClient(InetSocketAddress address) {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
return getClient(address.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs a Client from the Network
|
||||
*
|
||||
* @param address Address to search
|
||||
* @return Client
|
||||
*/
|
||||
public Client getClient(String address) {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
return clients.get(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs all the Clients on the Network
|
||||
*
|
||||
* @return Client List
|
||||
*/
|
||||
public Collection<Client> getClients() {
|
||||
return clients.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Client from the Network
|
||||
*
|
||||
* @param client Client to Kick
|
||||
* @throws IOException
|
||||
*/
|
||||
public void removeClient(Client client) throws IOException {
|
||||
if (Util.isNull(client)) throw new NullPointerException();
|
||||
removeClient(client.getAddress());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Client from the Network
|
||||
*
|
||||
* @param address Address to Kick
|
||||
* @throws IOException
|
||||
*/
|
||||
public void removeClient(InetSocketAddress address) throws IOException {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
removeClient(address.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Client from the Network
|
||||
*
|
||||
* @param address Address to Kick
|
||||
* @throws IOException
|
||||
*/
|
||||
public void removeClient(String address) throws IOException {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
if (clients.keySet().contains(address)) {
|
||||
Client client = clients.get(address);
|
||||
plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent(this, client));
|
||||
clients.remove(address);
|
||||
client.disconnect();
|
||||
System.out.println("SubData > " + client.getAddress().toString() + " has disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast a Packet to everything on the Network<br>
|
||||
* <b>Warning:</b> There are usually different types of applications on the network at once, they may not recognise the same packet handles
|
||||
*
|
||||
* @param packet Packet to send
|
||||
*/
|
||||
public void broadcastPacket(PacketOut packet) {
|
||||
if (Util.isNull(packet)) throw new NullPointerException();
|
||||
List<Client> clients = new ArrayList<Client>();
|
||||
clients.addAll(getClients());
|
||||
for (Client client : clients) {
|
||||
client.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow Connections from an Address
|
||||
*
|
||||
* @param address Address to allow
|
||||
*/
|
||||
public static void allowConnection(String address) {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
if (!allowedAddresses.contains(address)) allowedAddresses.add(address);
|
||||
}
|
||||
|
||||
private boolean checkConnection(InetAddress address) {
|
||||
boolean whitelisted = false;
|
||||
Matcher regaddress = Pattern.compile("^(\\d{1,3}).(\\d{1,3}).(\\d{1,3}).(\\d{1,3})$").matcher(address.getHostAddress());
|
||||
if (regaddress.find()) {
|
||||
for (String allowed : allowedAddresses) if (!whitelisted) {
|
||||
Matcher regallowed = Pattern.compile("^(\\d{1,3}|%).(\\d{1,3}|%).(\\d{1,3}|%).(\\d{1,3}|%)$").matcher(allowed);
|
||||
if (regallowed.find() && (
|
||||
(regaddress.group(1).equals(regallowed.group(1)) || regallowed.group(1).equals("%")) &&
|
||||
(regaddress.group(2).equals(regallowed.group(2)) || regallowed.group(2).equals("%")) &&
|
||||
(regaddress.group(3).equals(regallowed.group(3)) || regallowed.group(3).equals("%")) &&
|
||||
(regaddress.group(4).equals(regallowed.group(4)) || regallowed.group(4).equals("%"))
|
||||
)) whitelisted = true;
|
||||
}
|
||||
}
|
||||
SubNetworkConnectEvent event = new SubNetworkConnectEvent(this, address);
|
||||
event.setCancelled(!whitelisted);
|
||||
plugin.getPluginManager().callEvent(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deny Connections from an Address
|
||||
*
|
||||
* @param address Address to deny
|
||||
*/
|
||||
public static void denyConnection(String address) {
|
||||
if (Util.isNull(address)) throw new NullPointerException();
|
||||
allowedAddresses.remove(address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode PacketOut
|
||||
*
|
||||
* @param packet PacketOut
|
||||
* @return JSON Formatted Packet
|
||||
* @throws IllegalPacketException
|
||||
*/
|
||||
protected static YAMLSection encodePacket(Client client, PacketOut packet) throws IllegalPacketException, InvocationTargetException {
|
||||
YAMLSection section = new YAMLSection();
|
||||
|
||||
if (!pOut.keySet().contains(packet.getClass())) throw new IllegalPacketException(packet.getClass().getCanonicalName() + ": Unknown PacketOut Channel: " + packet.getClass().getCanonicalName());
|
||||
if (packet.getVersion() == null) throw new NullPointerException(packet.getClass().getCanonicalName() + ": PacketOut getVersion() cannot be null: " + packet.getClass().getCanonicalName());
|
||||
|
||||
try {
|
||||
YAMLSection contents = packet.generate();
|
||||
section.set("n", pOut.get(packet.getClass()).name());
|
||||
section.set("h", pOut.get(packet.getClass()).get());
|
||||
section.set("v", packet.getVersion());
|
||||
if (contents != null) section.set("c", contents);
|
||||
return section;
|
||||
} catch (Throwable e) {
|
||||
throw new InvocationTargetException(e, packet.getClass().getCanonicalName() + ": Exception while encoding packet");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode PacketIn
|
||||
*
|
||||
* @param data Data to Decode
|
||||
* @return PacketIn
|
||||
* @throws IllegalPacketException
|
||||
*/
|
||||
protected static List<PacketIn> decodePacket(Client client, YAMLSection data) throws IllegalPacketException {
|
||||
if (!data.contains("n") || !data.contains("h") || !data.contains("v")) throw new IllegalPacketException(client.getAddress().toString() + ": 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(client.getAddress().toString() + ": 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() throws IOException {
|
||||
while(clients.size() > 0) {
|
||||
removeClient((Client) clients.values().toArray()[0]);
|
||||
}
|
||||
server.close();
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(server.getLocalPort())) UPnP.closePortTCP(server.getLocalPort());
|
||||
System.out.println("SubServers > The SubData Listener has been closed");
|
||||
plugin.subdata = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.SubDataProtocol;
|
||||
import net.ME1312.SubData.Server.SubDataServer;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkConnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
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(Logger logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (open)
|
||||
ProxyServer.getInstance().getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
instance = new SubProtocol(log);
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
plugin.getPluginManager().registerListener(null, new PacketOutExRunEvent(plugin));
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.setVersion(new Version("2.13.2a+"));
|
||||
|
||||
|
||||
// 00-09: Object Link Packets
|
||||
instance.registerPacket(0x0000, PacketLinkProxy.class);
|
||||
instance.registerPacket(0x0001, PacketLinkExHost.class);
|
||||
instance.registerPacket(0x0002, PacketLinkServer.class);
|
||||
|
||||
instance.registerPacket(0x0000, new PacketLinkProxy(plugin));
|
||||
instance.registerPacket(0x0001, new PacketLinkExHost(plugin));
|
||||
instance.registerPacket(0x0002, new PacketLinkServer(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(0x0010, new PacketDownloadLang(plugin));
|
||||
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo(plugin));
|
||||
instance.registerPacket(0x0012, new PacketDownloadProxyInfo(plugin));
|
||||
instance.registerPacket(0x0013, new PacketDownloadHostInfo(plugin));
|
||||
instance.registerPacket(0x0014, new PacketDownloadGroupInfo(plugin));
|
||||
instance.registerPacket(0x0015, new PacketDownloadServerInfo(plugin));
|
||||
instance.registerPacket(0x0016, new PacketDownloadPlayerList(plugin));
|
||||
|
||||
|
||||
// 30-49: Control Packets
|
||||
//instance.registerPacket(0x0030, PacketInReload.class); TODO
|
||||
instance.registerPacket(0x0031, PacketCreateServer.class);
|
||||
//instance.registerPacket(0x0032, PacketAddServer.class); TODO
|
||||
instance.registerPacket(0x0033, PacketStartServer.class);
|
||||
//instance.registerPacket(0x0034, PacketEditServer.class); TODO
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
//instance.registerPacket(0x0038, PacketRemoveServer.class); TODO
|
||||
//instance.registerPacket(0x0039, PacketDeleteServer.class); TODO
|
||||
|
||||
//instance.registerPacket(0x0030, new PacketInReload(plugin)); TODO
|
||||
instance.registerPacket(0x0031, new PacketCreateServer(plugin));
|
||||
//instance.registerPacket(0x0032, new PacketAddServer(plugin)); TODO
|
||||
instance.registerPacket(0x0033, new PacketStartServer(plugin));
|
||||
//instance.registerPacket(0x0034, new PacketEditServer(plugin)); TODO
|
||||
instance.registerPacket(0x0035, new PacketRestartServer(plugin));
|
||||
instance.registerPacket(0x0036, new PacketCommandServer(plugin));
|
||||
instance.registerPacket(0x0037, new PacketStopServer(plugin));
|
||||
//instance.registerPacket(0x0038, new PacketRemoveServer(plugin)); TODO
|
||||
//instance.registerPacket(0x0039, new PacketDeleteServer(plugin)); TODO
|
||||
|
||||
|
||||
// 50-69: External Host Packets
|
||||
instance.registerPacket(0x0050, PacketExConfigureHost.class);
|
||||
instance.registerPacket(0x0051, PacketExDownloadTemplates.class);
|
||||
//instance.registerPacket(0x0052, PacketInExRequestQueue.class);
|
||||
instance.registerPacket(0x0053, PacketExCreateServer.class);
|
||||
instance.registerPacket(0x0054, PacketExAddServer.class);
|
||||
instance.registerPacket(0x0055, PacketExUpdateServer.class);
|
||||
//instance.registerPacket(0x0056, PacketInExLogMessage.class);
|
||||
instance.registerPacket(0x0057, PacketExDeleteServer.class);
|
||||
instance.registerPacket(0x0058, PacketExRemoveServer.class);
|
||||
|
||||
instance.registerPacket(0x0050, new PacketExConfigureHost(plugin));
|
||||
instance.registerPacket(0x0051, new PacketExDownloadTemplates(plugin));
|
||||
instance.registerPacket(0x0052, new PacketInExRequestQueue(plugin));
|
||||
instance.registerPacket(0x0053, new PacketExCreateServer(null));
|
||||
instance.registerPacket(0x0054, new PacketExAddServer());
|
||||
instance.registerPacket(0x0055, new PacketExUpdateServer(plugin));
|
||||
instance.registerPacket(0x0056, new PacketInExLogMessage());
|
||||
instance.registerPacket(0x0057, new PacketExDeleteServer());
|
||||
instance.registerPacket(0x0058, new PacketExRemoveServer());
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
instance.registerPacket(0x0070, PacketOutExRunEvent.class);
|
||||
instance.registerPacket(0x0071, PacketOutExReset.class);
|
||||
instance.registerPacket(0x0072, PacketOutExReload.class);
|
||||
instance.registerPacket(0x0073, PacketOutExUpdateWhitelist.class);
|
||||
|
||||
//instance.registerPacket(0x0070, new PacketOutRunEvent());
|
||||
//instance.registerPacket(0x0071, new PacketOutReset());
|
||||
//instance.registerPacket(0x0072, new PacketOutReload());
|
||||
//instance.registerPacket(0x0073, new PacketOutExUpdateWhitelist());
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataServer open(InetAddress address, int port, String cipher) throws IOException {
|
||||
SubDataServer subdata = super.open(address, port, cipher);
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
subdata.on.closed(server -> plugin.subdata = null);
|
||||
subdata.on.connect(client -> {
|
||||
if (!plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(client.getServer(), client)).isCancelled()) {
|
||||
client.on.closed(c -> plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent(c.get().getServer(), c.get(), c.name())));
|
||||
return true;
|
||||
} else return false;
|
||||
});
|
||||
|
||||
return subdata;
|
||||
}
|
||||
}
|
@ -1,18 +1,18 @@
|
||||
package net.ME1312.SubServers.Bungee;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import net.ME1312.SubData.Server.DataServer;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddHostEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveHostEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Container;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.UniversalFile;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
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.Server.SubDataServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@ -87,7 +87,7 @@ public final class SubAPI {
|
||||
*
|
||||
* @return SubData Network Manager
|
||||
*/
|
||||
public SubDataServer getSubDataNetwork() {
|
||||
public DataServer getSubDataNetwork() {
|
||||
return plugin.subdata;
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,11 @@ package net.ME1312.SubServers.Bungee;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.CommandX;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Bungee.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.ClientHandler;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@ -96,12 +96,12 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("");
|
||||
new Thread(() -> {
|
||||
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 = plugin.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) {
|
||||
@ -179,7 +179,7 @@ public final class SubCommand extends CommandX {
|
||||
if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
message += ChatColor.WHITE;
|
||||
} else if (((SubServer) server).isRunning()) {
|
||||
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
message += ChatColor.AQUA;
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
@ -212,7 +212,7 @@ public final class SubCommand extends CommandX {
|
||||
for (SubServer subserver : host.getSubServers().values()) {
|
||||
if (i != 0) message += div;
|
||||
if (subserver.isRunning()) {
|
||||
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||
message += ChatColor.AQUA;
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
@ -551,7 +551,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > The BungeeCord library provided does not support console sudo.");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 3) {
|
||||
if (plugin.api.getSubServers().keySet().contains(args[1].toLowerCase()) || SubCreator.isReserved(args[1])) {
|
||||
sender.sendMessage("SubServers > There is already a SubServer with that name");
|
||||
} else if (!plugin.hosts.keySet().contains(args[2].toLowerCase())) {
|
||||
@ -564,15 +564,13 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > There is no template with that name");
|
||||
} else if (!plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3]).isEnabled()) {
|
||||
sender.sendMessage("SubServers > That Template is not enabled");
|
||||
} else if (new Version("1.8").compareTo(new Version(args[4])) > 0) {
|
||||
sender.sendMessage("SubServers > SubCreator cannot create servers before Minecraft 1.8");
|
||||
} else if (args.length > 5 && (Util.isException(() -> Integer.parseInt(args[5])) || Integer.parseInt(args[5]) <= 0 || Integer.parseInt(args[5]) > 65535)) {
|
||||
sender.sendMessage("SubServers > Invalid Port Number");
|
||||
} else {
|
||||
plugin.hosts.get(args[2].toLowerCase()).getCreator().create(args[1], plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3]), new Version(args[4]), (args.length > 5)?Integer.parseInt(args[5]):null);
|
||||
plugin.hosts.get(args[2].toLowerCase()).getCreator().create(args[1], plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3]), (args.length > 4)?new Version(args[4]):null, (args.length > 5)?Integer.parseInt(args[5]):null);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Template> <Version> [Port]");
|
||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) {
|
||||
if (args.length > 1) {
|
||||
@ -584,7 +582,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > That Server is not a SubServer");
|
||||
} else if (((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
|
||||
sender.sendMessage("SubServers > That SubServer is still running");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().deleteSubServer(args[1].toLowerCase())){
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().recycleSubServer(args[1].toLowerCase())){
|
||||
System.out.println("SubServers > Couldn't remove server from memory.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -620,7 +618,7 @@ public final class SubCommand extends CommandX {
|
||||
" Terminate Server: /sub kill <SubServer>",
|
||||
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
||||
" Sudo Server: /sub sudo <SubServer>",
|
||||
" Create Server: /sub create <Name> <Host> <Template> <Version> [Port]",
|
||||
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
|
||||
" Remove Server: /sub delete <SubServer>",
|
||||
"",
|
||||
" To see BungeeCord supplied commands, please visit:",
|
||||
|
@ -3,22 +3,26 @@ package net.ME1312.SubServers.Bungee;
|
||||
import com.dosse.upnp.UPnP;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
|
||||
import net.ME1312.SubServers.Bungee.Event.SubStoppedEvent;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Server.*;
|
||||
import net.ME1312.SubData.Server.Encryption.AES;
|
||||
import net.ME1312.SubData.Server.Encryption.RSA;
|
||||
import net.ME1312.SubServers.Bungee.Event.*;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Cipher;
|
||||
import net.ME1312.SubServers.Bungee.Network.ClientHandler;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutReload;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubDataServer;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReload;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubProtocol;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
@ -32,10 +36,10 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -57,6 +61,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
private YAMLConfig bungeeconfig;
|
||||
public YAMLConfig langconfig;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
public SubDataProtocol subprotocol;
|
||||
public SubDataServer subdata = null;
|
||||
public SubServer sudo = null;
|
||||
public static final Version version = Version.fromString("2.13.2d");
|
||||
@ -89,7 +94,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
System.out.println("SubServers > Created ~/SubServers/config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getMap("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "config.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
@ -191,15 +196,17 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
getPluginManager().registerListener(null, this);
|
||||
|
||||
System.out.println("SubServers > Pre-Parsing Config...");
|
||||
for (String name : config.get().getSection("Servers").getKeys()) {
|
||||
for (String name : config.get().getMap("Servers").getKeys()) {
|
||||
try {
|
||||
if (Util.getCaseInsensitively(config.get().getSection("Hosts").get(), config.get().getSection("Servers").getSection(name).getString("Host")) == null) throw new InvalidServerException("There is no host with this name: " + config.get().getSection("Servers").getSection(name).getString("Host"));
|
||||
legServers.put(name, new BungeeServerInfo(name, new InetSocketAddress(InetAddress.getByName((String) ((Map<String, ?>) Util.getCaseInsensitively(config.get().getSection("Hosts").get(), config.get().getSection("Servers").getSection(name).getString("Host"))).get("Address")), config.get().getSection("Servers").getSection(name).getInt("Port")), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Restricted")));
|
||||
if (Util.getCaseInsensitively(config.get().getMap("Hosts").get(), config.get().getMap("Servers").getMap(name).getString("Host")) == null) throw new InvalidServerException("There is no host with this name: " + config.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
legServers.put(name, new BungeeServerInfo(name, new InetSocketAddress(InetAddress.getByName((String) ((Map<String, ?>) Util.getCaseInsensitively(config.get().getMap("Hosts").get(), config.get().getMap("Servers").getMap(name).getString("Host"))).get("Address")), config.get().getMap("Servers").getMap(name).getInt("Port")),
|
||||
ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")), config.get().getMap("Servers").getMap(name).getBoolean("Restricted")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
subprotocol = SubProtocol.get();
|
||||
System.out.println("SubServers > Loading BungeeCord Libraries...");
|
||||
}
|
||||
|
||||
@ -214,7 +221,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
reload();
|
||||
|
||||
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 {
|
||||
@ -247,34 +254,62 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
YAMLSection prevconfig = config.get();
|
||||
config.reload();
|
||||
langconfig.reload();
|
||||
for (String key : langconfig.get().getSection("Lang").getKeys())
|
||||
api.setLang("SubServers", key, langconfig.get().getSection("Lang").getColoredString(key, '&'));
|
||||
for (String key : langconfig.get().getMap("Lang").getKeys())
|
||||
api.setLang("SubServers", key, ChatColor.translateAlternateColorCodes('&', langconfig.get().getMap("Lang").getString(key)));
|
||||
|
||||
if (subdata == null || // SubData Server must be reset
|
||||
!config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").equals(prevconfig.getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391")) ||
|
||||
!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equals(prevconfig.getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE"))
|
||||
!config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").equals(prevconfig.getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391")) ||
|
||||
!config.get().getMap("Settings").getMap("SubData").getRawString("Encryption", "NONE").equals(prevconfig.getMap("Settings").getMap("SubData").getRawString("Encryption", "NONE"))
|
||||
) {
|
||||
if (subdata != null) subdata.destroy();
|
||||
if (subdata != null) {
|
||||
subdata.close();
|
||||
Util.isException(subdata::waitFor);
|
||||
}
|
||||
|
||||
Cipher cipher = null;
|
||||
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
|
||||
if (config.get().getSection("Settings").getSection("SubData").getString("Password", "").length() == 0) {
|
||||
System.out.println("SubData > Cannot encrypt connection without a password");
|
||||
} else if (!SubDataServer.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 = SubDataServer.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");
|
||||
String cipher = config.get().getMap("Settings").getMap("SubData").getRawString("Encryption", "NULL");
|
||||
String[] ciphers = (cipher.contains("/"))?cipher.split("/"):new String[]{cipher};
|
||||
if (ciphers[0].equals("AES") || ciphers[0].equals("AES-128") || ciphers[0].equals("AES-192") || ciphers[0].equals("AES-256")) {
|
||||
if (config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() == 0) {
|
||||
byte[] bytes = new byte[32];
|
||||
new SecureRandom().nextBytes(bytes);
|
||||
String random = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
|
||||
if (random.length() > bytes.length) random = random.substring(0, bytes.length);
|
||||
config.get().getMap("Settings").getMap("SubData").set("Password", random);
|
||||
config.save();
|
||||
}
|
||||
|
||||
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 > Encrypting SubData with AES:");
|
||||
System.out.println("SubData > Use the password in config.yml to allow clients to connect");
|
||||
} else if (ciphers[0].equals("RSA") || ciphers[0].equals("RSA-2048") || ciphers[0].equals("RSA-3072") || ciphers[0].equals("RSA-4096")) {
|
||||
try {
|
||||
int length = (ciphers[0].contains("-"))?Integer.parseInt(ciphers[0].split("-")[1]):2048;
|
||||
subprotocol.registerCipher("RSA", new RSA(length, new UniversalFile("SubServers:Cache:private.rsa.key"), new UniversalFile("SubServers:subdata.rsa.key")));
|
||||
cipher = "RSA" + cipher.substring(ciphers[0].length());
|
||||
|
||||
System.out.println("SubData > Encrypting SubData with RSA:");
|
||||
System.out.println("SubData > Copy your subdata.rsa.key to clients to allow them to connect");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
subdata = new SubDataServer(this, Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1]),
|
||||
(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||
cipher);
|
||||
System.out.println("SubServers > SubData Direct Listening on " + subdata.getServer().getLocalSocketAddress().toString());
|
||||
loop();
|
||||
|
||||
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]), cipher);
|
||||
} // Add new entries to Allowed-Connections
|
||||
for (String s : config.get().getSection("Settings").getSection("SubData").getStringList("Allowed-Connections", new ArrayList<String>())) {
|
||||
for (String s : config.get().getMap("Settings").getMap("SubData").getStringList("Allowed-Connections", new ArrayList<String>())) {
|
||||
try {
|
||||
SubDataServer.allowConnection(s);
|
||||
subdata.whitelist(s);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -310,33 +345,33 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
int hosts = 0;
|
||||
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading Hosts...");
|
||||
for (String name : config.get().getSection("Hosts").getKeys()) {
|
||||
for (String name : config.get().getMap("Hosts").getKeys()) {
|
||||
if (!ukeys.contains(name.toLowerCase())) try {
|
||||
if (!hostDrivers.keySet().contains(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
|
||||
if (!hostDrivers.keySet().contains(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
|
||||
Host host = this.hosts.get(name.toLowerCase());
|
||||
if (host == null || // Host must be reset
|
||||
!hostDrivers.get(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_')).equals(host.getClass()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Address").equals(host.getAddress().getHostAddress()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Directory").equals(host.getPath()) ||
|
||||
!config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash").equals(host.getCreator().getBashDirectory())
|
||||
!hostDrivers.get(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toUpperCase().replace('-', '_').replace(' ', '_')).equals(host.getClass()) ||
|
||||
!config.get().getMap("Hosts").getMap(name).getRawString("Address").equals(host.getAddress().getHostAddress()) ||
|
||||
!config.get().getMap("Hosts").getMap(name).getRawString("Directory").equals(host.getPath()) ||
|
||||
!config.get().getMap("Hosts").getMap(name).getRawString("Git-Bash").equals(host.getCreator().getBashDirectory())
|
||||
) {
|
||||
if (host != null) api.forceRemoveHost(name);
|
||||
host = api.addHost(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toLowerCase(), name, config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"),
|
||||
Range.closed(Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[1])),
|
||||
config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true), InetAddress.getByName(config.get().getSection("Hosts").getSection(name).getRawString("Address")),
|
||||
config.get().getSection("Hosts").getSection(name).getRawString("Directory"), config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash"));
|
||||
host = api.addHost(config.get().getMap("Hosts").getMap(name).getRawString("Driver").toLowerCase(), name, config.get().getMap("Hosts").getMap(name).getBoolean("Enabled"),
|
||||
Range.closed(Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[1])),
|
||||
config.get().getMap("Hosts").getMap(name).getBoolean("Log-Creator", true), InetAddress.getByName(config.get().getMap("Hosts").getMap(name).getRawString("Address")),
|
||||
config.get().getMap("Hosts").getMap(name).getRawString("Directory"), config.get().getMap("Hosts").getMap(name).getRawString("Git-Bash"));
|
||||
} else { // Host wasn't reset, so check for these changes
|
||||
if (config.get().getSection("Hosts").getSection(name).getBoolean("Enabled") != host.isEnabled())
|
||||
host.setEnabled(config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"));
|
||||
if (!config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").equals(prevconfig.getSection("Hosts", new YAMLSection()).getSection(name, new YAMLSection()).getRawString("Port-Range", "25500-25559")))
|
||||
host.getCreator().setPortRange(Range.closed(Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getSection("Hosts").getSection(name).getRawString("Port-Range", "25500-25559").split("-")[1])));
|
||||
if (config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true) != host.getCreator().isLogging())
|
||||
host.getCreator().setLogging(config.get().getSection("Hosts").getSection(name).getBoolean("Log-Creator", true));
|
||||
if (config.get().getMap("Hosts").getMap(name).getBoolean("Enabled") != host.isEnabled())
|
||||
host.setEnabled(config.get().getMap("Hosts").getMap(name).getBoolean("Enabled"));
|
||||
if (!config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").equals(prevconfig.getMap("Hosts", new ObjectMap<String>()).getMap(name, new ObjectMap<String>()).getRawString("Port-Range", "25500-25559")))
|
||||
host.getCreator().setPortRange(Range.closed(Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[0]), Integer.parseInt(config.get().getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559").split("-")[1])));
|
||||
if (config.get().getMap("Hosts").getMap(name).getBoolean("Log-Creator", true) != host.getCreator().isLogging())
|
||||
host.getCreator().setLogging(config.get().getMap("Hosts").getMap(name).getBoolean("Log-Creator", true));
|
||||
} // Check for other changes
|
||||
if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Display") && ((config.get().getSection("Hosts").getSection(name).getString("Display").length() == 0 && !host.getDisplayName().equals(host.getName())) || !config.get().getSection("Hosts").getSection(name).getString("Display").equals(host.getDisplayName())))
|
||||
host.setDisplayName(config.get().getSection("Hosts").getSection(name).getString("Display"));
|
||||
if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Extra"))
|
||||
for (String extra : config.get().getSection("Hosts").getSection(name).getSection("Extra").getKeys()) host.addExtra(extra, config.get().getSection("Hosts").getSection(name).getSection("Extra").getObject(extra));
|
||||
if (config.get().getMap("Hosts").getMap(name).getKeys().contains("Display") && ((config.get().getMap("Hosts").getMap(name).getString("Display").length() == 0 && !host.getDisplayName().equals(host.getName())) || !config.get().getMap("Hosts").getMap(name).getString("Display").equals(host.getDisplayName())))
|
||||
host.setDisplayName(config.get().getMap("Hosts").getMap(name).getString("Display"));
|
||||
if (config.get().getMap("Hosts").getMap(name).getKeys().contains("Extra"))
|
||||
for (String extra : config.get().getMap("Hosts").getMap(name).getMap("Extra").getKeys()) host.addExtra(extra, config.get().getMap("Hosts").getMap(name).getMap("Extra").getObject(extra));
|
||||
ukeys.add(name.toLowerCase());
|
||||
hosts++;
|
||||
} catch (Exception e) {
|
||||
@ -348,35 +383,35 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
int servers = 0;
|
||||
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading Servers...");
|
||||
bungeeconfig.reload();
|
||||
for (String name : bungeeconfig.get().getSection("servers").getKeys()) {
|
||||
for (String name : bungeeconfig.get().getMap("servers").getKeys()) {
|
||||
if (!ukeys.contains(name.toLowerCase())) try {
|
||||
Server server = api.getServer(name);
|
||||
if (server == null || !(server instanceof SubServer)) {
|
||||
if (server == null || // Server must be reset
|
||||
bungeeconfig.get().getSection("servers").getSection(name).getRawString("address").equals(server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort())
|
||||
bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").equals(server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort())
|
||||
) {
|
||||
if (server != null) api.forceRemoveServer(name);
|
||||
server = api.addServer(name, InetAddress.getByName(bungeeconfig.get().getSection("servers").getSection(name).getRawString("address").split(":")[0]),
|
||||
Integer.parseInt(bungeeconfig.get().getSection("servers").getSection(name).getRawString("address").split(":")[1]), bungeeconfig.get().getSection("servers").getSection(name).getColoredString("motd", '&'),
|
||||
bungeeconfig.get().getSection("servers").getSection(name).getBoolean("hidden", false), bungeeconfig.get().getSection("servers").getSection(name).getBoolean("restricted"));
|
||||
server = api.addServer(name, InetAddress.getByName(bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").split(":")[0]),
|
||||
Integer.parseInt(bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").split(":")[1]), ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")),
|
||||
bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false), bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
} else { // Server wasn't reset, so check for these changes
|
||||
if (!bungeeconfig.get().getSection("servers").getSection(name).getColoredString("motd", '&').equals(server.getMotd()))
|
||||
server.setMotd(bungeeconfig.get().getSection("servers").getSection(name).getColoredString("motd", '&'));
|
||||
if (bungeeconfig.get().getSection("servers").getSection(name).getBoolean("hidden", false) != server.isHidden())
|
||||
server.setHidden(bungeeconfig.get().getSection("servers").getSection(name).getBoolean("hidden", false));
|
||||
if (bungeeconfig.get().getSection("servers").getSection(name).getBoolean("restricted") != server.isRestricted())
|
||||
server.setRestricted(bungeeconfig.get().getSection("servers").getSection(name).getBoolean("restricted"));
|
||||
if (!ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false) != server.isHidden())
|
||||
server.setHidden(bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted") != server.isRestricted())
|
||||
server.setRestricted(bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
} // Check for other changes
|
||||
if (bungeeconfig.get().getSection("servers").getSection(name).getKeys().contains("display") && ((bungeeconfig.get().getSection("servers").getSection(name).getRawString("display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !bungeeconfig.get().getSection("servers").getSection(name).getRawString("display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(bungeeconfig.get().getSection("servers").getSection(name).getString("display"));
|
||||
if (bungeeconfig.get().getSection("servers").getSection(name).getKeys().contains("group")) {
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getKeys().contains("display") && ((bungeeconfig.get().getMap("servers").getMap(name).getRawString("display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !bungeeconfig.get().getMap("servers").getMap(name).getRawString("display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(bungeeconfig.get().getMap("servers").getMap(name).getString("display"));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getKeys().contains("group")) {
|
||||
for (String group : server.getGroups()) server.removeGroup(group);
|
||||
for (String group : bungeeconfig.get().getSection("servers").getSection(name).getStringList("group")) server.addGroup(group);
|
||||
for (String group : bungeeconfig.get().getMap("servers").getMap(name).getStringList("group")) server.addGroup(group);
|
||||
}
|
||||
if (bungeeconfig.get().getSection("servers").getSection(name).getKeys().contains("extra"))
|
||||
for (String extra : config.get().getSection("servers").getSection(name).getSection("extra").getKeys()) server.addExtra(extra, config.get().getSection("servers").getSection(name).getSection("extra").getObject(extra));
|
||||
if (bungeeconfig.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)
|
||||
server.getSubData().sendPacket(new PacketOutReload(null));
|
||||
((SubDataClient) server.getSubData()).sendPacket(new PacketOutExReload(null));
|
||||
ukeys.add(name.toLowerCase());
|
||||
servers++;
|
||||
}
|
||||
@ -400,43 +435,43 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}, "SubServers.Bungee::System_Shutdown"));
|
||||
running = true;
|
||||
List<String> autorun = new LinkedList<String>();
|
||||
for (String name : config.get().getSection("Servers").getKeys()) {
|
||||
for (String name : config.get().getMap("Servers").getKeys()) {
|
||||
if (!ukeys.contains(name.toLowerCase())) try {
|
||||
if (!this.hosts.keySet().contains(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + config.get().getSection("Servers").getSection(name).getString("Host"));
|
||||
if (!this.hosts.keySet().contains(config.get().getMap("Servers").getMap(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + config.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
if (exServers.keySet().contains(name.toLowerCase())) {
|
||||
exServers.remove(name.toLowerCase());
|
||||
servers--;
|
||||
}
|
||||
SubServer server = api.getSubServer(name);
|
||||
if (server != null && server.isEditable()) { // Server can edit() (May be reset depending on change severity)
|
||||
YAMLSection edits = new YAMLSection();
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Enabled") != server.isEnabled())
|
||||
edits.set("enabled", config.get().getSection("Servers").getSection(name).getBoolean("Enabled"));
|
||||
if (config.get().getSection("Servers").getSection(name).getKeys().contains("Display") && ((config.get().getSection("Servers").getSection(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getSection("Servers").getSection(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
edits.set("display", config.get().getSection("Servers").getSection(name).getRawString("Display"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getString("Host").equalsIgnoreCase(server.getHost().getName()))
|
||||
edits.set("host", config.get().getSection("Servers").getSection(name).getRawString("Host"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getStringList("Group").equals(server.getGroups()))
|
||||
edits.set("group", config.get().getSection("Servers").getSection(name).getRawStringList("Group"));
|
||||
if (config.get().getSection("Servers").getSection(name).getInt("Port") != server.getAddress().getPort())
|
||||
edits.set("port", config.get().getSection("Servers").getSection(name).getInt("Port"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&').equals(server.getMotd()))
|
||||
edits.set("motd", config.get().getSection("Servers").getSection(name).getRawString("Motd"));
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Log") != server.isLogging())
|
||||
edits.set("log", config.get().getSection("Servers").getSection(name).getBoolean("Log"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()))
|
||||
edits.set("dir", config.get().getSection("Servers").getSection(name).getRawString("Directory"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Executable").equals(server.getExecutable()))
|
||||
edits.set("exec", config.get().getSection("Servers").getSection(name).getRawString("Executable"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
edits.set("stop-cmd", config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"));
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getSection("Servers").getSection(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
ObjectMap<String> edits = new ObjectMap<String>();
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
edits.set("enabled", config.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Display") && ((config.get().getMap("Servers").getMap(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getMap("Servers").getMap(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
edits.set("display", config.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()))
|
||||
edits.set("host", config.get().getMap("Servers").getMap(name).getRawString("Host"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getStringList("Group").equals(server.getGroups()))
|
||||
edits.set("group", config.get().getMap("Servers").getMap(name).getRawStringList("Group"));
|
||||
if (config.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort())
|
||||
edits.set("port", config.get().getMap("Servers").getMap(name).getInt("Port"));
|
||||
if (!(ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd())))
|
||||
edits.set("motd", config.get().getMap("Servers").getMap(name).getRawString("Motd"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
edits.set("log", config.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()))
|
||||
edits.set("dir", config.get().getMap("Servers").getMap(name).getRawString("Directory"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable()))
|
||||
edits.set("exec", config.get().getMap("Servers").getMap(name).getRawString("Executable"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
edits.set("stop-cmd", config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null && action != server.getStopAction())
|
||||
edits.set("stop-action", action.toString());
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Restricted") != server.isRestricted())
|
||||
edits.set("restricted", config.get().getSection("Servers").getSection(name).getBoolean("Restricted"));
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Hidden") != server.isHidden())
|
||||
edits.set("hidden", config.get().getSection("Servers").getSection(name).getBoolean("Hidden"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
edits.set("restricted", config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
edits.set("hidden", config.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
|
||||
|
||||
if (edits.getKeys().size() > 0) {
|
||||
@ -445,43 +480,43 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
} else { // Server cannot edit()
|
||||
if (server == null || // Server must be reset
|
||||
!config.get().getSection("Servers").getSection(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
||||
config.get().getSection("Servers").getSection(name).getInt("Port") != server.getAddress().getPort() ||
|
||||
!config.get().getSection("Servers").getSection(name).getRawString("Directory").equals(server.getPath()) ||
|
||||
!config.get().getSection("Servers").getSection(name).getRawString("Executable").equals(server.getExecutable())
|
||||
!config.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
||||
config.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort() ||
|
||||
!config.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()) ||
|
||||
!config.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable())
|
||||
) {
|
||||
if (server != null) server.getHost().forceRemoveSubServer(name);
|
||||
server = this.hosts.get(config.get().getSection("Servers").getSection(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getSection("Servers").getSection(name).getBoolean("Enabled"),
|
||||
config.get().getSection("Servers").getSection(name).getInt("Port"), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Log"),
|
||||
config.get().getSection("Servers").getSection(name).getRawString("Directory"), config.get().getSection("Servers").getSection(name).getRawString("Executable"), config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"),
|
||||
config.get().getSection("Servers").getSection(name).getBoolean("Hidden"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"));
|
||||
server = this.hosts.get(config.get().getMap("Servers").getMap(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getMap("Servers").getMap(name).getBoolean("Enabled"),
|
||||
config.get().getMap("Servers").getMap(name).getInt("Port"), ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")), config.get().getMap("Servers").getMap(name).getBoolean("Log"),
|
||||
config.get().getMap("Servers").getMap(name).getRawString("Directory"), config.get().getMap("Servers").getMap(name).getRawString("Executable"), config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"),
|
||||
config.get().getMap("Servers").getMap(name).getBoolean("Hidden"), config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
} else { // Server doesn't need to reset
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Enabled") != server.isEnabled())
|
||||
server.setEnabled(config.get().getSection("Servers").getSection(name).getBoolean("Enabled"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&').equals(server.getMotd()))
|
||||
server.setMotd(config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'));
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Log") != server.isLogging())
|
||||
server.setLogging(config.get().getSection("Servers").getSection(name).getBoolean("Log"));
|
||||
if (!config.get().getSection("Servers").getSection(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
server.setStopCommand(config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"));
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Restricted") != server.isRestricted())
|
||||
server.setRestricted(config.get().getSection("Servers").getSection(name).getBoolean("Restricted"));
|
||||
if (config.get().getSection("Servers").getSection(name).getBoolean("Hidden") != server.isHidden())
|
||||
server.setHidden(config.get().getSection("Servers").getSection(name).getBoolean("Hidden"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
server.setEnabled(config.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
if (!ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
server.setLogging(config.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
server.setStopCommand(config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
server.setRestricted(config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
server.setHidden(config.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
} // Apply these changes regardless of reset
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getSection("Servers").getSection(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null && action != server.getStopAction())
|
||||
server.setStopAction(action);
|
||||
if (!status && config.get().getSection("Servers").getSection(name).getBoolean("Run-On-Launch"))
|
||||
if (!status && config.get().getMap("Servers").getMap(name).getBoolean("Run-On-Launch"))
|
||||
autorun.add(name.toLowerCase());
|
||||
if (config.get().getSection("Servers").getSection(name).getKeys().contains("Display") && ((config.get().getSection("Servers").getSection(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getSection("Servers").getSection(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(config.get().getSection("Servers").getSection(name).getRawString("Display"));
|
||||
if (config.get().getSection("Servers").getSection(name).getKeys().contains("Group")) {
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Display") && ((config.get().getMap("Servers").getMap(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getMap("Servers").getMap(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(config.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Group")) {
|
||||
for (String group : server.getGroups()) server.removeGroup(group);
|
||||
for (String group : config.get().getSection("Servers").getSection(name).getStringList("Group")) server.addGroup(group);
|
||||
for (String group : config.get().getMap("Servers").getMap(name).getStringList("Group")) server.addGroup(group);
|
||||
}
|
||||
} // Apply these changes regardless of edit/reset
|
||||
if (config.get().getSection("Servers").getSection(name).getKeys().contains("Extra")) for (String extra : config.get().getSection("Servers").getSection(name).getSection("Extra").getKeys()) server.addExtra(extra, config.get().getSection("Servers").getSection(name).getSection("Extra").getObject(extra));
|
||||
if (config.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));
|
||||
ukeys.add(name.toLowerCase());
|
||||
subservers++;
|
||||
} catch (Exception e) {
|
||||
@ -490,7 +525,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
for (String name : ukeys) {
|
||||
SubServer server = api.getSubServer(name);
|
||||
for (String oname : config.get().getSection("Servers").getSection(server.getName()).getRawStringList("Incompatible", new ArrayList<>())) {
|
||||
for (String oname : config.get().getMap("Servers").getMap(server.getName()).getRawStringList("Incompatible", new ArrayList<>())) {
|
||||
SubServer oserver = api.getSubServer(oname);
|
||||
if (oserver != null && server.isCompatible(oserver)) server.toggleCompatibility(oserver);
|
||||
}
|
||||
@ -514,13 +549,13 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
if (status) {
|
||||
for (Host host : api.getHosts().values()) if (host instanceof ClientHandler && ((ClientHandler) host).getSubData() != null) ((ClientHandler) host).getSubData().sendPacket(new PacketOutReload(null));
|
||||
for (Server server : api.getServers().values()) if (server.getSubData() != null) server.getSubData().sendPacket(new PacketOutReload(null));
|
||||
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));
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
long scd = TimeUnit.SECONDS.toMillis(config.get().getSection("Settings").getLong("Run-On-Launch-Timeout", 0L));
|
||||
long scd = TimeUnit.SECONDS.toMillis(config.get().getMap("Settings").getLong("Run-On-Launch-Timeout", 0L));
|
||||
if (autorun.size() > 0) for (Host host : api.getHosts().values()) {
|
||||
List<String> ar = new LinkedList<String>();
|
||||
for (String name : autorun) if (host.getSubServer(name) != null) ar.add(name);
|
||||
@ -553,7 +588,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
@ -567,12 +602,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) {
|
||||
@ -586,18 +621,6 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}, 0, TimeUnit.DAYS.toMillis(2));
|
||||
}
|
||||
|
||||
private void loop() {
|
||||
new Thread(() -> {
|
||||
while (subdata != null) {
|
||||
try {
|
||||
subdata.addClient(subdata.getServer().accept());
|
||||
} catch (IOException e) {
|
||||
if (!(e instanceof SocketException)) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "SubServers.Bungee::SubData_Connection_Listener").start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all changes made by startListeners
|
||||
*
|
||||
@ -621,7 +644,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
shutdown();
|
||||
|
||||
subdata.destroy();
|
||||
subdata.close();
|
||||
|
||||
for (ListenerInfo listener : getConfig().getListeners()) {
|
||||
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(listener.getHost().getPort())) UPnP.closePortTCP(listener.getHost().getPort());
|
||||
|
@ -14,6 +14,14 @@
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>me1312-repo</id>
|
||||
<url>https://src.me1312.net/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>puharesource-repo</id>
|
||||
<url>https://repo.puha.io/repo/</url>
|
||||
@ -32,9 +40,21 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>msgpack-core</artifactId>
|
||||
<version>0.8.16</version>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.10-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w16a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w16b</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -135,6 +155,8 @@
|
||||
<reportOutputDirectory>${basedir}/../../Javadoc/SubServers.Client.Bukkit</reportOutputDirectory>
|
||||
<additionalOptions>-Xdoclint:none</additionalOptions>
|
||||
<links>
|
||||
<link>https://src.me1312.net/jenkins/job/GalaxiEngine/javadoc/GalaxiUtil/</link>
|
||||
<link>https://src.me1312.net/jenkins/job/SubData/javadoc/Client/</link>
|
||||
<link>https://hub.spigotmc.org/javadocs/spigot/</link>
|
||||
</links>
|
||||
</configuration>
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@ -31,7 +30,7 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
if (Util.isNull(host, name, template, version, port)) throw new NullPointerException();
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLValue;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@ -16,7 +16,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;
|
||||
|
||||
/**
|
||||
@ -29,11 +29,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.contains(".")?section.get("."):null);
|
||||
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.contains(".")?section.get("."):null);
|
||||
this.perm = permanent;
|
||||
}
|
||||
|
||||
@ -56,7 +56,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.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user