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;
|
2017-12-10 01:30:06 +01:00
|
|
|
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;
|
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-15 22:04:39 +01:00
|
|
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
2016-12-05 04:21:04 +01:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2017-07-21 22:45:41 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2017-12-10 15:14:49 +01:00
|
|
|
import java.util.UUID;
|
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
|
|
|
|
public JSONObject generate() {
|
|
|
|
JSONObject json = new JSONObject();
|
2016-12-15 22:04:39 +01:00
|
|
|
json.put("id", id);
|
2016-12-05 04:21:04 +01:00
|
|
|
json.put("type", (server == null)?"invalid":((server instanceof SubServer)?"subserver":"server"));
|
2016-12-15 22:04:39 +01:00
|
|
|
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) {
|
2016-12-15 22:04:39 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|