mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-22 12:44:51 +02:00
75b9b688cc
This commit removes the org.JSON library where alternatives are already provided (Bungee & Bukkit provide Gson). This change was made to improve compatability with BungeeCord plugins and reduce file sizes. This means big changes to the SubData API, which heavily relied on org.JSON. Now we submit our data through YAMLSection to be converted and sent over the network.
58 lines
1.7 KiB
Java
58 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 Network List Packet
|
|
*/
|
|
public class PacketDownloadNetworkList implements PacketIn, PacketOut {
|
|
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
|
private String id;
|
|
|
|
/**
|
|
* New PacketDownloadNetworkList (In)
|
|
*/
|
|
public PacketDownloadNetworkList() {}
|
|
|
|
/**
|
|
* New PacketDownloadNetworkList (Out)
|
|
*
|
|
* @param callback Callbacks
|
|
*/
|
|
@SafeVarargs
|
|
public PacketDownloadNetworkList(Callback<YAMLSection>... callback) {
|
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
|
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
|
callbacks.put(id, callback);
|
|
}
|
|
@Override
|
|
public YAMLSection generate() {
|
|
if (id != null) {
|
|
YAMLSection data = new YAMLSection();
|
|
data.set("id", id);
|
|
return data;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@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.11.0a");
|
|
}
|
|
}
|