13
0
geforkt von Mirrors/Paper

Narrowed down the return type of most EntityEvent subclasses for convenience. Addresses BUKKIT-809

By: TomyLobo <tomylobo@nurfuerspam.de>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-02-28 04:59:09 -06:00
Ursprung 345f24b35c
Commit 38fd1dd5f0
18 geänderte Dateien mit 139 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -1,8 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.EntityType;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
@ -37,6 +36,11 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
canceled = cancel; canceled = cancel;
} }
@Override
public LivingEntity getEntity() {
return (LivingEntity) entity;
}
/** /**
* Gets the location at which the creature is spawning. * Gets the location at which the creature is spawning.
* *
@ -54,16 +58,7 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
*/ */
@Deprecated @Deprecated
public CreatureType getCreatureType() { public CreatureType getCreatureType() {
return CreatureType.fromEntityType(getSpawnedType()); return CreatureType.fromEntityType(getEntityType());
}
/**
* Gets the type of creature being spawned.
*
* @return A CreatureType value detailing the type of creature being spawned
*/
public EntityType getSpawnedType() {
return getEntity().getType();
} }
/** /**

Datei anzeigen

@ -1,6 +1,7 @@
package org.bukkit.event.entity; 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.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -13,14 +14,14 @@ public class CreeperPowerEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean canceled; private boolean canceled;
private final PowerCause cause; 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(creeper, cause);
this.bolt = bolt; this.bolt = bolt;
} }
public CreeperPowerEvent(final Entity creeper, final PowerCause cause) { public CreeperPowerEvent(final Creeper creeper, final PowerCause cause) {
super(creeper); super(creeper);
this.cause = cause; this.cause = cause;
} }
@ -33,12 +34,17 @@ public class CreeperPowerEvent extends EntityEvent implements Cancellable {
canceled = cancel; canceled = cancel;
} }
@Override
public Creeper getEntity() {
return (Creeper) entity;
}
/** /**
* Gets the lightning bolt which is striking the Creeper. * Gets the lightning bolt which is striking the Creeper.
* *
* @return The Entity for 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; return bolt;
} }

Datei anzeigen

@ -2,7 +2,7 @@ package org.bukkit.event.entity;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -17,13 +17,18 @@ public class EntityChangeBlockEvent extends EntityEvent implements Cancellable {
private boolean cancel; private boolean cancel;
private final Material to; 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); super(what);
this.block = block; this.block = block;
this.cancel = false; this.cancel = false;
this.to = to; this.to = to;
} }
@Override
public LivingEntity getEntity() {
return (LivingEntity) entity;
}
/** /**
* Gets the block the entity is changing * Gets the block the entity is changing
* *

Datei anzeigen

@ -3,7 +3,7 @@ package org.bukkit.event.entity;
import java.util.List; import java.util.List;
import org.bukkit.PortalType; import org.bukkit.PortalType;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -16,13 +16,18 @@ public class EntityCreatePortalEvent extends EntityEvent implements Cancellable
private boolean cancelled = false; private boolean cancelled = false;
private PortalType type = PortalType.CUSTOM; 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); super(what);
this.blocks = blocks; this.blocks = blocks;
this.type = type; this.type = type;
} }
@Override
public LivingEntity getEntity() {
return (LivingEntity) entity;
}
/** /**
* Gets a list of all blocks associated with the portal. * Gets a list of all blocks associated with the portal.
* *

Datei anzeigen

@ -1,7 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import java.util.List; import java.util.List;
import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,16 +13,21 @@ public class EntityDeathEvent extends EntityEvent {
private final List<ItemStack> drops; private final List<ItemStack> drops;
private int dropExp = 0; 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); 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); super(what);
this.drops = drops; this.drops = drops;
this.dropExp = droppedExp; this.dropExp = droppedExp;
} }
@Override
public LivingEntity getEntity() {
return (LivingEntity) entity;
}
/** /**
* Gets how much EXP should be dropped from this death. * Gets how much EXP should be dropped from this death.
* <p> * <p>

Datei anzeigen

@ -1,6 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.Event; import org.bukkit.event.Event;
/** /**
@ -18,7 +19,16 @@ public abstract class EntityEvent extends Event {
* *
* @return Entity who is involved in this event * @return Entity who is involved in this event
*/ */
public final Entity getEntity() { public Entity getEntity() {
return entity; 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();
}
} }

Datei anzeigen

@ -24,6 +24,11 @@ public class EntityShootBowEvent extends EntityEvent implements Cancellable {
this.force = force; 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 * Gets the bow ItemStack used to fire the arrow; is null if the shooter is a skeleton
* *

Datei anzeigen

@ -1,7 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -13,11 +13,16 @@ public class EntityTameEvent extends EntityEvent implements Cancellable {
private boolean cancelled; private boolean cancelled;
private final AnimalTamer owner; private final AnimalTamer owner;
public EntityTameEvent(final Entity entity, final AnimalTamer owner) { public EntityTameEvent(final LivingEntity entity, final AnimalTamer owner) {
super(entity); super(entity);
this.owner = owner; this.owner = owner;
} }
@Override
public LivingEntity getEntity() {
return (LivingEntity) entity;
}
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }

Datei anzeigen

@ -1,6 +1,6 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -12,14 +12,19 @@ public class FoodLevelChangeEvent extends EntityEvent implements Cancellable {
private boolean cancel = false; private boolean cancel = false;
private int level; private int level;
public FoodLevelChangeEvent(final Entity what, final int level) { public FoodLevelChangeEvent(final HumanEntity what, final int level) {
super(what); super(what);
this.level = level; 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. * 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. * Where 20 is a full food bar and 0 is an empty one.
* *
* @return The resultant food level * @return The resultant food level

Datei anzeigen

@ -1,7 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Item;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -10,8 +10,8 @@ public class ItemDespawnEvent extends EntityEvent implements Cancellable {
private boolean canceled; private boolean canceled;
private final Location location; private final Location location;
public ItemDespawnEvent(final Entity spawnee, final Location loc) { public ItemDespawnEvent(final Item despawnee, final Location loc) {
super(spawnee); super(despawnee);
location = loc; location = loc;
} }
@ -23,6 +23,11 @@ public class ItemDespawnEvent extends EntityEvent implements Cancellable {
canceled = cancel; canceled = cancel;
} }
@Override
public Item getEntity() {
return (Item) entity;
}
/** /**
* Gets the location at which the item is despawning. * Gets the location at which the item is despawning.
* *

Datei anzeigen

@ -1,6 +1,6 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Item;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -13,7 +13,7 @@ public class ItemSpawnEvent extends EntityEvent implements Cancellable {
private final Location location; private final Location location;
private boolean canceled; private boolean canceled;
public ItemSpawnEvent(final Entity spawnee, final Location loc) { public ItemSpawnEvent(final Item spawnee, final Location loc) {
super(spawnee); super(spawnee);
this.location = loc; this.location = loc;
} }
@ -26,6 +26,11 @@ public class ItemSpawnEvent extends EntityEvent implements Cancellable {
canceled = cancel; canceled = cancel;
} }
@Override
public Item getEntity() {
return (Item) entity;
}
/** /**
* Gets the location at which the item is spawning. * Gets the location at which the item is spawning.
* *

Datei anzeigen

@ -1,6 +1,8 @@
package org.bukkit.event.entity; 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.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -10,10 +12,10 @@ import org.bukkit.event.HandlerList;
public class PigZapEvent extends EntityEvent implements Cancellable { public class PigZapEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean canceled; private boolean canceled;
private final Entity pigzombie; private final PigZombie pigzombie;
private final Entity bolt; 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); super(pig);
this.bolt = bolt; this.bolt = bolt;
this.pigzombie = pigzombie; this.pigzombie = pigzombie;
@ -27,12 +29,17 @@ public class PigZapEvent extends EntityEvent implements Cancellable {
canceled = cancel; canceled = cancel;
} }
@Override
public Pig getEntity() {
return (Pig) entity;
}
/** /**
* Gets the bolt which is striking the pig. * Gets the bolt which is striking the pig.
* *
* @return lightning entity * @return lightning entity
*/ */
public Entity getLightning() { public LightningStrike getLightning() {
return bolt; return bolt;
} }
@ -42,7 +49,7 @@ public class PigZapEvent extends EntityEvent implements Cancellable {
* *
* @return resulting entity * @return resulting entity
*/ */
public Entity getPigZombie() { public PigZombie getPigZombie() {
return pigzombie; return pigzombie;
} }

Datei anzeigen

@ -31,6 +31,11 @@ public class PlayerDeathEvent extends EntityDeathEvent {
this.deathMessage = deathMessage; this.deathMessage = deathMessage;
} }
@Override
public Player getEntity() {
return (Player) entity;
}
/** /**
* Set the death message that will appear to everyone on the server. * Set the death message that will appear to everyone on the server.
* *

Datei anzeigen

@ -24,6 +24,11 @@ public class PotionSplashEvent extends ProjectileHitEvent implements Cancellable
this.affectedEntities = affectedEntities; this.affectedEntities = affectedEntities;
} }
@Override
public ThrownPotion getEntity() {
return (ThrownPotion) entity;
}
/** /**
* Gets the potion which caused this event * Gets the potion which caused this event
* *

Datei anzeigen

@ -13,6 +13,11 @@ public class ProjectileHitEvent extends EntityEvent {
super(projectile); super(projectile);
} }
@Override
public Projectile getEntity() {
return (Projectile) entity;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

Datei anzeigen

@ -1,7 +1,7 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.entity.Entity; import org.bukkit.entity.Sheep;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -13,8 +13,8 @@ public class SheepDyeWoolEvent extends EntityEvent implements Cancellable {
private boolean cancel; private boolean cancel;
private DyeColor color; private DyeColor color;
public SheepDyeWoolEvent(final Entity what, final DyeColor color) { public SheepDyeWoolEvent(final Sheep sheep, final DyeColor color) {
super(what); super(sheep);
this.cancel = false; this.cancel = false;
this.color = color; this.color = color;
} }
@ -27,6 +27,11 @@ public class SheepDyeWoolEvent extends EntityEvent implements Cancellable {
this.cancel = cancel; this.cancel = cancel;
} }
@Override
public Sheep getEntity() {
return (Sheep) entity;
}
/** /**
* Gets the DyeColor the sheep is being dyed * Gets the DyeColor the sheep is being dyed
* *

Datei anzeigen

@ -1,6 +1,6 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Sheep;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -11,8 +11,8 @@ public class SheepRegrowWoolEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancel; private boolean cancel;
public SheepRegrowWoolEvent(final Entity what) { public SheepRegrowWoolEvent(final Sheep sheep) {
super(what); super(sheep);
this.cancel = false; this.cancel = false;
} }
@ -24,6 +24,11 @@ public class SheepRegrowWoolEvent extends EntityEvent implements Cancellable {
this.cancel = cancel; this.cancel = cancel;
} }
@Override
public Sheep getEntity() {
return (Sheep) entity;
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

Datei anzeigen

@ -1,6 +1,6 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.entity.Entity; import org.bukkit.entity.Slime;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -9,12 +9,11 @@ import org.bukkit.event.HandlerList;
*/ */
public class SlimeSplitEvent extends EntityEvent implements Cancellable { public class SlimeSplitEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancel; private boolean cancel = false;
private int count; private int count;
public SlimeSplitEvent(final Entity what, final int count) { public SlimeSplitEvent(final Slime slime, final int count) {
super(what); super(slime);
this.cancel = false;
this.count = count; this.count = count;
} }
@ -26,6 +25,11 @@ public class SlimeSplitEvent extends EntityEvent implements Cancellable {
this.cancel = cancel; this.cancel = cancel;
} }
@Override
public Slime getEntity() {
return (Slime) entity;
}
/** /**
* Gets the amount of smaller slimes to spawn * Gets the amount of smaller slimes to spawn
* *