mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 02:57:37 +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);
|
||||
}
|
||||
|
||||
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)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityDamageEvent entityDamageEvent = new EntityDamageEvent(type, value);
|
||||
@ -120,6 +125,8 @@ public abstract class LivingEntity extends Entity {
|
||||
sendPacketToViewersAndSelf(entityAnimationPacket);
|
||||
setHealth(getHealth() - damage);
|
||||
});
|
||||
|
||||
return !entityDamageEvent.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,11 +116,12 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(DamageType type, float value) {
|
||||
if (!isImmune(type)) {
|
||||
public boolean damage(DamageType type, float value) {
|
||||
boolean result = super.damage(type, value);
|
||||
if (result) {
|
||||
lastDamageSource = type;
|
||||
}
|
||||
super.damage(type, value);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user