From 89c8bf8103b9429fbc7a1ea63612dac565872d43 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:25:12 +0200 Subject: Backend: PlayerDeathEvent (#1544) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/data/MiningAPI.kt | 16 ++++++----- .../hannibal2/skyhanni/data/PlayerDeathManager.kt | 31 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/PlayerDeathManager.kt (limited to 'src/main/java/at/hannibal2/skyhanni/data') diff --git a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt index 47d38ef74..940b4ea35 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent import at.hannibal2.skyhanni.events.ServerBlockChangeEvent import at.hannibal2.skyhanni.events.mining.OreMinedEvent +import at.hannibal2.skyhanni.events.player.PlayerDeathEvent import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.features.mining.OreBlock import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -20,7 +21,6 @@ import at.hannibal2.skyhanni.utils.LorenzUtils.inAnyIsland import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst -import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.TimeUtils.format @@ -37,7 +37,7 @@ object MiningAPI { private val group = RepoPattern.group("data.miningapi") private val glaciteAreaPattern by group.pattern("area.glacite", "Glacite Tunnels|Glacite Lake") private val dwarvenBaseCampPattern by group.pattern("area.basecamp", "Dwarven Base Camp") - private val coldReset by group.pattern( + val coldReset by group.pattern( "cold.reset", "§6The warmth of the campfire reduced your §r§b❄ Cold §r§6to §r§a0§r§6!|§c ☠ §r§7You froze to death§r§7.", ) @@ -129,11 +129,13 @@ object MiningAPI { updateCold(0) lastColdReset = SimpleTimeMark.now() } - coldResetDeath.matchMatcher(event.message) { - if (group("name") == LorenzUtils.getPlayerName()) { - updateCold(0) - lastColdReset = SimpleTimeMark.now() - } + } + + @SubscribeEvent + fun onPlayerDeath(event: PlayerDeathEvent) { + if (event.name == LorenzUtils.getPlayerName()) { + updateCold(0) + lastColdReset = SimpleTimeMark.now() } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/PlayerDeathManager.kt b/src/main/java/at/hannibal2/skyhanni/data/PlayerDeathManager.kt new file mode 100644 index 000000000..75616520f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/PlayerDeathManager.kt @@ -0,0 +1,31 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.player.PlayerDeathEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object PlayerDeathManager { + + /** + * REGEX-TEST: §c ☠ §r§7§r§bZeroHazel§r§7 was killed by §r§8§lAshfang§r§7§r§7. + */ + private val deathMessagePattern by RepoPattern.pattern( + "chat.player.death", + "§c ☠ §r§7§r§.(?.+)§r§7 (?.+)", + ) + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + val message = event.message + deathMessagePattern.matchMatcher(message) { + val name = group("name") + val reason = group("reason").removeColor() + PlayerDeathEvent(name, reason, event).postAndCatch() + } + } +} -- cgit