Skip to content

Commit

Permalink
Create MythicMobKillPlayerEventEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Sep 11, 2024
1 parent a2222f8 commit d131595
Showing 1 changed file with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
package com.typewritermc.mythicmobs.entries.event

/** TODO:
* Since minecraft 1.20.5 changed how the player death event source is handled,
* we cannot support it for 1.20.4 and 1.20.5 at the same time.
* So we can use this again once we drop support for 1.20.4
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.extension.annotations.Help
import com.typewritermc.core.extension.annotations.Placeholder
import com.typewritermc.core.extension.annotations.Regex
import com.typewritermc.engine.paper.entry.TriggerableEntry
import com.typewritermc.engine.paper.entry.entries.EventEntry
import com.typewritermc.engine.paper.entry.triggerAllFor
import io.lumine.mythic.bukkit.MythicBukkit
import org.bukkit.event.entity.PlayerDeathEvent
import java.util.*


@Entry("mythicmobs_kill_player_event", "MythicMob Kill Player Event", Colors.YELLOW, "fa6-solid:skull")
/**
* The `MythicMob Kill Player Event` event is triggered when MythicMob kills a player.
*
* ## How could this be used?
* When the player is killed by a certain monster, there is a probability that the monster will drag them back to their lair.
*/
class MythicMobKillPlayerEventEntry(
override val id: String = "",
override val name: String = "",
override val triggers: List<Ref<TriggerableEntry>> = emptyList(),
@Help("The type of the MythicMob that killed the player")
@Placeholder
@Regex
val mythicMobType: Optional<String> = Optional.empty(),
) : EventEntry

@EntryListener(MythicMobKillPlayerEventEntry::class)
fun onMythicMobKillPlayer(event: PlayerDeathEvent, query: Query<MythicMobKillPlayerEventEntry>) {
val causingEntity = event.damageSource.causingEntity ?: return
val mythicMob = MythicBukkit.inst().mobManager.getMythicMobInstance(causingEntity) ?: return

//@Entry("mythicmobs_kill_player_event", "MythicMob Kill Player Event", Colors.YELLOW, "fa6-solid:skull")
///**
// * The `MythicMob Kill Player Event` event is triggered when MythicMob kills a player.
// *
// * ## How could this be used?
// * When the player is killed by a certain monster, there is a probability that the monster will drag them back to their lair.
// */
//class MythicMobKillPlayerEventEntry(
// override val id: String = "",
// override val name: String = "",
// override val triggers: List<Ref<TriggerableEntry>> = emptyList(),
// @Help("The type of the MythicMob that killed the player")
// @Placeholder
// @Regex
// val mythicMobType: Optional<String> = Optional.empty(),
//) : EventEntry
//
//@EntryListener(MythicMobKillPlayerEventEntry::class)
//fun onMythicMobKillPlayer(event: PlayerDeathEvent, query: Query<MythicMobKillPlayerEventEntry>) {
// val causingEntity = event.damageSource.causingEntity ?: return
// val mythicMob = MythicBukkit.inst().mobManager.getMythicMobInstance(causingEntity) ?: return
//
// query findWhere { entry ->
// entry.mythicMobType.map { it.toRegex().matches(mythicMob.mobType) }.orElse(true)
// } triggerAllFor event.player
//}
query findWhere { entry ->
entry.mythicMobType.map { it.toRegex().matches(mythicMob.mobType) }.orElse(true)
} triggerAllFor event.player
}

0 comments on commit d131595

Please sign in to comment.