-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create MythicMobKillPlayerEventEntry
- Loading branch information
Showing
1 changed file
with
39 additions
and
30 deletions.
There are no files selected for viewing
69 changes: 39 additions & 30 deletions
69
...rc/main/kotlin/com/typewritermc/mythicmobs/entries/event/MythicMobKillPlayerEventEntry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |