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

78 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
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.Host.ServerContainer;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Host.SubServer;
2017-12-10 15:14:49 +01:00
import net.ME1312.SubServers.Bungee.Library.NamedContainer;
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;
import net.md_5.bungee.api.connection.ProxiedPlayer;
2016-12-05 04:21:04 +01:00
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
2017-12-10 15:14:49 +01:00
import java.util.UUID;
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
public JSONObject generate() {
JSONObject json = new JSONObject();
json.put("id", id);
2016-12-05 04:21:04 +01:00
json.put("type", (server == null)?"invalid":((server instanceof SubServer)?"subserver":"server"));
JSONObject info = new JSONObject();
2016-12-05 04:21:04 +01:00
2018-03-21 21:45:59 +01:00
if (server != null) {
info = new JSONObject(server.toString());
info.remove("type");
2016-12-05 04:21:04 +01:00
}
json.put("server", info);
return json;
}
@Override
public void execute(Client client, JSONObject data) {
client.sendPacket(new PacketDownloadServerInfo(plugin, plugin.api.getServer(data.getString("server")), (data.keySet().contains("id"))?data.getString("id"):null));
2016-12-05 04:21:04 +01:00
}
@Override
public Version getVersion() {
return new Version("2.11.0a");
}
}