Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,7 @@ public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSou

if (source instanceof EntityDamageSourceIndirect) {
damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
if (damager.getBukkitEntity() instanceof ThrownPotion) {
cause = DamageCause.MAGIC;
} else if (damager.getBukkitEntity() instanceof Projectile) {
cause = DamageCause.PROJECTILE;
}
cause = checkMagicOrProjectile(damager, cause);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really need cause as an argument here since you never use the value that's passed in. It's really just a local variable inside checkMagicOrProjectile that happens to have the same name as the variable out here.

} else if ("thorns".equals(source.translationIndex)) {
cause = DamageCause.THORNS;
}
Expand All @@ -419,6 +415,28 @@ public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSou
return event;
}

DamageCause cause = setCause(source);

if (cause != null) {
return callEntityDamageEvent(null, entity, cause, damage);
}

// If an event was called earlier, we return null.
// EG: Cactus, Lava, EntityEnderPearl "fall", FallingSand
return null;
}

private static DamageCause checkMagicOrProjectile(Entity damager,
DamageCause cause) {
if (damager.getBukkitEntity() instanceof ThrownPotion) {
cause = DamageCause.MAGIC;
} else if (damager.getBukkitEntity() instanceof Projectile) {
cause = DamageCause.PROJECTILE;
}
return cause;
}

private static DamageCause setCause(DamageSource source) {
DamageCause cause = null;
if (source == DamageSource.FIRE) {
cause = DamageCause.FIRE;
Expand All @@ -439,14 +457,7 @@ public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSou
} else if (source == DamageSource.MAGIC) {
cause = DamageCause.MAGIC;
}

if (cause != null) {
return callEntityDamageEvent(null, entity, cause, damage);
}

// If an event was called earlier, we return null.
// EG: Cactus, Lava, EntityEnderPearl "fall", FallingSand
return null;
return cause;
}

// Non-Living Entities such as EntityEnderCrystal need to call this
Expand Down