mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-13 11:41:52 +01:00
Added damage application verification
This commit is contained in:
parent
bf795c1442
commit
22511ca052
@ -105,9 +105,14 @@ public abstract class LivingEntity extends Entity {
|
|||||||
callEvent(DeathEvent.class, deathEvent);
|
callEvent(DeathEvent.class, deathEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void damage(DamageType type, float value) {
|
/**
|
||||||
|
* @param type the damage type
|
||||||
|
* @param value the amount of damage
|
||||||
|
* @return true if damage has been applied, false if it didn't
|
||||||
|
*/
|
||||||
|
public boolean damage(DamageType type, float value) {
|
||||||
if (isImmune(type)) {
|
if (isImmune(type)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityDamageEvent entityDamageEvent = new EntityDamageEvent(type, value);
|
EntityDamageEvent entityDamageEvent = new EntityDamageEvent(type, value);
|
||||||
@ -120,6 +125,8 @@ public abstract class LivingEntity extends Entity {
|
|||||||
sendPacketToViewersAndSelf(entityAnimationPacket);
|
sendPacketToViewersAndSelf(entityAnimationPacket);
|
||||||
setHealth(getHealth() - damage);
|
setHealth(getHealth() - damage);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return !entityDamageEvent.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,11 +116,12 @@ public class Player extends LivingEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage(DamageType type, float value) {
|
public boolean damage(DamageType type, float value) {
|
||||||
if (!isImmune(type)) {
|
boolean result = super.damage(type, value);
|
||||||
|
if (result) {
|
||||||
lastDamageSource = type;
|
lastDamageSource = type;
|
||||||
}
|
}
|
||||||
super.damage(type, value);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user