[Bleeding] Added EntityType to replace CreatureType.

By: Celtic Minstrel <celtic.minstrel.ca@some.place>
This commit is contained in:
Bukkit/Spigot
2012-02-14 23:52:38 -05:00
parent c6050ff89d
commit 6e054ddf7f
8 changed files with 261 additions and 16 deletions

View File

@@ -1,8 +1,10 @@
package org.bukkit.event.entity;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -13,18 +15,20 @@ import org.bukkit.event.HandlerList;
*/
public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Location location;
private boolean canceled;
private final CreatureType creatureType;
private final SpawnReason spawnReason;
public CreatureSpawnEvent(final Entity spawnee, final CreatureType mobtype, final Location loc, final SpawnReason spawnReason) {
public CreatureSpawnEvent(final LivingEntity spawnee, final SpawnReason spawnReason) {
super(spawnee);
this.creatureType = mobtype;
this.location = loc;
this.spawnReason = spawnReason;
}
@Deprecated
public CreatureSpawnEvent(Entity spawnee, CreatureType type, Location loc, SpawnReason reason) {
super(spawnee);
spawnReason = reason;
}
public boolean isCancelled() {
return canceled;
}
@@ -39,7 +43,18 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
* @return The location at which the creature is spawning
*/
public Location getLocation() {
return location;
return getEntity().getLocation();
}
/**
* Gets the type of creature being spawned.
*
* @return A CreatureType value detailing the type of creature being spawned
* @deprecated In favour of {@link #getSpawnedType()}.
*/
@Deprecated
public CreatureType getCreatureType() {
return CreatureType.fromEntityType(getSpawnedType());
}
/**
@@ -47,8 +62,8 @@ public class CreatureSpawnEvent extends EntityEvent implements Cancellable {
*
* @return A CreatureType value detailing the type of creature being spawned
*/
public CreatureType getCreatureType() {
return creatureType;
public EntityType getSpawnedType() {
return getEntity().getType();
}
/**

View File

@@ -2,6 +2,7 @@ package org.bukkit.event.player;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
@@ -12,15 +13,20 @@ public class PlayerEggThrowEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private final Egg egg;
private boolean hatching;
private CreatureType hatchType;
private EntityType hatchType;
private byte numHatches;
public PlayerEggThrowEvent(final Player player, final Egg egg, final boolean hatching, final byte numHatches, final CreatureType hatchType) {
public PlayerEggThrowEvent(final Player player, final Egg egg, final boolean hatching, final byte numHatches, final EntityType hatchingType) {
super(player);
this.egg = egg;
this.hatching = hatching;
this.numHatches = numHatches;
this.hatchType = hatchType;
this.hatchType = hatchingType;
}
@Deprecated
public PlayerEggThrowEvent(Player player, Egg egg, boolean hatching, byte numHatches, CreatureType hatchingType) {
this(player, egg, hatching, numHatches, hatchingType.toEntityType());
}
/**
@@ -53,12 +59,34 @@ public class PlayerEggThrowEvent extends PlayerEvent {
}
/**
* Get the type of the mob being hatched (CreatureType.CHICKEN by default)
* Get the type of the mob being hatched (EntityType.CHICKEN by default)
*
* @return The type of the mob being hatched by the egg
* @deprecated In favour of {@link #getHatchingType()}.
*/
@Deprecated
public CreatureType getHatchType() {
return CreatureType.fromEntityType(hatchType);
}
/**
* Get the type of the mob being hatched (EntityType.CHICKEN by default)
*
* @return The type of the mob being hatched by the egg
*/
public CreatureType getHatchType() {
return CreatureType.fromName(hatchType.getName());
public EntityType getHatchingType() {
return hatchType;
}
/**
* Change the type of mob being hatched by the egg
*
* @param hatchType The type of the mob being hatched by the egg
* @deprecated In favour of {@link #setHatchingType(EntityType)}.
*/
@Deprecated
public void setHatchType(CreatureType hatchType) {
this.hatchType = hatchType.toEntityType();
}
/**
@@ -66,7 +94,8 @@ public class PlayerEggThrowEvent extends PlayerEvent {
*
* @param hatchType The type of the mob being hatched by the egg
*/
public void setHatchType(CreatureType hatchType) {
public void setHatchingType(EntityType hatchType) {
if(!hatchType.isSpawnable()) throw new IllegalArgumentException("Can't spawn that entity type from an egg!");
this.hatchType = hatchType;
}