Merge branch 'master' of https://github.com/tkelly910/Bukkit into tkelly910-master

By: Taylor Kelly <tkelly910@gmail.com>
This commit is contained in:
Bukkit/Spigot 2011-01-11 18:53:54 -05:00
commit 6260932a36
6 changed files with 227 additions and 96 deletions

View File

@ -0,0 +1,25 @@
package org.bukkit;
public enum MobType {
CHICKEN("Chicken"),
COW("Cow"),
CREEPER("Creeper"),
GHAST("Ghast"),
PIG("Pig"),
PIG_ZOMBIE("PigZombie"),
SHEEP("Sheep"),
SKELETON("Skeleton"),
SPIDER("Spider"),
ZOMBIE("Zombie");
private String name;
private MobType(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -193,6 +193,13 @@ public abstract class Event {
*/
PLAYER_ITEM (Category.PLAYER),
/**
* Called when a player throws an egg and it might hatch
*
* @see org.bukkit.event.player.PlayerEggThrowEvent
*/
PLAYER_EGG_THROW (Category.PLAYER),
/**
* Called when a player teleports from one position to another
*
@ -206,7 +213,8 @@ public abstract class Event {
/**
* Called when a block is damaged (hit by a player)
* @todo: Add Javadoc see note here.
*
* @see org.bukkit.event.block.BlockDamagedEvent
*/
BLOCK_DAMAGED (Category.BLOCK),

View File

@ -0,0 +1,87 @@
package org.bukkit.event.player;
import org.bukkit.MobType;
import org.bukkit.Player;
/**
*
* @author tkelly
*
*/
public class PlayerEggThrowEvent extends PlayerEvent {
private boolean hatching;
private MobType hatchType;
private byte numHatches;
public PlayerEggThrowEvent(Type type, Player player, boolean hatching, byte numHatches, MobType hatchType) {
super(type, player);
this.hatching = hatching;
this.numHatches = numHatches;
this.hatchType = hatchType;
}
/**
* Grabs whether the egg is hatching or not. Will be what the server
* would've done without interaction.
*
* @return boolean Whether the egg is going to hatch or not
*/
public boolean isHatching() {
return hatching;
}
/**
* Sets whether the egg will hatch.
*
* @param hatching true if you want the egg to hatch
* false if you want it not to
*/
public void setHatching(boolean hatching) {
this.hatching = hatching;
}
/**
* Get the type of the mob being hatched (MobType.CHICKEN by default)
*
* @return The type of the mob being hatched by the egg
*/
public MobType getHatchType() {
return hatchType;
}
/**
* Change the type of mob being hatched by the egg
*
* @param hatchType The type of the mob being hatched by the egg
*/
public void setHatchType(MobType hatchType) {
this.hatchType = hatchType;
}
/**
* Get the number of mob hatches from the egg. By default the number
* will be he number the server would've done
*
* 7/8 chance of being 0
* 31/256 ~= 1/8 chance to be 1
* 1/256 chance to be 4
*
* @return The number of mobs going to be hatched by the egg
*/
public byte getNumHatches() {
return numHatches;
}
/**
* Change the number of mobs coming out of the hatched egg
*
* The boolean hatching will override this number.
* Ie. If hatching = false, this number will not matter
*
* @param numHatches The number of mobs coming out of the egg
*/
public void setNumHatches(byte numHatches) {
this.numHatches = numHatches;
}
}

View File

@ -73,4 +73,12 @@ public class PlayerListener implements Listener {
*/
public void onPlayerLogin(PlayerLoginEvent event) {
}
/**
* Called when a player throws an egg and it might hatch
*
* @param event Relevant event details
*/
public void onPlayerEggThrow(PlayerEggThrowEvent event) {
}
}

View File

@ -126,6 +126,9 @@ public final class JavaPluginLoader implements PluginLoader {
case PLAYER_LOGIN:
trueListener.onPlayerLogin((PlayerLoginEvent)event);
break;
case PLAYER_EGG_THROW:
trueListener.onPlayerEggThrow((PlayerEggThrowEvent)event);
break;
}
} else if (listener instanceof BlockListener) {
BlockListener trueListener = (BlockListener)listener;