SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/Network/Packet/PacketDownloadPlayerList.java
ME1312 75b9b688cc Rewrite SubData API for JSON dependancy changes
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.
2018-04-14 21:53:51 -04:00

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 Player List Packet
*/
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
private String id;
/**
* New PacketDownloadPlayerList (In)
*/
public PacketDownloadPlayerList() {}
/**
* New PacketDownloadPlayerList (Out)
*
* @param callback Callbacks
*/
@SafeVarargs
public PacketDownloadPlayerList(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");
}
}