SubServers-2/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerInfo.java

75 lines
2.3 KiB
Java
Raw Normal View History

2016-12-24 05:55:17 +01:00
package net.ME1312.SubServers.Bungee.Network.Packet;
2016-12-05 04:21:04 +01: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;
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
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
import java.util.Map;
2017-01-07 20:06:54 +01:00
/**
* Download Server Info Packet
*/
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
2016-12-05 04:21:04 +01:00
private SubPlugin plugin;
private Server server;
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
*/
public PacketDownloadServerInfo(SubPlugin plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
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
*/
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;
this.server = server;
this.id = id;
2016-12-05 04:21:04 +01:00
}
@Override
@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) {
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
}
json.set("server", info);
2016-12-05 04:21:04 +01:00
return json;
}
@Override
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");
}
}