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.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<Integer, Consumer<InventoryClickEvent>> 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;