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

77 lines
2.4 KiB
Java
Raw Normal View History

2016-12-24 05:55:17 +01:00
package net.ME1312.SubServers.Bungee.Network.Packet;
2019-04-18 16:02:09 +02:00
import net.ME1312.SubData.Server.SubDataClient;
2016-12-24 05:55:17 +01:00
import net.ME1312.SubServers.Bungee.Host.Host;
2019-04-18 16:02:09 +02:00
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubServers.Bungee.SubProxy;
2017-11-22 22:58:33 +01:00
import java.util.Arrays;
import java.util.List;
2019-04-18 16:02:09 +02:00
import java.util.UUID;
2017-01-07 20:06:54 +01:00
/**
* Download Host Info Packet
*/
2019-04-18 16:02:09 +02:00
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubProxy plugin;
private String[] hosts;
2019-04-18 16:02:09 +02:00
private UUID tracker;
2017-01-07 20:06:54 +01:00
/**
* New PacketDownloadHostInfo (In)
*
* @param plugin SubPlugin
*/
public PacketDownloadHostInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
}
2017-01-07 20:06:54 +01:00
/**
* New PacketDownloadHostInfo (Out)
*
* @param plugin SubPlugin
* @param hosts Hosts (or null for all)
2019-04-18 16:02:09 +02:00
* @param tracker Receiver ID
2017-01-07 20:06:54 +01:00
*/
public PacketDownloadHostInfo(SubProxy plugin, List<String> hosts, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
2019-04-18 16:02:09 +02:00
this.tracker = tracker;
if (hosts != null) {
this.hosts = new String[hosts.size()];
for (int i = 0; i < this.hosts.length; ++i) this.hosts[i] = hosts.get(i).toLowerCase();
Arrays.sort(this.hosts);
}
}
@Override
2019-04-18 16:02:09 +02:00
public ObjectMap<Integer> send(SubDataClient client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (tracker != null) data.set(0x0000, tracker);
2019-04-18 16:02:09 +02:00
ObjectMap<String> hosts = new ObjectMap<String>();
for (Host host : plugin.api.getHosts().values()) {
if (this.hosts == null || this.hosts.length <= 0 || Arrays.binarySearch(this.hosts, host.getName().toLowerCase()) >= 0) {
2019-04-18 16:02:09 +02:00
hosts.set(host.getName(), host.forSubData());
}
}
2019-04-18 16:02:09 +02:00
data.set(0x0001, hosts);
return data;
}
@Override
2019-04-18 16:02:09 +02:00
public void receive(SubDataClient client, ObjectMap<Integer> data) {
client.sendPacket(new PacketDownloadHostInfo(plugin, (data.contains(0x0001))?data.getRawStringList(0x0001):null, (data.contains(0x0000))?data.getUUID(0x0000):null));
}
@Override
2019-04-18 16:02:09 +02:00
public int version() {
return 0x0001;
}
}