2016-12-24 05:55:17 +01:00
|
|
|
package net.ME1312.SubServers.Bungee.Network.Packet;
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2018-08-09 20:54:56 +02:00
|
|
|
import com.google.gson.Gson;
|
2016-12-24 05:55:17 +01:00
|
|
|
import net.ME1312.SubServers.Bungee.Host.Host;
|
2018-04-15 03:53:51 +02:00
|
|
|
import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection;
|
2018-08-09 20:54:56 +02: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;
|
2017-11-22 22:58:33 +01:00
|
|
|
|
2018-08-09 20:54:56 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* Download Host Info Packet
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
|
|
|
private SubPlugin plugin;
|
2018-08-09 20:54:56 +02:00
|
|
|
private String host;
|
2016-12-15 22:04:39 +01:00
|
|
|
private String id;
|
|
|
|
|
2017-01-07 20:06:54 +01:00
|
|
|
/**
|
|
|
|
* New PacketDownloadHostInfo (In)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
|
|
|
*/
|
2016-12-15 22:04:39 +01:00
|
|
|
public PacketDownloadHostInfo(SubPlugin plugin) {
|
2018-08-09 20:54:56 +02:00
|
|
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
2016-12-15 22:04:39 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
2017-01-07 20:06:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* New PacketDownloadHostInfo (Out)
|
|
|
|
*
|
|
|
|
* @param plugin SubPlugin
|
2018-08-09 20:54:56 +02:00
|
|
|
* @param host Host (or null for all)
|
2017-01-07 20:06:54 +01:00
|
|
|
* @param id Receiver ID
|
|
|
|
*/
|
2018-08-09 20:54:56 +02:00
|
|
|
public PacketDownloadHostInfo(SubPlugin plugin, String host, String id) {
|
|
|
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
2016-12-15 22:04:39 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
this.host = host;
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2018-08-09 20:54:56 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2016-12-15 22:04:39 +01:00
|
|
|
@Override
|
2018-04-15 03:53:51 +02:00
|
|
|
public YAMLSection generate() {
|
|
|
|
YAMLSection data = new YAMLSection();
|
2018-08-24 04:32:49 +02:00
|
|
|
if (id != null) data.set("id", id);
|
2016-12-15 22:04:39 +01:00
|
|
|
|
2018-08-09 20:54:56 +02:00
|
|
|
YAMLSection hosts = new YAMLSection();
|
|
|
|
for (Host host : plugin.api.getHosts().values()) {
|
|
|
|
if (this.host == null || this.host.length() <= 0 || this.host.equalsIgnoreCase(host.getName())) {
|
|
|
|
hosts.set(host.getName(), new YAMLSection(new Gson().fromJson(host.toString(), Map.class)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.set("hosts", hosts);
|
2018-04-15 03:53:51 +02:00
|
|
|
return data;
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-15 03:53:51 +02:00
|
|
|
public void execute(Client client, YAMLSection data) {
|
2018-08-09 20:54:56 +02:00
|
|
|
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains("host"))?data.getRawString("host"):null, (data.contains("id"))?data.getRawString("id"):null));
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Version getVersion() {
|
2018-08-09 20:54:56 +02:00
|
|
|
return new Version("2.13b");
|
2016-12-15 22:04:39 +01:00
|
|
|
}
|
|
|
|
}
|