/
PacketDownloadGroupInfo.java
58 lines (50 loc) · 1.74 KB
/
PacketDownloadGroupInfo.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
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.SubServers.Host.Library.Callback;
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
import net.ME1312.SubServers.Host.Library.Util;
import net.ME1312.SubServers.Host.Library.Version.Version;
import net.ME1312.SubServers.Host.Network.PacketIn;
import net.ME1312.SubServers.Host.Network.PacketOut;
import java.util.HashMap;
import java.util.UUID;
/**
* Download Group Info Packet
*/
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
private String group;
private String id;
/**
* New PacketDownloadGroupInfo (In)
*/
public PacketDownloadGroupInfo() {}
/**
* New PacketDownloadGroupInfo (Out)
*
* @param group Group name (or null for all)
* @param callback Callbacks
*/
@SafeVarargs
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
if (Util.isNull((Object) callback)) throw new NullPointerException();
this.group = group;
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
callbacks.put(id, callback);
}
@Override
public YAMLSection generate() {
YAMLSection json = new YAMLSection();
json.set("id", id);
json.set("group", group);
return json;
}
@Override
public void execute(YAMLSection data) {
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
callbacks.remove(data.getRawString("id"));
}
@Override
public Version getVersion() {
return new Version("2.13b");
}
}