diff --git a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java index 103e72f..2ebbb79 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java +++ b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java @@ -23,15 +23,18 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import de.steamwar.comms.handlers.BungeeHandler; import de.steamwar.comms.handlers.InventoryHandler; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.*; import de.steamwar.core.Core; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.plugin.messaging.PluginMessageListener; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class BungeeReceiver implements PluginMessageListener { @@ -59,6 +62,23 @@ public class BungeeReceiver implements PluginMessageListener { Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); player.closeInventory(); }); + BungeeReceiver.registerHandler((byte) PacketIdManager.CHANGE_ITEM_INV, byteArrayDataInput -> { + Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); + Schematic schem = Schematic.getSchemFromDB(byteArrayDataInput.readInt()); + List> materials = new LinkedList<>(); + for(Material material : Material.values()){ + SWItem item = new SWItem(material, "§7" + material); + if(item.getItemMeta() != null && material.isItem()) + materials.add(new SWListInv.SWListEntry<>(item, material)); + } + + SWListInv inv = new SWListInv<>(player, "Item ändern", materials, (clickType, material) -> { + schem.setItem(material.name()); + player.closeInventory(); + }); + inv.setCallback(-999, (ClickType click) -> player.closeInventory()); + inv.open(); + }); } @Override diff --git a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java index 2407d6a..5958ae0 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java +++ b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java @@ -28,4 +28,9 @@ public class PacketIdManager { public final static byte INVENTORY_PACKET = 0x10; public final static byte INVENTORY_CALLBACK_PACKET = 0x11; public final static byte INVENTORY_CLOSE_PACKET = 0x12; + //0x2(X) Schematic System + public static final byte LOAD_SCHEMATIC = 0x23; + public static final byte SAVE_SCHEMATIC = 0x24; + public static final byte CHECK_SCHEMATIC = 0x25; + public static final byte CHANGE_ITEM_INV = 0x26; } diff --git a/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java b/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java index 433aa86..a62398e 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java +++ b/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java @@ -23,11 +23,13 @@ import com.google.common.io.ByteArrayDataInput; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import de.steamwar.core.Core; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import de.steamwar.comms.packets.*; +import org.bukkit.event.inventory.InventoryType; import java.util.*; @@ -45,12 +47,19 @@ public class InventoryHandler implements BungeeHandler { for (int i = 0; i < length; i++) { JsonObject itemJson = array.get(i).getAsJsonObject(); SWItem item = SWItem.getItemFromJson(itemJson); - item.setCallback(click -> new InventoryCallbackPacket(itemJson, click, player).send(Bukkit.getPlayer(player))); + item.setCallback(click -> { + new InventoryCallbackPacket(itemJson, click, player).send(Bukkit.getPlayer(player)); + }); items.put(itemJson.get("position").getAsInt(), item); } SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), size, title, items); - inventory.addCloseCallback(click -> new InventoryCallbackPacket(player).send(Bukkit.getPlayer(player))); + inventory.addCloseCallback(click -> { + Bukkit.getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> { + if(Bukkit.getPlayer(player).getOpenInventory().getType() != InventoryType.CHEST) + new InventoryCallbackPacket(player).send(Bukkit.getPlayer(player)); + }, 1); + }); inventory.open(); } } diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java b/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java index f75b0b2..8d4636d 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java @@ -154,7 +154,11 @@ public class SWItem { item = new SWItem(Material.valueOf(itemJson.get("material").getAsString()), itemJson.get("title").getAsString()); } }catch (IllegalArgumentException e) { - item = new SWItem(Material.STONE, itemJson.get("title").getAsString()); + try { + item = new SWItem(Material.valueOf(Material.LEGACY_PREFIX + itemJson.get("material").getAsString()), itemJson.get("title").getAsString()); + }catch (IllegalArgumentException ex) { + item = new SWItem(Material.STONE, itemJson.get("title").getAsString()); + } } if(itemJson.has("skullOwner")) { item = SWItem.getPlayerSkull(itemJson.get("skullOwner").getAsString());