Search in sources :

Example 1 with BungeeForwardEvent

use of org.anhcraft.spaciouslib.events.BungeeForwardEvent in project SpaciousLib by anhcraft.

the class BungeeManager method onPluginMessageReceived.

@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(CHANNEL)) {
        return;
    }
    ByteArrayDataInput i = ByteStreams.newDataInput(message);
    String sc = i.readUTF();
    boolean b = false;
    for (BungeeResponse br : queue) {
        if (sc.equals("IP") && br instanceof BungeePlayerIPResponse) {
            ((BungeePlayerIPResponse) br).result(i.readUTF(), i.readInt());
            b = true;
        }
        if (sc.equals("PlayerCount") && br instanceof BungeePlayerAmountResponse) {
            ((BungeePlayerAmountResponse) br).result(i.readUTF(), i.readInt());
            b = true;
        }
        if (sc.equals("PlayerList") && br instanceof BungeePlayerListResponse) {
            ((BungeePlayerListResponse) br).result(i.readUTF(), new ArrayList<>(Arrays.asList(i.readUTF().split(", "))));
            b = true;
        }
        if (sc.equals("GetServers") && br instanceof BungeeServerListResponse) {
            ((BungeeServerListResponse) br).result(new ArrayList<>(Arrays.asList(i.readUTF().split(", "))));
            b = true;
        }
        if (sc.equals("GetServer") && br instanceof BungeeServerNameResponse) {
            ((BungeeServerNameResponse) br).result(i.readUTF());
            b = true;
        }
        if (sc.equals("UUID") && br instanceof BungeePlayerUUIDResponse) {
            ((BungeePlayerUUIDResponse) br).result(UUID.fromString(i.readUTF()));
            b = true;
        }
        if (sc.equals("UUIDOther") && br instanceof BungeeOtherPlayerUUIDResponse) {
            ((BungeeOtherPlayerUUIDResponse) br).result(i.readUTF(), UUID.fromString(i.readUTF()));
            b = true;
        }
        if (sc.equals("ServerIP") && br instanceof BungeeServerIPResponse) {
            ((BungeeServerIPResponse) br).result(i.readUTF(), i.readUTF(), i.readUnsignedShort());
            b = true;
        }
        if (b) {
            break;
        }
    }
    if (b) {
        queue.remove(0);
    } else {
        byte[] bytedata = new byte[i.readShort()];
        i.readFully(bytedata);
        DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytedata));
        BungeeForwardEvent ev = new BungeeForwardEvent(sc, data);
        Bukkit.getServer().getPluginManager().callEvent(ev);
    }
}
Also used : BungeeForwardEvent(org.anhcraft.spaciouslib.events.BungeeForwardEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 BungeeForwardEvent (org.anhcraft.spaciouslib.events.BungeeForwardEvent)1