Skip to content

Commit

Permalink
Create ConsumeItemEventEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Dec 18, 2024
1 parent 8598aa2 commit ace0488
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Ref<TriggerableEntry>> = emptyList(),
val item: Item = Item.Empty,
) : EventEntry

@EntryListener(ConsumeItemEventEntry::class)
fun onItemConsume(event: PlayerItemConsumeEvent, query: Query<ConsumeItemEventEntry>) {
val player = event.player
query.findWhere { entry ->
entry.item.isSameAs(player, event.item)
}.triggerAllFor(player, context())
}

0 comments on commit ace0488

Please sign in to comment.