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

76 lines
2.1 KiB
Java
Raw Normal View History

2016-12-24 05:55:17 +01:00
package net.ME1312.SubServers.Bungee.Network.Packet;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.Host.SubCreator;
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;
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.ClientHandler;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Network.PacketIn;
import net.ME1312.SubServers.Bungee.Network.PacketOut;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.SubPlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.json.JSONObject;
2017-11-22 22:58:33 +01:00
import java.util.ArrayList;
2017-12-10 15:14:49 +01:00
import java.util.UUID;
2017-11-22 22:58:33 +01:00
2017-01-07 20:06:54 +01:00
/**
* Download Host Info Packet
*/
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
private SubPlugin plugin;
private Host host;
private String id;
2017-01-07 20:06:54 +01:00
/**
* New PacketDownloadHostInfo (In)
*
* @param plugin SubPlugin
*/
public PacketDownloadHostInfo(SubPlugin plugin) {
this.plugin = plugin;
}
2017-01-07 20:06:54 +01:00
/**
* New PacketDownloadHostInfo (Out)
*
* @param plugin SubPlugin
* @param host Host
* @param id Receiver ID
*/
public PacketDownloadHostInfo(SubPlugin plugin, Host host, String id) {
this.plugin = plugin;
this.host = host;
this.id = id;
}
@Override
public JSONObject generate() {
JSONObject json = new JSONObject();
json.put("id", id);
JSONObject info = new JSONObject();
if (host != null) {
json.put("valid", true);
2018-03-21 21:45:59 +01:00
info = new JSONObject(host.toString());
info.remove("type");
} else json.put("valid", false);
json.put("host", info);
return json;
}
@Override
public void execute(Client client, JSONObject data) {
client.sendPacket(new PacketDownloadHostInfo(plugin, plugin.api.getHost(data.getString("host")), (data.keySet().contains("id"))?data.getString("id"):null));
}
@Override
public Version getVersion() {
return new Version("2.11.0a");
}
}