From 658946d4da4b6670d412e825232996befeec41d3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 8 Dec 2020 17:25:27 +0100 Subject: [PATCH] Extracting BungeeGUI Changes --- .../src/de/steamwar/comms/BungeeReceiver.java | 2 +- .../steamwar/comms/handlers/InventoryHandler.java | 13 +++++++++++-- .../src/de/steamwar/inventory/SWItem.java | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java index 103e72f..16ddf21 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java +++ b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java @@ -24,7 +24,7 @@ import com.google.common.io.ByteStreams; import de.steamwar.comms.handlers.BungeeHandler; import de.steamwar.comms.handlers.InventoryHandler; import de.steamwar.core.Core; -import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.*; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; 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 784839e..8e3a06f 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWItem.java @@ -138,7 +138,7 @@ public class SWItem { itemJson.has("color")?itemJson.get("color").getAsByte():0, itemJson.get("title").getAsString()); }else { - item = new SWItem(Material.valueOf(itemJson.get("material").getAsString()), itemJson.get("title").getAsString()); + item = new SWItem(SWItem.getMaterial(itemJson.get("material").getAsString()), itemJson.get("title").getAsString()); } }catch (IllegalArgumentException e) { item = new SWItem(Material.STONE, itemJson.get("title").getAsString());