mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-22 12:44:51 +02:00
This commit removes the org.JSON library where alternatives are already provided (Bungee & Bukkit provide Gson). This change was made to improve compatability with BungeeCord plugins and reduce file sizes. This means big changes to the SubData API, which heavily relied on org.JSON. Now we submit our data through YAMLSection to be converted and sent over the network.
65 lines
1.9 KiB
Java
65 lines
1.9 KiB
Java
package net.ME1312.SubServers.Host.Network.Packet;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
|
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
|
import net.ME1312.SubServers.Host.Library.Util;
|
|
import net.ME1312.SubServers.Host.Library.Version.Version;
|
|
import net.ME1312.SubServers.Host.Network.PacketIn;
|
|
import net.ME1312.SubServers.Host.Network.PacketOut;
|
|
import net.ME1312.SubServers.Host.Network.SubDataClient;
|
|
import net.ME1312.SubServers.Host.ExHost;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
|
|
/**
|
|
* Link Host Packet
|
|
*/
|
|
public class PacketLinkExHost implements PacketIn, PacketOut {
|
|
private ExHost host;
|
|
private Logger log;
|
|
|
|
/**
|
|
* New PacketLinkHost
|
|
*
|
|
* @param host SubServers.Host
|
|
*/
|
|
public PacketLinkExHost(ExHost host) {
|
|
if (Util.isNull(host)) throw new NullPointerException();
|
|
this.host = host;
|
|
try {
|
|
Field f = SubDataClient.class.getDeclaredField("log");
|
|
f.setAccessible(true);
|
|
this.log = (Logger) f.get(null);
|
|
f.setAccessible(false);
|
|
} catch (IllegalAccessException | NoSuchFieldException e) {}
|
|
}
|
|
|
|
@Override
|
|
public YAMLSection generate() {
|
|
YAMLSection data = new YAMLSection();
|
|
data.set("name", host.subdata.getName());
|
|
return data;
|
|
}
|
|
|
|
@Override
|
|
public void execute(YAMLSection data) {
|
|
if (data.getInt("r") == 0) {
|
|
try {
|
|
Method m = SubDataClient.class.getDeclaredMethod("init");
|
|
m.setAccessible(true);
|
|
m.invoke(host.subdata);
|
|
m.setAccessible(false);
|
|
} catch (Exception e) {}
|
|
} else {
|
|
log.info.println("Could not link name with host: " + data.getRawString("m"));
|
|
host.stop(1);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Version getVersion() {
|
|
return new Version("2.11.0a");
|
|
}
|
|
}
|