Skip to content

Commit

Permalink
Add a delay between revive and death state
Browse files Browse the repository at this point in the history
tab list always lags behind chat message
  • Loading branch information
My-Name-Is-Jeff committed Sep 15, 2023
1 parent df4b117 commit 836a824
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/main/kotlin/gg/skytils/skytilsmod/listeners/DungeonListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,12 @@ object DungeonListener {
val match = deathRegex.find(text) ?: return
val username = match.groups["username"]?.value ?: mc.thePlayer.name
val teammate = team[username] ?: return
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} detected dead from chat message")
markDead(teammate)
} else if (text.startsWith("§r§a ❣ ")) {
val match = reviveRegex.find(text) ?: return
val username = match.groups["username"]!!.value
val teammate = team[username] ?: return
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} detected revived from chat message")
if (deads.remove(teammate)) {
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} removed from dead list")
teammate.dead = false
}
markRevived(teammate)
}
}
}
Expand Down Expand Up @@ -172,13 +167,8 @@ object DungeonListener {
it.name == teammate.playerName && it.uniqueID.version() == 4
}
if (self?.dead != true) {
if (entry.endsWith("§r§cDEAD§r§f)§r")) {
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} detected dead from tablist")
markDead(teammate)
} else if (deads.remove(teammate)) {
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} removed from dead list")
teammate.dead = false
}
if (entry.endsWith("§r§cDEAD§r§f)§r")) markDead(teammate)
else markRevived(teammate)
}
}
}
Expand All @@ -187,13 +177,10 @@ object DungeonListener {

fun markDead(teammate: DungeonTeammate) {
if (deads.add(teammate)) {
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} added on dead list")
val time = System.currentTimeMillis()
val lastDeath = teammate.lastMarkedDead
// there's no way they die twice in less than half a second
if (lastDeath != null && time - lastDeath <= 500) return
UChat.chat("${Skytils.prefix} §fdebug: ${teammate.playerName} passed dead time check")
teammate.lastMarkedDead = time
val lastDeath = teammate.lastLivingStateChange
if (lastDeath != null && time - lastDeath <= 1000) return
teammate.lastLivingStateChange = time
teammate.dead = true
teammate.deaths++
val totalDeaths = team.values.sumOf { it.deaths }
Expand Down Expand Up @@ -221,6 +208,13 @@ object DungeonListener {
}
}

fun markRevived(teammate: DungeonTeammate) {
if (deads.remove(teammate)) {
teammate.dead = false
teammate.lastLivingStateChange = System.currentTimeMillis()
}
}

fun markAllRevived() {
UChat.chat("${Skytils.prefix} §fdebug: marking all teammates as revived")
deads.clear()
Expand Down Expand Up @@ -319,7 +313,7 @@ object DungeonListener {
var player: EntityPlayer? = null
var dead = false
var deaths = 0
var lastMarkedDead: Long? = null
var lastLivingStateChange: Long? = null


fun canRender() = player != null && player!!.health > 0 && !dead
Expand Down

0 comments on commit 836a824

Please sign in to comment.