mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Prevent IllegalArgumentException with Rupture and provide more detailed logging when Rupture cannot activate from illegal state Fixes #5063
This commit is contained in:
parent
684583c19b
commit
c7409a8f9b
@ -8,10 +8,13 @@ import com.gmail.nossr50.util.MetadataConstants;
|
|||||||
import com.gmail.nossr50.util.MobHealthbarUtils;
|
import com.gmail.nossr50.util.MobHealthbarUtils;
|
||||||
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH;
|
||||||
|
|
||||||
public class RuptureTask extends CancellableRunnable {
|
public class RuptureTask extends CancellableRunnable {
|
||||||
|
|
||||||
public static final int DAMAGE_TICK_INTERVAL = 10;
|
public static final int DAMAGE_TICK_INTERVAL = 10;
|
||||||
@ -82,20 +85,36 @@ public class RuptureTask extends CancellableRunnable {
|
|||||||
private boolean applyRupture() {
|
private boolean applyRupture() {
|
||||||
double healthBeforeRuptureIsApplied = targetEntity.getHealth();
|
double healthBeforeRuptureIsApplied = targetEntity.getHealth();
|
||||||
|
|
||||||
//Ensure victim has health
|
// Ensure victim has health
|
||||||
if (healthBeforeRuptureIsApplied > 0.01) {
|
if (healthBeforeRuptureIsApplied > 0.01) {
|
||||||
//Send a fake damage event
|
//Send a fake damage event
|
||||||
McMMOEntityDamageByRuptureEvent event =
|
McMMOEntityDamageByRuptureEvent event =
|
||||||
new McMMOEntityDamageByRuptureEvent(ruptureSource, targetEntity, calculateAdjustedTickDamage());
|
new McMMOEntityDamageByRuptureEvent(ruptureSource, targetEntity, calculateAdjustedTickDamage());
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
//Ensure the event wasn't cancelled and damage is still greater than 0
|
//Ensure the event wasn't canceled and damage is still greater than 0
|
||||||
double damage = event.getDamage(); //Use raw damage for Rupture
|
double damage = event.getDamage(); //Use raw damage for Rupture
|
||||||
|
|
||||||
if (event.isCancelled() || damage <= 0 || healthBeforeRuptureIsApplied - damage <= 0)
|
if (event.isCancelled() || damage <= 0 || healthBeforeRuptureIsApplied - damage <= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
double damagedHealth = healthBeforeRuptureIsApplied - damage;
|
final double damagedHealth = healthBeforeRuptureIsApplied - damage;
|
||||||
|
|
||||||
|
final AttributeInstance maxHealthAttribute = targetEntity.getAttribute(GENERIC_MAX_HEALTH);
|
||||||
|
if (maxHealthAttribute == null) {
|
||||||
|
// Can't remove health if max health is null
|
||||||
|
mcMMO.p.getLogger().info("RuptureTask: Target entity has an illegal state for its health." +
|
||||||
|
" Cancelling Rupture. Target has null " + GENERIC_MAX_HEALTH + " attribute.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damagedHealth > maxHealthAttribute.getValue()) {
|
||||||
|
// Something went very wrong here, target has an illegal state for its health
|
||||||
|
mcMMO.p.getLogger().info("RuptureTask: Target entity has an illegal state for its health." +
|
||||||
|
" Cancelling Rupture. Target has " + targetEntity.getHealth() + " health," +
|
||||||
|
" but max health is " + maxHealthAttribute.getValue());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
targetEntity.setHealth(damagedHealth); //Hurt entity without the unwanted side effects of damage()}
|
targetEntity.setHealth(damagedHealth); //Hurt entity without the unwanted side effects of damage()}
|
||||||
MobHealthbarUtils.handleMobHealthbars(targetEntity, damage, mcMMO.p);
|
MobHealthbarUtils.handleMobHealthbars(targetEntity, damage, mcMMO.p);
|
||||||
|
@ -38,6 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.gmail.nossr50.datatypes.experience.XPGainReason.PVP;
|
||||||
import static com.gmail.nossr50.util.MobMetadataUtils.hasMobFlag;
|
import static com.gmail.nossr50.util.MobMetadataUtils.hasMobFlag;
|
||||||
|
|
||||||
public final class CombatUtils {
|
public final class CombatUtils {
|
||||||
@ -891,7 +892,7 @@ public final class CombatUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xpGainReason = XPGainReason.PVP;
|
xpGainReason = PVP;
|
||||||
|
|
||||||
if (defender.isOnline()
|
if (defender.isOnline()
|
||||||
&& SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) {
|
&& SkillUtils.cooldownExpired(mcMMOPlayer.getRespawnATS(), Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user