Added CaptiveItemChangeEvent
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user