mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-22 12:44:51 +02:00
The Download group of packets was in desperate need for a restructuring. Now, instead of using `DownloadServerList` to list everything, different object types now are downloaded through their own seperate packets. (Improving network efficiency)
59 lines
1.7 KiB
Java
59 lines
1.7 KiB
Java
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 Proxy Info Packet
|
|
*/
|
|
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
|
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
|
private String proxy;
|
|
private String id;
|
|
|
|
/**
|
|
* New PacketDownloadProxyInfo (In)
|
|
*/
|
|
public PacketDownloadProxyInfo() {}
|
|
|
|
/**
|
|
* New PacketDownloadProxyInfo (Out)
|
|
*
|
|
* @param proxy Proxy name (or null for all)
|
|
* @param callback Callbacks
|
|
*/
|
|
@SafeVarargs
|
|
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
|
this.proxy = proxy;
|
|
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("proxy", proxy);
|
|
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");
|
|
}
|
|
}
|