Fix damage reduction for Warrior
This commit is contained in:
parent
e6f1eec9e3
commit
202e359e81
5 changed files with 51 additions and 39 deletions
|
@ -9,6 +9,7 @@ import com.comphenix.protocol.wrappers.PlayerInfoData
|
|||
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||
import de.moritzruth.spigot_ttt.game.players.*
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.call
|
||||
import de.moritzruth.spigot_ttt.utils.nextTick
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
|
@ -86,7 +87,6 @@ object GameListener : Listener {
|
|||
val tttPlayer = TTTPlayer.of(event.entity as Player) ?: return
|
||||
if (event.cause == EntityDamageEvent.DamageCause.CUSTOM) return
|
||||
|
||||
if (tttPlayer.player.health - event.finalDamage <= 0) {
|
||||
val reason = when (event.cause) {
|
||||
EntityDamageEvent.DamageCause.FALL -> DeathReason.FALL
|
||||
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION,
|
||||
|
@ -96,12 +96,15 @@ object GameListener : Listener {
|
|||
EntityDamageEvent.DamageCause.FIRE_TICK,
|
||||
EntityDamageEvent.DamageCause.LAVA,
|
||||
EntityDamageEvent.DamageCause.HOT_FLOOR -> DeathReason.FIRE
|
||||
EntityDamageEvent.DamageCause.POISON, EntityDamageEvent.DamageCause.WITHER -> DeathReason.POISON
|
||||
EntityDamageEvent.DamageCause.POISON,
|
||||
EntityDamageEvent.DamageCause.WITHER -> DeathReason.POISON
|
||||
else -> DeathReason.SUICIDE
|
||||
}
|
||||
|
||||
tttPlayer.onDeath(reason, null)
|
||||
val e = TTTPlayerDamageEvent(tttPlayer, event.finalDamage, reason).call()
|
||||
|
||||
if (tttPlayer.player.health - e.damage <= 0) {
|
||||
tttPlayer.onDeath(reason, null)
|
||||
event.damage = 0.0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,23 @@
|
|||
package de.moritzruth.spigot_ttt.game.classes.impl
|
||||
|
||||
import de.moritzruth.spigot_ttt.game.classes.TTTClass
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.players.DeathReason
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayerDamageEvent
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
import java.util.*
|
||||
|
||||
object Stuntman: TTTClass(
|
||||
"Stuntman",
|
||||
ChatColor.DARK_RED
|
||||
) {
|
||||
val IMMUNE_DAMAGE_CAUSES = EnumSet.of(
|
||||
EntityDamageEvent.DamageCause.FALL,
|
||||
EntityDamageEvent.DamageCause.BLOCK_EXPLOSION,
|
||||
EntityDamageEvent.DamageCause.ENTITY_EXPLOSION
|
||||
)!!
|
||||
val IMMUNE_DEATH_REASONS = setOf(DeathReason.FALL, DeathReason.EXPLOSION)
|
||||
|
||||
override val listener = object : Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
fun onEntityDamage(event: EntityDamageEvent) {
|
||||
val entity = event.entity
|
||||
if (entity !is Player) return
|
||||
|
||||
val tttPlayer = TTTPlayer.of(entity) ?: return
|
||||
if (tttPlayer.tttClass == Stuntman) {
|
||||
if (IMMUNE_DAMAGE_CAUSES.contains(event.cause)) event.damage = 0.0
|
||||
fun onEntityDamage(event: TTTPlayerDamageEvent) {
|
||||
if (event.tttPlayer.tttClass == Stuntman) {
|
||||
if (IMMUNE_DEATH_REASONS.contains(event.deathReason)) event.damage = 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@ package de.moritzruth.spigot_ttt.game.classes.impl
|
|||
|
||||
import de.moritzruth.spigot_ttt.game.classes.TTTClass
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayer
|
||||
import de.moritzruth.spigot_ttt.game.players.TTTPlayerDamageEvent
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.entity.EntityDamageEvent
|
||||
|
||||
object Warrior: TTTClass(
|
||||
"Warrior",
|
||||
|
@ -18,12 +17,8 @@ object Warrior: TTTClass(
|
|||
|
||||
override val listener = object : Listener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
fun onEntityDamage(event: EntityDamageEvent) {
|
||||
val entity = event.entity
|
||||
if (entity !is Player) return
|
||||
|
||||
val tttPlayer = TTTPlayer.of(entity) ?: return
|
||||
if (tttPlayer.tttClass == Warrior) {
|
||||
fun onEntityDamage(event: TTTPlayerDamageEvent) {
|
||||
if (event.tttPlayer.tttClass == Warrior) {
|
||||
event.damage *= 0.9
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@ class TTTPlayer(player: Player, role: Role, val tttClass: TTTClass?) {
|
|||
|
||||
fun damage(damage: Double, reason: DeathReason, damager: TTTPlayer, scream: Boolean = true) {
|
||||
if (!alive) return
|
||||
val finalHealth = player.health - damage
|
||||
|
||||
val event = TTTPlayerDamageEvent(this, damage, reason).call()
|
||||
val finalHealth = player.health - event.damage
|
||||
|
||||
if (finalHealth <= 0.0) onDeath(reason, damager, scream)
|
||||
else player.damage(damage)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package de.moritzruth.spigot_ttt.game.players
|
||||
|
||||
import org.bukkit.event.Event
|
||||
import org.bukkit.event.HandlerList
|
||||
|
||||
class TTTPlayerDamageEvent(
|
||||
val tttPlayer: TTTPlayer,
|
||||
var damage: Double,
|
||||
val deathReason: DeathReason
|
||||
): Event() {
|
||||
override fun getHandlers(): HandlerList {
|
||||
@Suppress("RedundantCompanionReference") // false positive
|
||||
return Companion.handlers
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val handlers = HandlerList()
|
||||
|
||||
@JvmStatic
|
||||
fun getHandlerList() = handlers
|
||||
}
|
||||
}
|
Reference in a new issue