blob: 1de8f09a22db38254d9bb7d2b42bef88d8ba9843 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package at.hannibal2.skyhanni.features.chat
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.getLorenzVec
import net.minecraft.client.Minecraft
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
class PlayerDeathMessages {
private var tick = 0
private val lastTimePlayerSeen = mutableMapOf<String, Long>()
//§c ☠ §r§7§r§bZeroHazel§r§7 was killed by §r§8§lAshfang§r§7§r§7.
private val pattern = "§c ☠ §r§7§r§.(.+)§r§7 (.+)".toPattern()
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
if (!isHideFarDeathsEnabled()) return
if (tick++ % 20 == 0) {
checkOtherPlayers()
}
}
@SubscribeEvent
fun onChatMessage(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
val message = event.message
val matcher = pattern.matcher(message)
if (matcher.matches()) {
val name = matcher.group(1)
if (SkyHanniMod.feature.markedPlayers.highlightInChat && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight) {
if (MarkedPlayerManager.isMarkedPlayer(name)) {
val reason = matcher.group(2).removeColor()
LorenzUtils.chat(" §c☠ §e$name §7$reason")
event.blockedReason = "marked_player_death"
return
}
}
if (isHideFarDeathsEnabled()) {
if (System.currentTimeMillis() > lastTimePlayerSeen.getOrDefault(name, 0) + 30_000) {
event.blockedReason = "far_away_player_death"
}
}
}
}
private fun checkOtherPlayers() {
val location = LocationUtils.playerLocation()
for (otherPlayer in Minecraft.getMinecraft().theWorld.loadedEntityList
.filterIsInstance<EntityOtherPlayerMP>()
.filter { it.getLorenzVec().distance(location) < 25 }) {
lastTimePlayerSeen[otherPlayer.name] = System.currentTimeMillis()
}
}
private fun isHideFarDeathsEnabled(): Boolean {
return LorenzUtils.inSkyBlock && SkyHanniMod.feature.chat.hideFarDeathMessages && !LorenzUtils.inDungeons && !LorenzUtils.inKuudraFight
}
}
|