mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-22 12:44:51 +02:00
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.
67 lines
2.0 KiB
Java
67 lines
2.0 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;
|
|
|
|
/**
|
|
* Command Server Packet
|
|
*/
|
|
public class PacketCommandServer implements PacketIn, PacketOut {
|
|
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
|
private UUID player;
|
|
private String server;
|
|
private String command;
|
|
private String id;
|
|
|
|
/**
|
|
* New PacketCommandServer (In)
|
|
*/
|
|
public PacketCommandServer() {}
|
|
|
|
/**
|
|
* New PacketCommandServer (Out)
|
|
*
|
|
* @param player Player Sending
|
|
* @param server Server to send to
|
|
* @param command Command to send
|
|
* @param callback Callbacks
|
|
*/
|
|
@SafeVarargs
|
|
public PacketCommandServer(UUID player, String server, String command, Callback<YAMLSection>... callback) {
|
|
if (Util.isNull(server, command, callback)) throw new NullPointerException();
|
|
this.player = player;
|
|
this.server = server;
|
|
this.command = command;
|
|
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
|
callbacks.put(id, callback);
|
|
}
|
|
|
|
@Override
|
|
public YAMLSection generate() {
|
|
YAMLSection data = new YAMLSection();
|
|
data.set("id", id);
|
|
if (player != null) data.set("player", player.toString());
|
|
data.set("server", server);
|
|
data.set("command", command);
|
|
return data;
|
|
}
|
|
|
|
@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");
|
|
}
|
|
}
|