From d870ab8501c6dde54833c1cb68f40ac95631d900 Mon Sep 17 00:00:00 2001 From: tylerswanson2 <31103658+tylerswanson2@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:38:15 -0500 Subject: [PATCH] Fix absorption --- .../server/module/combat/OldCombatModule.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/common/src/main/kotlin/com/bluedragonmc/server/module/combat/OldCombatModule.kt b/common/src/main/kotlin/com/bluedragonmc/server/module/combat/OldCombatModule.kt index 44df7dfc..8b7e7194 100644 --- a/common/src/main/kotlin/com/bluedragonmc/server/module/combat/OldCombatModule.kt +++ b/common/src/main/kotlin/com/bluedragonmc/server/module/combat/OldCombatModule.kt @@ -13,6 +13,7 @@ import net.minestom.server.entity.damage.DamageType import net.minestom.server.event.Event import net.minestom.server.event.EventNode import net.minestom.server.event.entity.EntityAttackEvent +import net.minestom.server.event.entity.EntityPotionAddEvent import net.minestom.server.event.entity.EntityTickEvent import net.minestom.server.event.player.PlayerEatEvent import net.minestom.server.event.player.PlayerSpawnEvent @@ -79,14 +80,8 @@ class OldCombatModule(var allowDamage: Boolean = true, var allowKnockback: Boole if(event.entity is Player) { val player = event.entity as Player player.activeEffects.forEach { - when(it.potion.effect) { - PotionEffect.REGENERATION -> { - player.health = (player.health + 1.0f / (50.0f / it.potion.amplifier)).coerceAtMost(player.maxHealth) - } - PotionEffect.ABSORPTION -> { - player.additionalHearts = 4.0f * it.potion.amplifier - } - else -> {} + if (it.potion.effect == PotionEffect.REGENERATION) { + player.health = (player.health + 1.0f / (50.0f / it.potion.amplifier)).coerceAtMost(player.maxHealth) } } if(player.activeEffects.none { it.potion.effect == PotionEffect.ABSORPTION }) @@ -130,6 +125,13 @@ class OldCombatModule(var allowDamage: Boolean = true, var allowKnockback: Boole event.player.setItemInHand(event.hand, event.itemStack.withAmount(event.itemStack.amount() - 1)) } + eventNode.addListener(EntityPotionAddEvent::class.java) { event -> + val entity = event.entity as? Player ?: return@addListener + if (event.potion.effect == PotionEffect.ABSORPTION) { + entity.additionalHearts = 4.0f * event.potion.amplifier + } + } + eventNode.addListener(EntityAttackEvent::class.java) { event -> if (event.entity !is Player) return@addListener