SteamWar/SpigotCore
Archiviert
13
0
Dieser Commit ist enthalten in:
Chaoscaot 2020-09-21 23:22:50 +02:00
Ursprung fc28403750
Commit a8f88935df
4 geänderte Dateien mit 23 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -36,18 +36,14 @@ import java.util.UUID;
public class BungeeReceiver implements PluginMessageListener { 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); handlerMap.put(code, handler);
} }
public static void registerHandler(String name, BungeeHandler handler) {
handlerMap.put(name.hashCode(), handler);
}
static { static {
registerHandler("PingHandler", byteArrayDataInput -> { registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> {
UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID(); UUID uuid = SteamwarUser.get(byteArrayDataInput.readInt()).getUUID();
if(Bukkit.getPlayer(uuid).isOnline()) { if(Bukkit.getPlayer(uuid).isOnline()) {
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
@ -55,8 +51,8 @@ public class BungeeReceiver implements PluginMessageListener {
} }
}); });
registerHandler("InventoryHandler", new InventoryHandler()); registerHandler(PacketIdManager.INVENTORY_PACKET, new InventoryHandler());
registerHandler("CloseInventory", byteArrayDataInput -> { registerHandler(PacketIdManager.INVENTORY_CLOSE_PACKET, byteArrayDataInput -> {
Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID());
player.closeInventory(); player.closeInventory();
}); });
@ -65,6 +61,7 @@ public class BungeeReceiver implements PluginMessageListener {
@Override @Override
public void onPluginMessageReceived(String s, Player player, byte[] bytes) { public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
ByteArrayDataInput in = ByteStreams.newDataInput(bytes); ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
handlerMap.get(in.readInt()).handle(in); Byte handler = in.readByte();
handlerMap.get(handler).handle(in);
} }
} }

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -20,25 +20,26 @@
package de.steamwar.comms.packets; package de.steamwar.comms.packets;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import de.steamwar.comms.PacketIdManager;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
public class InventoryCallbackPacket extends SpigotPacket { public class InventoryCallbackPacket extends SpigotPacket {
int position; int position = -1;
ClickType clickType; ClickType clickType;
CallbackType callbackType; CallbackType callbackType;
int owner; int owner;
@Override @Override
public int getName() { public int getName() {
return "InventoryCallback".hashCode(); return PacketIdManager.INVENTORY_CALLBACK_PACKET;
} }
@Override @Override
public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { public void writeVars(ByteArrayDataOutput byteArrayDataOutput) {
byteArrayDataOutput.writeInt(owner); byteArrayDataOutput.writeInt(owner);
byteArrayDataOutput.writeUTF(callbackType.name()); byteArrayDataOutput.writeUTF(callbackType.name());
if(position != 0){ if(position != -1){
byteArrayDataOutput.writeInt(position); byteArrayDataOutput.writeInt(position);
byteArrayDataOutput.writeUTF(clickType.name()); byteArrayDataOutput.writeUTF(clickType.name());
} }

Datei anzeigen

@ -28,7 +28,7 @@ public abstract class SpigotPacket {
public void send(Player player) { public void send(Player player) {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(getName()); out.writeByte(getName());
writeVars(out); writeVars(out);
player.sendPluginMessage(Core.getInstance(), "sw:bridge", out.toByteArray()); player.sendPluginMessage(Core.getInstance(), "sw:bridge", out.toByteArray());
} }