2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee.Network.Packet;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2018-04-15 03:53:51 +02:00
|
|
|
import com.google.gson.Gson;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Host.Server;
|
|
|
|
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
2018-04-15 03:53:51 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
2017-01-30 21:22:36 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Util;
|
2016-12-24 05:55:17 +01:00
|
|
|
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;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2018-04-15 03:53:51 +02:00
|
|
|
import java.util.Map;
|
2017-07-21 22:45:41 +02:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* Download Server Info Packet
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
2016-12-05 04:21:04 +01:00
|
|
|
private SubPlugin plugin;
|
|
|
|
private Server server;
|
2016-12-15 22:04:39 +01:00
|
|
|
private String id;
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* New PacketDownloadServerInfo (In)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public PacketDownloadServerInfo(SubPlugin plugin) {
|
2017-01-30 21:22:36 +01:00
|
|
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
2016-12-15 22:04:39 +01:00
|
|
|
this.plugin = plugin;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
2017-01-07 20:06:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New PacketDownloadServerInfo (Out)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
|
|
|
* @param server Server
|
|
|
|
* @param id Receiver ID
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public PacketDownloadServerInfo(SubPlugin plugin, Server server, String id) {
|
2017-04-10 05:39:22 +02:00
|
|
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
2016-12-05 04:21:04 +01:00
|
|
|
this.plugin = plugin;
|
2016-12-15 22:04:39 +01:00
|
|
|
this.server = server;
|
|
|
|
this.id = id;
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-15 03:53:51 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public YAMLSection generate() {
|
|
|
|
YAMLSection json = new YAMLSection();
|
|
|
|
json.set("id", id);
|
|
|
|
json.set("type", (server == null)?"invalid":((server instanceof SubServer)?"subserver":"server"));
|
|
|
|
YAMLSection info = new YAMLSection();
|
2016-12-05 04:21:04 +01:00
|
|
|
|
2018-03-21 21:45:59 +01:00
|
|
|
if (server != null) {
|
2018-04-15 03:53:51 +02:00
|
|
|
info = new YAMLSection(new Gson().fromJson(server.toString(), Map.class));
|
2018-03-21 21:45:59 +01:00
|
|
|
info.remove("type");
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 03:53:51 +02:00
|
|
|
json.set("server", info);
|
2016-12-05 04:21:04 +01:00
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-15 03:53:51 +02:00
|
|
|
public void execute(Client client, YAMLSection data) {
|
|
|
|
client.sendPacket(new PacketDownloadServerInfo(plugin, plugin.api.getServer(data.getRawString("server")), (data.contains("id"))?data.getRawString("id"):null));
|
2016-12-05 04:21:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Version getVersion() {
|
|
|
|
return new Version("2.11.0a");
|
|
|
|
}
|
|
|
|
}
|