Packet System + Bungee GUI #59
@ -36,18 +36,14 @@ import java.util.UUID;
|
||||
|
||||
public class BungeeReceiver implements PluginMessageListener {
|
||||
|
||||
private static Map<Integer, BungeeHandler> handlerMap = new HashMap<>();
|
||||
private static Map<Byte, BungeeHandler> handlerMap = new HashMap<>();
|
||||
|
||||
public static void registerHandler(int code, BungeeHandler handler) {
|
||||
public static void registerHandler(Byte code, BungeeHandler handler) {
|
||||
handlerMap.put(code, handler);
|
||||
}
|
||||
|
||||
public static void registerHandler(String name, BungeeHandler handler) {
|
||||
handlerMap.put(name.hashCode(), handler);
|
||||
}
|
||||
|
||||
static {
|
||||
registerHandler("PingHandler", byteArrayDataInput -> {
|
||||
registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> {
|
||||
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
|
||||
if(Bukkit.getPlayer(uuid).isOnline()) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
@ -55,8 +51,8 @@ public class BungeeReceiver implements PluginMessageListener {
|
||||
}
|
||||
|
||||
});
|
||||
registerHandler("InventoryHandler", new InventoryHandler());
|
||||
registerHandler("CloseInventory", byteArrayDataInput -> {
|
||||
registerHandler(PacketIdManager.INVENTORY_PACKET, new InventoryHandler());
|
||||
registerHandler(PacketIdManager.INVENTORY_CLOSE_PACKET, byteArrayDataInput -> {
|
||||
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
|
||||
player.closeInventory();
|
||||
});
|
||||
@ -65,6 +61,7 @@ public class BungeeReceiver implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
handlerMap.get(in.readInt()).handle(in);
|
||||
Byte handler = in.readByte();
|
||||
handlerMap.get(handler).handle(in);
|
||||
}
|
||||
}
|
||||
|
11
SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java
Normale Datei
11
SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java
Normale Datei
@ -0,0 +1,11 @@
|
||||
package de.steamwar.comms;
|
||||
|
||||
|
||||
public class PacketIdManager {
|
||||
|
||||
//0x0(X) Standalone Packets
|
||||
public final static byte PING_PACKET = 0x01;
|
||||
//0x1(X) Bungee Inventory
|
||||
public final static byte INVENTORY_PACKET = 0x10;
|
||||
public final static byte INVENTORY_CALLBACK_PACKET = 0x11;
|
||||
public final static byte INVENTORY_CLOSE_PACKET = 0x12;
|
||||
}
|
@ -20,25 +20,26 @@
|
||||
package de.steamwar.comms.packets;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import de.steamwar.comms.PacketIdManager;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class InventoryCallbackPacket extends SpigotPacket {
|
||||
|
||||
int position;
|
||||
int position = -1;
|
||||
ClickType clickType;
|
||||
CallbackType callbackType;
|
||||
int owner;
|
||||
|
||||
@Override
|
||||
public int getName() {
|
||||
return "InventoryCallback".hashCode();
|
||||
return PacketIdManager.INVENTORY_CALLBACK_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
|
||||
byteArrayDataOutput.writeInt(owner);
|
||||
byteArrayDataOutput.writeUTF(callbackType.name());
|
||||
if(position != 0){
|
||||
if(position != -1){
|
||||
byteArrayDataOutput.writeInt(position);
|
||||
byteArrayDataOutput.writeUTF(clickType.name());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public abstract class SpigotPacket {
|
||||
|
||||
public void send(Player player) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeInt(getName());
|
||||
out.writeByte(getName());
|
||||
writeVars(out);
|
||||
player.sendPluginMessage(Core.getInstance(), "sw:bridge", out.toByteArray());
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Lizenzheader fehlt.