diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/menu/events/CaptiveItemChangeEvent.java b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/events/CaptiveItemChangeEvent.java new file mode 100644 index 00000000..9887f5d6 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/events/CaptiveItemChangeEvent.java @@ -0,0 +1,22 @@ +package com.willfp.eco.core.gui.menu.events; + +import com.willfp.eco.core.gui.menu.MenuEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a captive item change. + * + * @param row The row. + * @param column The column. + * @param before The previous item in the slot. + * @param after The new item in the slot. + */ +public record CaptiveItemChangeEvent( + int row, + int column, + @Nullable ItemStack before, + @Nullable ItemStack after +) implements MenuEvent { + +} diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt index 08c85801..95451923 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt @@ -1,5 +1,6 @@ package com.willfp.eco.internal.gui.menu +import com.willfp.eco.core.gui.menu.events.CaptiveItemChangeEvent import com.willfp.eco.core.items.isEmpty import com.willfp.eco.core.recipe.parts.EmptyTestableItem import com.willfp.eco.util.MenuUtils @@ -63,6 +64,20 @@ class RenderedInventory( captiveItems.clear() captiveItems.putAll(newCaptive) + // Call captive item change event + for (position in previousCaptive.keys union newCaptive.keys) { + if (previousCaptive[position] != newCaptive[position]) { + menu.callEvent( + player, CaptiveItemChangeEvent( + position.row, + position.column, + previousCaptive[position], + newCaptive[position] + ) + ) + } + } + menu.runOnRender(player) // Run second render if captive items changed