From 4565f7da7e9fb278de5dc0b6e9e65a1909a1830f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 16 Sep 2020 21:22:13 +0200 Subject: [PATCH] Add Stuff for Bungee GUI --- .../handlers/InventoryCallbackHandler.java | 16 ++++ .../coms/packets/InventoryPacket.java | 55 +++++++++++++ .../coms/packets/inventory/SWInventory.java | 4 + .../coms/packets/inventory/SWItem.java | 81 +++++++++++++++++++ .../bungeecore/coms/sender/Packet.java | 1 + .../bungeecore/coms/sender/PacketSender.java | 2 - 6 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/bungeecore/coms/handlers/InventoryCallbackHandler.java create mode 100644 src/de/steamwar/bungeecore/coms/packets/InventoryPacket.java create mode 100644 src/de/steamwar/bungeecore/coms/packets/inventory/SWInventory.java create mode 100644 src/de/steamwar/bungeecore/coms/packets/inventory/SWItem.java diff --git a/src/de/steamwar/bungeecore/coms/handlers/InventoryCallbackHandler.java b/src/de/steamwar/bungeecore/coms/handlers/InventoryCallbackHandler.java new file mode 100644 index 0000000..ca9d072 --- /dev/null +++ b/src/de/steamwar/bungeecore/coms/handlers/InventoryCallbackHandler.java @@ -0,0 +1,16 @@ +package de.steamwar.bungeecore.coms.handlers; + +import com.google.common.io.ByteArrayDataInput; +import de.steamwar.bungeecore.coms.receiver.Handler; + +public class InventoryCallbackHandler extends Handler { + @Override + protected String getName() { + return "InventoryCallback"; + } + + @Override + public void handle(ByteArrayDataInput byteArrayDataInput) { + + } +} diff --git a/src/de/steamwar/bungeecore/coms/packets/InventoryPacket.java b/src/de/steamwar/bungeecore/coms/packets/InventoryPacket.java new file mode 100644 index 0000000..64466a5 --- /dev/null +++ b/src/de/steamwar/bungeecore/coms/packets/InventoryPacket.java @@ -0,0 +1,55 @@ +package de.steamwar.bungeecore.coms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.bungeecore.coms.packets.inventory.SWItem; +import de.steamwar.bungeecore.coms.sender.Packet; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +public class InventoryPacket extends Packet { + + String title; + String name; + String player; + int size; + SWItem[] items; + + public InventoryPacket(int size, String title, String name, ProxiedPlayer player) { + items = new SWItem[size]; + this.title = title; + this.size = size; + this.name = name; + this.player = player.getUniqueId().toString(); + } + + @Override + public String getName() { + return "Inventory"; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + byteArrayDataOutput.writeUTF(name); + byteArrayDataOutput.writeUTF(player); + byteArrayDataOutput.writeUTF(title); + byteArrayDataOutput.writeInt(size); + byteArrayDataOutput.writeInt(items.length); + for (SWItem item: + items) { + if(item == null) + byteArrayDataOutput.writeUTF(item.writeToString()); + } + } + + public void addItem(SWItem item) { + for (int i = 0; i < items.length; i++) { + if (items[i] != null) { + items[i] = item; + return; + } + } + } + + public void setItem(int index, SWItem item) { + items[index] = item; + } +} diff --git a/src/de/steamwar/bungeecore/coms/packets/inventory/SWInventory.java b/src/de/steamwar/bungeecore/coms/packets/inventory/SWInventory.java new file mode 100644 index 0000000..c155bcf --- /dev/null +++ b/src/de/steamwar/bungeecore/coms/packets/inventory/SWInventory.java @@ -0,0 +1,4 @@ +package de.steamwar.bungeecore.coms.packets.inventory; + +public class SWInventory { +} diff --git a/src/de/steamwar/bungeecore/coms/packets/inventory/SWItem.java b/src/de/steamwar/bungeecore/coms/packets/inventory/SWItem.java new file mode 100644 index 0000000..2ead66a --- /dev/null +++ b/src/de/steamwar/bungeecore/coms/packets/inventory/SWItem.java @@ -0,0 +1,81 @@ +package de.steamwar.bungeecore.coms.packets.inventory; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import java.util.ArrayList; +import java.util.List; + +public class SWItem { + + String material, title, skullOwner; + boolean enchanted, hideAttributes; + int position; + List lore; + + public SWItem(String material, int position, String title) { + this.material = material; + lore = new ArrayList<>(); + this.position = position; + this.title = title; + } + + public String getMaterial() { + return material; + } + + public void setMaterial(String material) { + this.material = material; + } + + public String getSkullOwner() { + return skullOwner; + } + + public void setSkullOwner(String skullOwner) { + this.skullOwner = skullOwner; + } + + public boolean isEnchanted() { + return enchanted; + } + + public void setEnchanted(boolean enchanted) { + this.enchanted = enchanted; + } + + public boolean isHideAttributes() { + return hideAttributes; + } + + public void setHideAttributes(boolean hideAttributes) { + this.hideAttributes = hideAttributes; + } + + public void addLore(String lore) { + this.lore.add(lore); + } + + public String writeToString() { + JsonObject object = new JsonObject(); + object.addProperty("material", material); + object.addProperty("position", position); + object.addProperty("title", title); + if(skullOwner != null) + object.addProperty("skullOwner", skullOwner); + if(enchanted) + object.addProperty("enchanted", true); + if(hideAttributes) + object.addProperty("hideAttributes", true); + if(!lore.isEmpty()) { + JsonArray array = new JsonArray(); + for (String lores: + lore) { + array.add(lores); + } + object.add("lore", array); + } + + return object.getAsString(); + } +} diff --git a/src/de/steamwar/bungeecore/coms/sender/Packet.java b/src/de/steamwar/bungeecore/coms/sender/Packet.java index a7d92b6..8d400d3 100644 --- a/src/de/steamwar/bungeecore/coms/sender/Packet.java +++ b/src/de/steamwar/bungeecore/coms/sender/Packet.java @@ -16,5 +16,6 @@ public abstract class Packet { public abstract String getName(); + //TODO Write Variables Automatic public abstract void writeVars(ByteArrayDataOutput byteArrayDataOutput); } diff --git a/src/de/steamwar/bungeecore/coms/sender/PacketSender.java b/src/de/steamwar/bungeecore/coms/sender/PacketSender.java index 5bd6f8d..2a7e8da 100644 --- a/src/de/steamwar/bungeecore/coms/sender/PacketSender.java +++ b/src/de/steamwar/bungeecore/coms/sender/PacketSender.java @@ -6,8 +6,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; public class PacketSender {