/
PacketDownloadHostInfo.java
76 lines (66 loc) · 2.44 KB
/
PacketDownloadHostInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package net.ME1312.SubServers.Bungee.Network.Packet;
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.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.SubProxy;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* Download Host Info Packet
*/
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubProxy plugin;
private String[] hosts;
private UUID tracker;
/**
* New PacketDownloadHostInfo (In)
*
* @param plugin SubPlugin
*/
public PacketDownloadHostInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
}
/**
* New PacketDownloadHostInfo (Out)
*
* @param plugin SubPlugin
* @param hosts Hosts (or null for all)
* @param tracker Receiver ID
*/
public PacketDownloadHostInfo(SubProxy plugin, List<String> hosts, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
this.plugin = plugin;
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
public ObjectMap<Integer> send(SubDataClient client) {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (tracker != null) data.set(0x0000, tracker);
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) {
hosts.set(host.getName(), host.forSubData());
}
}
data.set(0x0001, hosts);
return data;
}
@Override
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
public int version() {
return 0x0001;
}
}