From a2a1884677587939fc2fe08124ef8444d3bf8329 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 25 Jul 2023 21:35:10 +0200 Subject: [PATCH] Add Inventory Logging --- .../src/de/steamwar/inventory/SWInventory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java index 9c52ee3..345b728 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWInventory.java @@ -28,6 +28,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; @@ -42,6 +43,7 @@ public class SWInventory implements Listener { final Player player; final Map> callbacks = new HashMap<>(); final Inventory inventory; + String title; boolean open = false; public SWInventory(Player p, int size, String t) { @@ -135,7 +137,9 @@ public class SWInventory implements Listener { } public void open() { - player.openInventory(inventory); + InventoryView view = player.openInventory(inventory); + title = view.getTitle(); + Core.getInstance().getLogger().info("[SWINV] Opened " + title + " for " + player.getName()); if(!open) { Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); open = true; @@ -149,6 +153,7 @@ public class SWInventory implements Listener { if (callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) { e.setCancelled(true); + Core.getInstance().getLogger().info("[SWINV] " + e.getWhoClicked().getName() + " " + e.getClick().name() + " clicked " + e.getRawSlot() + " on " + e.getCurrentItem().getItemMeta().getDisplayName() + " in " + e.getView().getTitle()); callbacks.get(e.getRawSlot()).accept(e); } } @@ -160,6 +165,7 @@ public class SWInventory implements Listener { InventoryClickEvent.getHandlerList().unregister(this); InventoryCloseEvent.getHandlerList().unregister(this); + Core.getInstance().getLogger().info("[SWINV] " + player.getName() + " closed " + title); if(callbacks.containsKey(-1)) callbacks.get(-1).accept(null); open = false;