diff options
author | TomyLobo <tomylobo@nurfuerspam.de> | 2012-02-28 04:59:09 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-28 21:57:17 -0500 |
commit | 1876c12a7979676367d357bd37e25f9492c557da (patch) | |
tree | 1ffae45ad50c36ece73eeb857acbc2d14889554d /src/main | |
parent | 93521af608fc836cc631677cd8f78f4c835483f4 (diff) | |
download | bukkit-1876c12a7979676367d357bd37e25f9492c557da.tar bukkit-1876c12a7979676367d357bd37e25f9492c557da.tar.gz bukkit-1876c12a7979676367d357bd37e25f9492c557da.tar.lz bukkit-1876c12a7979676367d357bd37e25f9492c557da.tar.xz bukkit-1876c12a7979676367d357bd37e25f9492c557da.zip |
Narrowed down the return type of most EntityEvent subclasses for convenience. Addresses BUKKIT-809
Diffstat (limited to 'src/main')
18 files changed, 139 insertions, 52 deletions
diff --git a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java index fec86e09..1761e24b 100644 --- a/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java +++ b/src/main/java/org/bukkit/event/entity/CreatureSpawnEvent.java @@ -1,8 +1,7 @@ package org.bukkit.event.entity; -import org.bukkit.entity.CreatureType; -import org.bukkit.entity.EntityType; import org.bukkit.Location; +import org.bukkit.entity.CreatureType; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.event.Cancellable; @@ -37,6 +36,11 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { canceled = cancel; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + /** * Gets the location at which the creature is spawning. * @@ -54,16 +58,7 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable { */ @Deprecated public CreatureType getCreatureType() { - return CreatureType.fromEntityType(getSpawnedType()); - } - - /** - * Gets the type of creature being spawned. - * - * @return A CreatureType value detailing the type of creature being spawned - */ - public EntityType getSpawnedType() { - return getEntity().getType(); + return CreatureType.fromEntityType(getEntityType()); } /** diff --git a/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java b/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java index 628dd871..eef769a9 100644 --- a/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java +++ b/src/main/java/org/bukkit/event/entity/CreeperPowerEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Entity; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.LightningStrike; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -13,14 +14,14 @@ public class CreeperPowerEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean canceled; private final PowerCause cause; - private Entity bolt; + private LightningStrike bolt; - public CreeperPowerEvent(final Entity creeper, final Entity bolt, final PowerCause cause) { + public CreeperPowerEvent(final Creeper creeper, final LightningStrike bolt, final PowerCause cause) { this(creeper, cause); this.bolt = bolt; } - public CreeperPowerEvent(final Entity creeper, final PowerCause cause) { + public CreeperPowerEvent(final Creeper creeper, final PowerCause cause) { super(creeper); this.cause = cause; } @@ -33,12 +34,17 @@ public class CreeperPowerEvent extends EntityEvent implements Cancellable { canceled = cancel; } + @Override + public Creeper getEntity() { + return (Creeper) entity; + } + /** * Gets the lightning bolt which is striking the Creeper. * * @return The Entity for the lightning bolt which is striking the Creeper */ - public Entity getLightning() { + public LightningStrike getLightning() { return bolt; } diff --git a/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java index 973236aa..c805e52d 100644 --- a/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java @@ -2,7 +2,7 @@ package org.bukkit.event.entity; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -17,13 +17,18 @@ public class EntityChangeBlockEvent extends EntityEvent implements Cancellable { private boolean cancel; private final Material to; - public EntityChangeBlockEvent(final Entity what, final Block block, final Material to) { + public EntityChangeBlockEvent(final LivingEntity what, final Block block, final Material to) { super(what); this.block = block; this.cancel = false; this.to = to; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + /** * Gets the block the entity is changing * diff --git a/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java b/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java index b29d1fe2..286c206d 100644 --- a/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityCreatePortalEvent.java @@ -3,7 +3,7 @@ package org.bukkit.event.entity; import java.util.List; import org.bukkit.PortalType; import org.bukkit.block.BlockState; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -16,13 +16,18 @@ public class EntityCreatePortalEvent extends EntityEvent implements Cancellable private boolean cancelled = false; private PortalType type = PortalType.CUSTOM; - public EntityCreatePortalEvent(final Entity what, final List<BlockState> blocks, final PortalType type) { + public EntityCreatePortalEvent(final LivingEntity what, final List<BlockState> blocks, final PortalType type) { super(what); this.blocks = blocks; this.type = type; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + /** * Gets a list of all blocks associated with the portal. * diff --git a/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java index 31672d47..d39596f6 100644 --- a/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java @@ -1,7 +1,7 @@ package org.bukkit.event.entity; import java.util.List; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; @@ -13,16 +13,21 @@ public class EntityDeathEvent extends EntityEvent { private final List<ItemStack> drops; private int dropExp = 0; - public EntityDeathEvent(final Entity entity, final List<ItemStack> drops) { + public EntityDeathEvent(final LivingEntity entity, final List<ItemStack> drops) { this(entity, drops, 0); } - public EntityDeathEvent(final Entity what, final List<ItemStack> drops, final int droppedExp) { + public EntityDeathEvent(final LivingEntity what, final List<ItemStack> drops, final int droppedExp) { super(what); this.drops = drops; this.dropExp = droppedExp; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + /** * Gets how much EXP should be dropped from this death. * <p> diff --git a/src/main/java/org/bukkit/event/entity/EntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityEvent.java index 85dc0e71..c9a4ab30 100644 --- a/src/main/java/org/bukkit/event/entity/EntityEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.entity; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.event.Event; /** @@ -18,7 +19,16 @@ public abstract class EntityEvent extends Event { * * @return Entity who is involved in this event */ - public final Entity getEntity() { + public Entity getEntity() { return entity; } + + /** + * Gets the EntityType of the Entity involved in this event. + * + * @return EntityType of the Entity involved in this event + */ + public EntityType getEntityType() { + return entity.getType(); + } } diff --git a/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java b/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java index 97413e63..69afbacd 100644 --- a/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java @@ -24,6 +24,11 @@ public class EntityShootBowEvent extends EntityEvent implements Cancellable { this.force = force; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + /** * Gets the bow ItemStack used to fire the arrow; is null if the shooter is a skeleton * diff --git a/src/main/java/org/bukkit/event/entity/EntityTameEvent.java b/src/main/java/org/bukkit/event/entity/EntityTameEvent.java index d68a1e64..f105817a 100644 --- a/src/main/java/org/bukkit/event/entity/EntityTameEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityTameEvent.java @@ -1,7 +1,7 @@ package org.bukkit.event.entity; import org.bukkit.entity.AnimalTamer; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -13,11 +13,16 @@ public class EntityTameEvent extends EntityEvent implements Cancellable { private boolean cancelled; private final AnimalTamer owner; - public EntityTameEvent(final Entity entity, final AnimalTamer owner) { + public EntityTameEvent(final LivingEntity entity, final AnimalTamer owner) { super(entity); this.owner = owner; } + @Override + public LivingEntity getEntity() { + return (LivingEntity) entity; + } + public boolean isCancelled() { return cancelled; } diff --git a/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java b/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java index 7d321908..9b6ba8e9 100644 --- a/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java +++ b/src/main/java/org/bukkit/event/entity/FoodLevelChangeEvent.java @@ -1,6 +1,6 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Entity; +import org.bukkit.entity.HumanEntity; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -12,14 +12,19 @@ public class FoodLevelChangeEvent extends EntityEvent implements Cancellable { private boolean cancel = false; private int level; - public FoodLevelChangeEvent(final Entity what, final int level) { + public FoodLevelChangeEvent(final HumanEntity what, final int level) { super(what); this.level = level; } + @Override + public HumanEntity getEntity() { + return (HumanEntity) entity; + } + /** * Gets the resultant food level that the entity involved in this event should be set to. - * <br /><br /> + * <p /> * Where 20 is a full food bar and 0 is an empty one. * * @return The resultant food level diff --git a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java b/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java index b086fae3..6f4533c0 100644 --- a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java +++ b/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java @@ -1,7 +1,7 @@ package org.bukkit.event.entity; import org.bukkit.Location; -import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -10,8 +10,8 @@ public class ItemDespawnEvent extends EntityEvent implements Cancellable { private boolean canceled; private final Location location; - public ItemDespawnEvent(final Entity spawnee, final Location loc) { - super(spawnee); + public ItemDespawnEvent(final Item despawnee, final Location loc) { + super(despawnee); location = loc; } @@ -23,6 +23,11 @@ public class ItemDespawnEvent extends EntityEvent implements Cancellable { canceled = cancel; } + @Override + public Item getEntity() { + return (Item) entity; + } + /** * Gets the location at which the item is despawning. * diff --git a/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java b/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java index 0a19c2f1..bafd934a 100644 --- a/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java +++ b/src/main/java/org/bukkit/event/entity/ItemSpawnEvent.java @@ -1,6 +1,6 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; import org.bukkit.Location; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -13,7 +13,7 @@ public class ItemSpawnEvent extends EntityEvent implements Cancellable { private final Location location; private boolean canceled; - public ItemSpawnEvent(final Entity spawnee, final Location loc) { + public ItemSpawnEvent(final Item spawnee, final Location loc) { super(spawnee); this.location = loc; } @@ -26,6 +26,11 @@ public class ItemSpawnEvent extends EntityEvent implements Cancellable { canceled = cancel; } + @Override + public Item getEntity() { + return (Item) entity; + } + /** * Gets the location at which the item is spawning. * diff --git a/src/main/java/org/bukkit/event/entity/PigZapEvent.java b/src/main/java/org/bukkit/event/entity/PigZapEvent.java index 0a990e15..47601762 100644 --- a/src/main/java/org/bukkit/event/entity/PigZapEvent.java +++ b/src/main/java/org/bukkit/event/entity/PigZapEvent.java @@ -1,6 +1,8 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Entity; +import org.bukkit.entity.LightningStrike; +import org.bukkit.entity.Pig; +import org.bukkit.entity.PigZombie; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -10,10 +12,10 @@ import org.bukkit.event.HandlerList; public class PigZapEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean canceled; - private final Entity pigzombie; - private final Entity bolt; + private final PigZombie pigzombie; + private final LightningStrike bolt; - public PigZapEvent(final Entity pig, final Entity bolt, final Entity pigzombie) { + public PigZapEvent(final Pig pig, final LightningStrike bolt, final PigZombie pigzombie) { super(pig); this.bolt = bolt; this.pigzombie = pigzombie; @@ -27,12 +29,17 @@ public class PigZapEvent extends EntityEvent implements Cancellable { canceled = cancel; } + @Override + public Pig getEntity() { + return (Pig) entity; + } + /** * Gets the bolt which is striking the pig. * * @return lightning entity */ - public Entity getLightning() { + public LightningStrike getLightning() { return bolt; } @@ -42,7 +49,7 @@ public class PigZapEvent extends EntityEvent implements Cancellable { * * @return resulting entity */ - public Entity getPigZombie() { + public PigZombie getPigZombie() { return pigzombie; } diff --git a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java index 51b052e7..26f75ed6 100644 --- a/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java +++ b/src/main/java/org/bukkit/event/entity/PlayerDeathEvent.java @@ -31,6 +31,11 @@ public class PlayerDeathEvent extends EntityDeathEvent { this.deathMessage = deathMessage; } + @Override + public Player getEntity() { + return (Player) entity; + } + /** * Set the death message that will appear to everyone on the server. * diff --git a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java index 74905412..2065ae4d 100644 --- a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java @@ -24,6 +24,11 @@ public class PotionSplashEvent extends ProjectileHitEvent implements Cancellable this.affectedEntities = affectedEntities;
}
+ @Override
+ public ThrownPotion getEntity() {
+ return (ThrownPotion) entity;
+ }
+
/**
* Gets the potion which caused this event
*
diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java index 96278ec9..25ae8323 100644 --- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java +++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java @@ -14,6 +14,11 @@ public class ProjectileHitEvent extends EntityEvent { } @Override + public Projectile getEntity() { + return (Projectile) entity; + } + + @Override public HandlerList getHandlers() { return handlers; } diff --git a/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java b/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java index f9744156..4c17fea3 100644 --- a/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java +++ b/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java @@ -1,7 +1,7 @@ package org.bukkit.event.entity; import org.bukkit.DyeColor; -import org.bukkit.entity.Entity; +import org.bukkit.entity.Sheep; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -13,8 +13,8 @@ public class SheepDyeWoolEvent extends EntityEvent implements Cancellable { private boolean cancel; private DyeColor color; - public SheepDyeWoolEvent(final Entity what, final DyeColor color) { - super(what); + public SheepDyeWoolEvent(final Sheep sheep, final DyeColor color) { + super(sheep); this.cancel = false; this.color = color; } @@ -27,6 +27,11 @@ public class SheepDyeWoolEvent extends EntityEvent implements Cancellable { this.cancel = cancel; } + @Override + public Sheep getEntity() { + return (Sheep) entity; + } + /** * Gets the DyeColor the sheep is being dyed * diff --git a/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java b/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java index 1e12bc3a..02d8a2e0 100644 --- a/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java +++ b/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java @@ -1,6 +1,6 @@ package org.bukkit.event.entity;
-import org.bukkit.entity.Entity;
+import org.bukkit.entity.Sheep;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -11,8 +11,8 @@ public class SheepRegrowWoolEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList();
private boolean cancel;
- public SheepRegrowWoolEvent(final Entity what) {
- super(what);
+ public SheepRegrowWoolEvent(final Sheep sheep) {
+ super(sheep);
this.cancel = false;
}
@@ -25,6 +25,11 @@ public class SheepRegrowWoolEvent extends EntityEvent implements Cancellable { }
@Override
+ public Sheep getEntity() {
+ return (Sheep) entity;
+ }
+
+ @Override
public HandlerList getHandlers() {
return handlers;
}
diff --git a/src/main/java/org/bukkit/event/entity/SlimeSplitEvent.java b/src/main/java/org/bukkit/event/entity/SlimeSplitEvent.java index 4f6a1fc4..4b995871 100644 --- a/src/main/java/org/bukkit/event/entity/SlimeSplitEvent.java +++ b/src/main/java/org/bukkit/event/entity/SlimeSplitEvent.java @@ -1,6 +1,6 @@ package org.bukkit.event.entity; -import org.bukkit.entity.Entity; +import org.bukkit.entity.Slime; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -9,12 +9,11 @@ import org.bukkit.event.HandlerList; */ public class SlimeSplitEvent extends EntityEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private boolean cancel; + private boolean cancel = false; private int count; - public SlimeSplitEvent(final Entity what, final int count) { - super(what); - this.cancel = false; + public SlimeSplitEvent(final Slime slime, final int count) { + super(slime); this.count = count; } @@ -26,6 +25,11 @@ public class SlimeSplitEvent extends EntityEvent implements Cancellable { this.cancel = cancel; } + @Override + public Slime getEntity() { + return (Slime) entity; + } + /** * Gets the amount of smaller slimes to spawn * |