13
0
geforkt von Mirrors/Paper

[Bleeding] Fixed potions throwing double events. Fixes BUKKIT-1332

Dieser Commit ist enthalten in:
feildmaster 2012-03-25 04:21:25 -05:00 committet von Warren Loo
Ursprung b45184fdf8
Commit 9d0ea52021
2 geänderte Dateien mit 10 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,12 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit start // CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.potion.PotionEffectType;
// CraftBukkit end // CraftBukkit end
public class MobEffectList { public class MobEffectList {
@ -86,7 +85,6 @@ public class MobEffectList {
if (entityliving.getHealth() > 1) { if (entityliving.getHealth() > 1) {
// CraftBukkit start // CraftBukkit start
EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.POISON, 1); EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.POISON, 1);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled() && event.getDamage() > 0) { if (!event.isCancelled() && event.getDamage() > 0) {
entityliving.damageEntity(DamageSource.MAGIC, event.getDamage()); entityliving.damageEntity(DamageSource.MAGIC, event.getDamage());
@ -99,7 +97,6 @@ public class MobEffectList {
if (this.id == HARM.id && !entityliving.aN() || this.id == HEAL.id && entityliving.aN()) { if (this.id == HARM.id && !entityliving.aN() || this.id == HEAL.id && entityliving.aN()) {
// CraftBukkit start // CraftBukkit start
EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.MAGIC, 6 << i); EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(null, entityliving, DamageCause.MAGIC, 6 << i);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled() && event.getDamage() > 0) { if (!event.isCancelled() && event.getDamage() > 0) {
entityliving.damageEntity(DamageSource.MAGIC, event.getDamage()); entityliving.damageEntity(DamageSource.MAGIC, event.getDamage());
@ -124,18 +121,11 @@ public class MobEffectList {
if (this.id == HARM.id && !entityliving1.aN() || this.id == HEAL.id && entityliving1.aN()) { if (this.id == HARM.id && !entityliving1.aN() || this.id == HEAL.id && entityliving1.aN()) {
j = (int) (d0 * (double) (6 << i) + 0.5D); j = (int) (d0 * (double) (6 << i) + 0.5D);
// CraftBukkit start
EntityDamageEvent event = CraftEventFactory.callEntityDamageEvent(potion != null ? potion : entityliving, entityliving1, DamageCause.MAGIC, j);
j = event.getDamage();
if (event.isCancelled() || j == 0) {
return;
}
// CraftBukkit end
if (entityliving == null) { if (entityliving == null) {
entityliving1.damageEntity(DamageSource.MAGIC, j); entityliving1.damageEntity(DamageSource.MAGIC, j);
} else { } else {
entityliving1.damageEntity(DamageSource.b(entityliving1, entityliving), j); // CraftBukkit - The "damager" needs to be the potion
entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), j);
} }
} }
} else { } else {

Datei anzeigen

@ -364,14 +364,17 @@ public class CraftEventFactory {
public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, int damage) { public static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, int damage) {
Entity damager = source.getEntity(); Entity damager = source.getEntity();
EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.ENTITY_ATTACK; DamageCause cause = DamageCause.ENTITY_ATTACK;
if (source instanceof EntityDamageSourceIndirect) { if (source instanceof EntityDamageSourceIndirect) {
damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource(); damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
if (damager.getBukkitEntity() instanceof Projectile) { if (damager.getBukkitEntity() instanceof ThrownPotion) {
cause = EntityDamageEvent.DamageCause.PROJECTILE; cause = DamageCause.MAGIC;
} // Else, magic..? } else if (damager.getBukkitEntity() instanceof Projectile) {
cause = DamageCause.PROJECTILE;
}
} }
return callEntityDamageEvent(damager, entity, cause, damage); return callEntityDamageEvent(damager, entity, cause, damage);
} }