mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 00:49:31 +00:00
* Add configurable option in config for PlayerInventoryOverflowEvent and able to define the class name of listener * Update checking method for overflow items handling logic, only fire event when actual listener is listening to it.
59 lines
3.0 KiB
Diff
59 lines
3.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Wed, 19 Feb 2025 00:36:20 -0500
|
|
Subject: [PATCH] PlayerInventoryOverflowEvent
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
index 8b4f8a475faafe3b8a479160888145c4aa603a27..2f8377ceefa29fbf0827f673c7bf6e1d3215e477 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
@@ -340,9 +340,47 @@ public class CraftInventory implements Inventory {
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+ // Leaf start - PlayerInventoryOverflowEvent
|
|
+ if (isListeningInventoryOverflowEvent() && !leftover.isEmpty() && this.inventory instanceof net.minecraft.world.entity.player.Inventory && this.inventory.getOwner() instanceof org.bukkit.entity.Player player) {
|
|
+ new org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent(player, leftover).callEvent();
|
|
+
|
|
+ return new HashMap<>();
|
|
+ }
|
|
+ // Leaf end - PlayerInventoryOverflowEvent
|
|
+
|
|
return leftover;
|
|
}
|
|
|
|
+ // Leaf start - PlayerInventoryOverflowEvent
|
|
+ private static boolean isListeningInventoryOverflowEvent() {
|
|
+ if (org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.isListeningInvOverflowCached == -1) {
|
|
+ org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.isListeningInvOverflowCached = 0;
|
|
+
|
|
+ if (!org.dreeam.leaf.config.modules.gameplay.ConfigurableInventoryOverflowEvent.enabled) {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ org.bukkit.plugin.RegisteredListener[] listeners = org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.getHandlerList().getRegisteredListeners();
|
|
+ if (listeners.length == 1) {
|
|
+ if (listeners[0].getListener().getClass().getName().equals(org.dreeam.leaf.config.modules.gameplay.ConfigurableInventoryOverflowEvent.listenerClass)) {
|
|
+ org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.isListeningInvOverflowCached = 1;
|
|
+ return true;
|
|
+ }
|
|
+ } else if (listeners.length > 1) {
|
|
+ for (org.bukkit.plugin.RegisteredListener registeredListener : listeners) {
|
|
+ if (registeredListener.getListener().getClass().getName().equals(org.dreeam.leaf.config.modules.gameplay.ConfigurableInventoryOverflowEvent.listenerClass)) {
|
|
+ org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.isListeningInvOverflowCached = 1;
|
|
+ return true;
|
|
+ };
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return org.dreeam.leaf.event.player.PlayerInventoryOverflowEvent.isListeningInvOverflowCached == 1;
|
|
+ }
|
|
+ // Leaf end - PlayerInventoryOverflowEvent
|
|
+
|
|
@Override
|
|
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) {
|
|
// Paper start
|