summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-06-20 23:25:12 +0200
committerGitHub <noreply@github.com>2024-06-20 23:25:12 +0200
commit89c8bf8103b9429fbc7a1ea63612dac565872d43 (patch)
tree7241600240caefa786aac3c787f0c67e6e926d11 /src/main/java/at/hannibal2/skyhanni/data
parent1a32e5e1a6e338e87043d39d04b9a6b817544469 (diff)
downloadskyhanni-89c8bf8103b9429fbc7a1ea63612dac565872d43.tar.gz
skyhanni-89c8bf8103b9429fbc7a1ea63612dac565872d43.tar.bz2
skyhanni-89c8bf8103b9429fbc7a1ea63612dac565872d43.zip
Backend: PlayerDeathEvent (#1544)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MiningAPI.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PlayerDeathManager.kt31
2 files changed, 40 insertions, 7 deletions
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§.(?<name>.+)§r§7 (?<reason>.+)",
+ )
+
+ @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()
+ }
+ }
+}