SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Add Inventory Logging' (#243) from inv_logging into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #243
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2023-07-25 21:43:17 +02:00
Commit bdf1ae2bf4

Datei anzeigen

@ -28,6 +28,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,6 +43,7 @@ public class SWInventory implements Listener {
final Player player; final Player player;
final Map<Integer, Consumer<InventoryClickEvent>> callbacks = new HashMap<>(); final Map<Integer, Consumer<InventoryClickEvent>> callbacks = new HashMap<>();
final Inventory inventory; final Inventory inventory;
String title;
boolean open = false; boolean open = false;
public SWInventory(Player p, int size, String t) { public SWInventory(Player p, int size, String t) {
@ -135,7 +137,9 @@ public class SWInventory implements Listener {
} }
public void open() { 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) { if(!open) {
Bukkit.getPluginManager().registerEvents(this, Core.getInstance()); Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
open = true; open = true;
@ -149,6 +153,7 @@ public class SWInventory implements Listener {
if (callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) { if (callbacks.containsKey(e.getRawSlot()) && callbacks.get(e.getRawSlot()) != null) {
e.setCancelled(true); 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); callbacks.get(e.getRawSlot()).accept(e);
} }
} }
@ -160,6 +165,7 @@ public class SWInventory implements Listener {
InventoryClickEvent.getHandlerList().unregister(this); InventoryClickEvent.getHandlerList().unregister(this);
InventoryCloseEvent.getHandlerList().unregister(this); InventoryCloseEvent.getHandlerList().unregister(this);
Core.getInstance().getLogger().info("[SWINV] " + player.getName() + " closed " + title);
if(callbacks.containsKey(-1)) if(callbacks.containsKey(-1))
callbacks.get(-1).accept(null); callbacks.get(-1).accept(null);
open = false; open = false;