Added damage application verification

This commit is contained in:
Felix Cravic 2020-04-27 23:03:21 +02:00
parent bf795c1442
commit 22511ca052
2 changed files with 13 additions and 5 deletions

View File

@ -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();
}
/**

View File

@ -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