59 lines
1.7 KiB
Java
59 lines
1.7 KiB
Java
package net.ME1312.SubServers.Sync.Network.Packet;
|
|
|
|
import net.ME1312.SubServers.Sync.Library.Callback;
|
|
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
|
import net.ME1312.SubServers.Sync.Library.Util;
|
|
import net.ME1312.SubServers.Sync.Library.Version.Version;
|
|
import net.ME1312.SubServers.Sync.Network.PacketIn;
|
|
import net.ME1312.SubServers.Sync.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");
|
|
}
|
|
}
|