From b1a3aa602a8021228e3cdf429cb613c590ceb122 Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Mon, 5 Dec 2011 19:13:10 +1100 Subject: [PATCH] Clean-up some events to maintain general style --- src/main/java/net/minecraft/server/Entity.java | 2 +- .../java/net/minecraft/server/EntityArrow.java | 4 ++-- .../java/net/minecraft/server/EntityEgg.java | 3 ++- .../net/minecraft/server/EntityFireball.java | 3 ++- .../minecraft/server/EntityFishingHook.java | 3 ++- .../java/net/minecraft/server/EntityHuman.java | 5 +++-- .../net/minecraft/server/EntityMonster.java | 5 +++-- .../minecraft/server/EntitySmallFireball.java | 18 ++++++++++-------- .../net/minecraft/server/EntitySnowball.java | 16 +++++++++------- .../java/net/minecraft/server/EntityWolf.java | 3 ++- .../java/net/minecraft/server/Explosion.java | 6 +++--- .../craftbukkit/event/CraftEventFactory.java | 2 +- 12 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 7851d560c8..4759b92bfc 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -1305,7 +1305,7 @@ public abstract class Entity { // CraftBukkit start final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); final org.bukkit.entity.Entity stormBukkitEntity = entityweatherlighting.getBukkitEntity(); - final PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + final PluginManager pluginManager = Bukkit.getPluginManager(); if (thisBukkitEntity instanceof Painting) { PaintingBreakByEntityEvent event = new PaintingBreakByEntityEvent((Painting) thisBukkitEntity, stormBukkitEntity); diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java index 64e71b9d42..d4bfa92968 100644 --- a/src/main/java/net/minecraft/server/EntityArrow.java +++ b/src/main/java/net/minecraft/server/EntityArrow.java @@ -3,6 +3,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; @@ -187,13 +188,12 @@ public class EntityArrow extends Entity { // CraftBukkit start boolean stick; if (entity instanceof EntityLiving) { - org.bukkit.Server server = this.world.getServer(); org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); Projectile projectile = (Projectile) this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, l); - server.getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { stick = !projectile.doesBounce(); diff --git a/src/main/java/net/minecraft/server/EntityEgg.java b/src/main/java/net/minecraft/server/EntityEgg.java index 5211e2e377..9b02315680 100644 --- a/src/main/java/net/minecraft/server/EntityEgg.java +++ b/src/main/java/net/minecraft/server/EntityEgg.java @@ -1,5 +1,6 @@ package net.minecraft.server; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Animals; import org.bukkit.entity.CreatureType; @@ -36,7 +37,7 @@ public class EntityEgg extends EntityProjectile { Projectile projectile = (Projectile) this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { stick = !projectile.doesBounce(); diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java index 6b1e914527..cd0955cb4c 100644 --- a/src/main/java/net/minecraft/server/EntityFireball.java +++ b/src/main/java/net/minecraft/server/EntityFireball.java @@ -3,6 +3,7 @@ package net.minecraft.server; import java.util.List; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.entity.Explosive; @@ -192,7 +193,7 @@ public class EntityFireball extends Entity { Projectile projectile = (Projectile) this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { stick = !projectile.doesBounce(); diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java index 5a48641c82..5e099849a3 100644 --- a/src/main/java/net/minecraft/server/EntityFishingHook.java +++ b/src/main/java/net/minecraft/server/EntityFishingHook.java @@ -3,6 +3,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; @@ -196,7 +197,7 @@ public class EntityFishingHook extends Entity { Projectile projectile = (Projectile) this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 0); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { stick = !projectile.doesBounce(); diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index 3a8b7f8fe5..29297677bf 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.List; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftItem; import org.bukkit.craftbukkit.TrigMath; import org.bukkit.entity.Player; @@ -591,7 +592,7 @@ public abstract class EntityHuman extends EntityLiving { org.bukkit.entity.Entity damagee = this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled() || event.getDamage() == 0) { return false; @@ -779,7 +780,7 @@ public abstract class EntityHuman extends EntityLiving { org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, i); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled() || event.getDamage() == 0) { return; diff --git a/src/main/java/net/minecraft/server/EntityMonster.java b/src/main/java/net/minecraft/server/EntityMonster.java index c425f67cb9..f1c1a1faf0 100644 --- a/src/main/java/net/minecraft/server/EntityMonster.java +++ b/src/main/java/net/minecraft/server/EntityMonster.java @@ -1,6 +1,7 @@ package net.minecraft.server; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -49,7 +50,7 @@ public abstract class EntityMonster extends EntityCreature implements IMonster { org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity(); EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { if (event.getTarget() == null) { @@ -88,7 +89,7 @@ public abstract class EntityMonster extends EntityCreature implements IMonster { org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(this.getBukkitEntity(), damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, this.damage); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); i = event.getDamage(); if (!event.isCancelled()) { diff --git a/src/main/java/net/minecraft/server/EntitySmallFireball.java b/src/main/java/net/minecraft/server/EntitySmallFireball.java index 426ad87beb..f36af592ed 100644 --- a/src/main/java/net/minecraft/server/EntitySmallFireball.java +++ b/src/main/java/net/minecraft/server/EntitySmallFireball.java @@ -1,6 +1,7 @@ package net.minecraft.server; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -25,16 +26,17 @@ public class EntitySmallFireball extends EntityFireball { if (!this.world.isStatic) { // CraftBukkit start - projectile hit event ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); - final PluginManager pluginManager = this.world.getServer().getPluginManager(); + final PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.callEvent(phe); // CraftBukkit end - if (movingobjectposition.entity != null) { + final Entity movingEntity = movingobjectposition.entity; + if (movingEntity != null) { // CraftBukkit start - entity damage by entity event + combust event - if (!movingobjectposition.entity.isFireproof()) { // check if not fireproof + if (!movingEntity.isFireproof()) { // check if not fireproof boolean stick; - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); + org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity(); Projectile projectile = (Projectile) this.getBukkitEntity(); - if (movingobjectposition.entity instanceof EntityLiving) { + if (movingEntity instanceof EntityLiving) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, 5); pluginManager.callEvent(event); @@ -43,10 +45,10 @@ public class EntitySmallFireball extends EntityFireball { 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()); + stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), event.getDamage()); } } else { - stick = movingobjectposition.entity.damageEntity(DamageSource.fireball(this, this.shooter), 5); + stick = movingEntity.damageEntity(DamageSource.fireball(this, this.shooter), 5); } if (stick) { // if the fireball 'sticks', ignite the target @@ -54,7 +56,7 @@ public class EntitySmallFireball extends EntityFireball { pluginManager.callEvent(combustEvent); if (!combustEvent.isCancelled()) { - movingobjectposition.entity.setOnFire(combustEvent.getDuration()); + movingEntity.setOnFire(combustEvent.getDuration()); } } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/EntitySnowball.java b/src/main/java/net/minecraft/server/EntitySnowball.java index fd82264b81..bbacb28fea 100644 --- a/src/main/java/net/minecraft/server/EntitySnowball.java +++ b/src/main/java/net/minecraft/server/EntitySnowball.java @@ -1,6 +1,7 @@ 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; @@ -31,16 +32,17 @@ public class EntitySnowball extends EntityProjectile { } // CraftBukkit start ProjectileHitEvent hitEvent = new ProjectileHitEvent((Projectile) this.getBukkitEntity()); - this.world.getServer().getPluginManager().callEvent(hitEvent); + Bukkit.getPluginManager().callEvent(hitEvent); + final Entity movingEntity = movingobjectposition.entity; boolean stick = false; - if (movingobjectposition.entity != null) { - if (movingobjectposition.entity instanceof EntityLiving) { - org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity(); + if (movingEntity != null) { + if (movingEntity instanceof EntityLiving) { + org.bukkit.entity.Entity damagee = movingEntity.getBukkitEntity(); Projectile projectile = (Projectile) this.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, b0); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); this.shooter = (projectile.getShooter() == null) ? null : ((CraftLivingEntity) projectile.getShooter()).getHandle(); b0 = (byte) event.getDamage(); @@ -48,10 +50,10 @@ public class EntitySnowball extends EntityProjectile { stick = !projectile.doesBounce(); } else { // this function returns if the snowball should stick in or not, i.e. !bounce - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), b0); + stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0); } } else { - stick = movingobjectposition.entity.damageEntity(DamageSource.projectile(this, this.shooter), b0); + stick = movingEntity.damageEntity(DamageSource.projectile(this, this.shooter), b0); } } diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index cd6d7a0cd4..879501ba7f 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.List; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -341,7 +342,7 @@ public class EntityWolf extends EntityAnimal { org.bukkit.entity.Entity damagee = entity == null ? null : entity.getBukkitEntity(); EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, b0); - this.world.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index 1d67dccf6b..739f1f4951 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -7,6 +7,7 @@ import java.util.Random; import java.util.Set; // CraftBukkit start +import org.bukkit.Bukkit; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -117,7 +118,6 @@ public class Explosion { double d10 = (1.0D - d7) * d9; // CraftBukkit start - explosion damage hook - org.bukkit.Server server = this.world.getServer(); org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity(); int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D); @@ -127,7 +127,7 @@ public class Explosion { // TODO: get the x/y/z of the tnt block? // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever EntityDamageByBlockEvent event = new EntityDamageByBlockEvent(null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone); - server.getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { entity.damageEntity(DamageSource.EXPLOSION, event.getDamage()); @@ -144,7 +144,7 @@ public class Explosion { damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION; } EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone); - server.getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { entity.damageEntity(DamageSource.EXPLOSION, event.getDamage()); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index cfa0ec8853..17438f7c3d 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -299,7 +299,7 @@ public class CraftEventFactory { } public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List drops) { - CraftLivingEntity entity = (CraftLivingEntity)victim.getBukkitEntity(); + CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity(); EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward()); org.bukkit.World world = entity.getWorld(); Bukkit.getServer().getPluginManager().callEvent(event);