diff options
author | Feildmaster <admin@feildmaster.com> | 2012-02-10 08:32:11 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-19 01:05:11 -0500 |
commit | b06719dd03aa722410d54b9f8adc4030f9eb03a8 (patch) | |
tree | 463f613652cb2e7e387f2fb04e18c0f611ea6c2b /src | |
parent | 5316c43a82718eaa30a0fb93bb9421b7a64c87ff (diff) | |
download | craftbukkit-b06719dd03aa722410d54b9f8adc4030f9eb03a8.tar craftbukkit-b06719dd03aa722410d54b9f8adc4030f9eb03a8.tar.gz craftbukkit-b06719dd03aa722410d54b9f8adc4030f9eb03a8.tar.lz craftbukkit-b06719dd03aa722410d54b9f8adc4030f9eb03a8.tar.xz craftbukkit-b06719dd03aa722410d54b9f8adc4030f9eb03a8.zip |
[Bleeding] Moved projectile EntityDamageByEntityEvent's to event factory. Addresses BUKKIT-775
Diffstat (limited to 'src')
7 files changed, 41 insertions, 154 deletions
diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java index e968d592..a1b899a9 100644 --- a/src/main/java/net/minecraft/server/EntityArrow.java +++ b/src/main/java/net/minecraft/server/EntityArrow.java @@ -6,8 +6,6 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerPickupItemEvent; // CraftBukkit end @@ -169,7 +167,8 @@ public class EntityArrow extends Entity { if (movingobjectposition != null) { // CraftBukkit start - ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); + Projectile projectile = (Projectile) this.getBukkitEntity(); + ProjectileHitEvent phe = new ProjectileHitEvent(projectile); this.world.getServer().getPluginManager().callEvent(phe); // CraftBukkit end if (movingobjectposition.entity != null) { @@ -198,28 +197,8 @@ public class EntityArrow extends Entity { } // CraftBukkit end } - - // CraftBukkit start - boolean stick; - if (entity instanceof EntityLiving || entity instanceof EntityComplexPart) { - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, l); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the arrow should stick in or not, i.e. !bounce - stick = movingobjectposition.entity.damageEntity(damagesource, event.getDamage()); - } - } else { - stick = movingobjectposition.entity.damageEntity(damagesource, l); - } - - if (stick) { - // CraftBukkit end + // CraftBukkit - entity.damageEntity -> event function + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, entity, damagesource, l)) { if (movingobjectposition.entity instanceof EntityLiving) { ++((EntityLiving) movingobjectposition.entity).aJ; if (this.n > 0) { diff --git a/src/main/java/net/minecraft/server/EntityEgg.java b/src/main/java/net/minecraft/server/EntityEgg.java index f3145561..76490d10 100644 --- a/src/main/java/net/minecraft/server/EntityEgg.java +++ b/src/main/java/net/minecraft/server/EntityEgg.java @@ -1,14 +1,12 @@ package net.minecraft.server; -import org.bukkit.Bukkit; +// CraftBukkit start import org.bukkit.Location; import org.bukkit.entity.Animals; import org.bukkit.entity.CreatureType; -import org.bukkit.entity.Projectile; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerEggThrowEvent; +// CraftBukkit end public class EntityEgg extends EntityProjectile { @@ -27,25 +25,7 @@ public class EntityEgg extends EntityProjectile { protected void a(MovingObjectPosition movingobjectposition) { // CraftBukkit start if (movingobjectposition.entity != null) { - boolean stick; - if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) { - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the egg should stick in or not, i.e. !bounce - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), event.getDamage()); - } - } else { - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), 0); - } - - if (stick) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) { ; // Original code does nothing *yet* } } diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java index 4925dafc..c8366ffa 100644 --- a/src/main/java/net/minecraft/server/EntityFireball.java +++ b/src/main/java/net/minecraft/server/EntityFireball.java @@ -3,12 +3,9 @@ package net.minecraft.server; import java.util.List; // CraftBukkit start -import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.entity.Explosive; import org.bukkit.entity.Projectile; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ProjectileHitEvent; // CraftBukkit end @@ -181,30 +178,14 @@ public class EntityFireball extends Entity { protected void a(MovingObjectPosition movingobjectposition) { if (!this.world.isStatic) { // CraftBukkit start - ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); + Projectile projectile = (Projectile) this.getBukkitEntity(); + ProjectileHitEvent phe = new ProjectileHitEvent(projectile); this.world.getServer().getPluginManager().callEvent(phe); // CraftBukkit end if (!this.world.isStatic) { // CraftBukkit start if (movingobjectposition.entity != null) { - boolean stick; - if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) { - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the fireball should stick in or not, i.e. !bounce - stick = movingobjectposition.entity.damageEntity(DamageSource.fireball(this, this.shooter), event.getDamage()); - } - } else { - stick = movingobjectposition.entity.damageEntity(DamageSource.fireball(this, this.shooter), 0); - } - if (stick) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) { ; } } diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java index e8602b81..7141be75 100644 --- a/src/main/java/net/minecraft/server/EntityFishingHook.java +++ b/src/main/java/net/minecraft/server/EntityFishingHook.java @@ -2,13 +2,7 @@ package net.minecraft.server; import java.util.List; -// CraftBukkit start -import org.bukkit.Bukkit; -import org.bukkit.entity.Projectile; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerFishEvent; -// CraftBukkit end +import org.bukkit.event.player.PlayerFishEvent; // CraftBukkit public class EntityFishingHook extends Entity { @@ -190,26 +184,8 @@ public class EntityFishingHook extends Entity { if (movingobjectposition != null) { if (movingobjectposition.entity != null) { - // CraftBukkit start - boolean stick; - if (movingobjectposition.entity instanceof EntityLiving || movingobjectposition.entity instanceof EntityComplexPart) { - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the fish should stick in or not, i.e. !bounce - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.owner), event.getDamage()); - } - } else { - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.owner), 0); - } - if (!stick) { - // CraftBukkit end + // CraftBukkit - entity.damageEntity -> event function + if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), entity, DamageSource.projectile(this, this.owner), 0)) { this.hooked = movingobjectposition.entity; } } else { diff --git a/src/main/java/net/minecraft/server/EntitySmallFireball.java b/src/main/java/net/minecraft/server/EntitySmallFireball.java index e33055dc..03933043 100644 --- a/src/main/java/net/minecraft/server/EntitySmallFireball.java +++ b/src/main/java/net/minecraft/server/EntitySmallFireball.java @@ -4,8 +4,6 @@ package net.minecraft.server; import org.bukkit.Bukkit; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.plugin.PluginManager; // CraftBukkit end @@ -25,7 +23,8 @@ public class EntitySmallFireball extends EntityFireball { protected void a(MovingObjectPosition movingobjectposition) { if (!this.world.isStatic) { // CraftBukkit start - projectile hit event - ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); + Projectile projectile = (Projectile) this.getBukkitEntity(); + ProjectileHitEvent phe = new ProjectileHitEvent(projectile); final PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.callEvent(phe); // CraftBukkit end @@ -33,25 +32,9 @@ public class EntitySmallFireball extends EntityFireball { if (movingEntity != null) { // CraftBukkit start - entity damage by entity event + combust event if (!movingEntity.isFireproof()) { // check if not fireproof - boolean stick; org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - if (movingEntity instanceof EntityLiving || movingEntity instanceof EntityComplexPart) { - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 5); - pluginManager.callEvent(event); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the fireball should stick in or not, i.e. !bounce - stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), event.getDamage()); - } - } else { - stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), 5); - } - - if (stick) { + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent(projectile, movingobjectposition.entity, DamageSource.projectile(this, this.shooter), 0)) { // if the fireball 'sticks', ignite the target EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(projectile, damagee, 5); pluginManager.callEvent(combustEvent); diff --git a/src/main/java/net/minecraft/server/EntitySnowball.java b/src/main/java/net/minecraft/server/EntitySnowball.java index f935fbf0..3dc5b9ac 100644 --- a/src/main/java/net/minecraft/server/EntitySnowball.java +++ b/src/main/java/net/minecraft/server/EntitySnowball.java @@ -1,13 +1,5 @@ package net.minecraft.server; -// CraftBukkit start -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.entity.CraftLivingEntity; -import org.bukkit.entity.Projectile; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -// CraftBukkit end - public class EntitySnowball extends EntityProjectile { public EntitySnowball(World world) { @@ -29,33 +21,8 @@ public class EntitySnowball extends EntityProjectile { if (movingobjectposition.entity instanceof EntityBlaze) { b0 = 3; } - // CraftBukkit start - final Entity movingEntity = movingobjectposition.entity; - boolean stick = false; - - if (movingEntity != null) { - if (movingEntity instanceof EntityLiving || movingEntity instanceof EntityComplexPart) { - org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity(); - Projectile projectile = (Projectile) this.getBukkitEntity(); - - EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, b0); - Bukkit.getPluginManager().callEvent(event); - this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle(); - b0 = event.getDamage(); - - if (event.isCancelled()) { - stick = !projectile.doesBounce(); - } else { - // this function returns if the snowball should stick in or not, i.e. !bounce - stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0); - } - } else { - stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0); - } - } - - if (stick) { - // CraftBukkit end + // CraftBukkit - entity.damageEntity -> event function + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleProjectileEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), movingobjectposition.entity, DamageSource.projectile(this, this.shooter), b0)) { ; } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 161031c8..7f0d44c9 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -5,13 +5,16 @@ import java.util.List; import java.util.Map; import net.minecraft.server.ChunkCoordinates; +import net.minecraft.server.DamageSource; import net.minecraft.server.Entity; import net.minecraft.server.EntityArrow; import net.minecraft.server.EntityBlaze; import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.EntityChicken; +import net.minecraft.server.EntityComplexPart; import net.minecraft.server.EntityCow; import net.minecraft.server.EntityCreeper; +import net.minecraft.server.EntityEnderCrystal; import net.minecraft.server.EntityEnderDragon; import net.minecraft.server.EntityEnderman; import net.minecraft.server.EntityGhast; @@ -20,7 +23,6 @@ import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityItem; import net.minecraft.server.EntityMagmaCube; import net.minecraft.server.EntityLiving; -import net.minecraft.server.EntityMonster; import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.EntityPig; import net.minecraft.server.EntityPigZombie; @@ -40,9 +42,9 @@ import net.minecraft.server.Item; import net.minecraft.server.ItemStack; import net.minecraft.server.World; import net.minecraft.server.WorldServer; + import org.bukkit.Bukkit; import org.bukkit.Server; - import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -58,6 +60,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.CreatureType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.entity.ThrownPotion; import org.bukkit.event.block.*; import org.bukkit.event.entity.*; @@ -417,4 +420,22 @@ public class CraftEventFactory { Bukkit.getPluginManager().callEvent(event); return event; } + + public static boolean handleProjectileEvent(Projectile projectile, Entity target, DamageSource damagesource, int damage) { + if (target instanceof EntityLiving || target instanceof EntityComplexPart) { + org.bukkit.entity.Entity damagee = target.getBukkitEntity(); + + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, damage); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + return target.damageEntity(damagesource, damage); + } + } else { + // Other entities have their events (if any) handled in damageEntity + return target.damageEntity(damagesource, damage); + } + + return !projectile.doesBounce(); + } } |