From ace0488e715fa5e87ba7340cf470439e608a3ce3 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Wed, 18 Dec 2024 08:01:25 +0100 Subject: [PATCH] Create ConsumeItemEventEntry --- .../entries/event/ConsumeItemEventEntry.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/event/ConsumeItemEventEntry.kt diff --git a/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/event/ConsumeItemEventEntry.kt b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/event/ConsumeItemEventEntry.kt new file mode 100644 index 0000000000..eac1627db4 --- /dev/null +++ b/extensions/BasicExtension/src/main/kotlin/com/typewritermc/basic/entries/event/ConsumeItemEventEntry.kt @@ -0,0 +1,29 @@ +package com.typewritermc.basic.entries.event + +import com.typewritermc.core.books.pages.Colors +import com.typewritermc.core.entries.Query +import com.typewritermc.core.entries.Ref +import com.typewritermc.core.extension.annotations.Entry +import com.typewritermc.core.extension.annotations.EntryListener +import com.typewritermc.core.interaction.context +import com.typewritermc.engine.paper.entry.TriggerableEntry +import com.typewritermc.engine.paper.entry.entries.EventEntry +import com.typewritermc.engine.paper.entry.triggerAllFor +import com.typewritermc.engine.paper.utils.item.Item +import org.bukkit.event.player.PlayerItemConsumeEvent + +@Entry("consume_item_event", "triggers when the player consumes food", Colors.YELLOW, "game-icons:eating") +class ConsumeItemEventEntry( + override val id: String = "", + override val name: String = "", + override val triggers: List> = emptyList(), + val item: Item = Item.Empty, +) : EventEntry + +@EntryListener(ConsumeItemEventEntry::class) +fun onItemConsume(event: PlayerItemConsumeEvent, query: Query) { + val player = event.player + query.findWhere { entry -> + entry.item.isSameAs(player, event.item) + }.triggerAllFor(player, context()) +} \ No newline at end of file