Renamed MobType->CreatureType and MobSpawner->CreatureSpawner.

This is to bring the names in line with the rest of bukkit.

Deprecated code has been left in to ensure nothing breaks as
a result of refactoring MobType.
This will be removed after 1 week, to give plugin devs time to
migrate

By: Andrew Ardill <andrew.ardill@gmail.com>
This commit is contained in:
Bukkit/Spigot 2011-02-17 14:19:57 +11:00
parent d3b62214a6
commit ca55cacd67
5 changed files with 125 additions and 5 deletions

View file

@ -0,0 +1,54 @@
package org.bukkit.block;
import org.bukkit.entity.CreatureType;
/**
* Represents a creature spawner.
*
* @author sk89q
* @author Cogito
*/
public interface CreatureSpawner extends BlockState {
/**
* Get the spawner's creature type.
*
* @return
*/
public CreatureType getCreatureType();
/**
* Set the spawner creature type.
*
* @param mobType
*/
public void setCreatureType(CreatureType creatureType);
/**
* Get the spawner's creature type.
*
* @return
*/
public String getCreatureTypeId();
/**
* Set the spawner mob type.
*
* @param creatureType
*/
public void setCreatureTypeId(String creatureType);
/**
* Get the spawner's delay.
*
* @return
*/
public int getDelay();
/**
* Set the spawner's delay.
*
* @param delay
*/
public void setDelay(int delay);
}

View file

@ -6,6 +6,8 @@ import org.bukkit.entity.MobType;
* Represents a mob spawner.
*
* @author sk89q
*
* @deprecated
*/
public interface MobSpawner extends BlockState {
/**

View file

@ -0,0 +1,42 @@
package org.bukkit.entity;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public enum CreatureType {
CHICKEN("Chicken"),
COW("Cow"),
CREEPER("Creeper"),
GHAST("Ghast"),
PIG("Pig"),
PIG_ZOMBIE("PigZombie"),
SHEEP("Sheep"),
SKELETON("Skeleton"),
SPIDER("Spider"),
ZOMBIE("Zombie"),
SQUID("Squid");
private String name;
private static final Map<String, CreatureType> mapping
= new HashMap<String, CreatureType>();
static {
for (CreatureType type : EnumSet.allOf(CreatureType.class)) {
mapping.put(type.name, type);
}
}
private CreatureType(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static CreatureType fromName(String name) {
return mapping.get(name);
}
}

View file

@ -3,7 +3,10 @@ package org.bukkit.entity;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* @deprecated Should be using CreatureType
*
*/
public enum MobType {
CHICKEN("Chicken"),
COW("Cow"),

View file

@ -1,5 +1,6 @@
package org.bukkit.event.player;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Egg;
import org.bukkit.entity.MobType;
import org.bukkit.entity.Player;
@ -13,10 +14,10 @@ import org.bukkit.entity.Player;
public class PlayerEggThrowEvent extends PlayerEvent {
private Egg egg;
private boolean hatching;
private MobType hatchType;
private CreatureType hatchType;
private byte numHatches;
public PlayerEggThrowEvent(Type type, Player player, Egg egg, boolean hatching, byte numHatches, MobType hatchType) {
public PlayerEggThrowEvent(Type type, Player player, Egg egg, boolean hatching, byte numHatches, CreatureType hatchType) {
super(type, player);
this.egg = egg;
this.hatching = hatching;
@ -24,6 +25,13 @@ public class PlayerEggThrowEvent extends PlayerEvent {
this.hatchType = hatchType;
}
public PlayerEggThrowEvent(Type type, Player player, Egg egg, boolean hatching, byte numHatches, MobType hatchType) {
super(type, player);
this.egg = egg;
this.hatching = hatching;
this.numHatches = numHatches;
this.hatchType = CreatureType.fromName(hatchType.getName());
}
/**
* Get the egg.
*
@ -59,7 +67,7 @@ public class PlayerEggThrowEvent extends PlayerEvent {
* @return The type of the mob being hatched by the egg
*/
public MobType getHatchType() {
return hatchType;
return MobType.fromName(hatchType.getName());
}
/**
@ -67,10 +75,21 @@ public class PlayerEggThrowEvent extends PlayerEvent {
*
* @param hatchType The type of the mob being hatched by the egg
*/
public void setHatchType(MobType hatchType) {
public void setHatchType(CreatureType hatchType) {
this.hatchType = hatchType;
}
/**
* Change the type of mob being hatched by the egg
*
* @param hatchType The type of the mob being hatched by the egg
*
* @deprecated
*/
public void setHatchType(MobType hatchType) {
this.hatchType = CreatureType.fromName(hatchType.getName());
}
/**
* Get the number of mob hatches from the egg. By default the number
* will be he number the server would've done