From 7e5c1baee90913211c267ffc87fb94707919ae41 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 21 Jan 2012 21:20:49 -0500 Subject: [PATCH] [Bleeding] Added Sheep, Shear and EntityChangeBlock API. Thanks tips48! Closes BUKKIT-512 By: Aidan Matzko --- .../main/java/org/bukkit/entity/Sheep.java | 2 - .../src/main/java/org/bukkit/event/Event.java | 26 ++++++++ .../event/entity/EntityChangeBlockEvent.java | 62 +++++++++++++++++++ .../event/entity/SheepDyeWoolEvent.java | 58 +++++++++++++++++ .../event/entity/SheepRegrowWoolEvent.java | 37 +++++++++++ .../event/player/PlayerShearEntityEvent.java | 49 +++++++++++++++ 6 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java diff --git a/paper-api/src/main/java/org/bukkit/entity/Sheep.java b/paper-api/src/main/java/org/bukkit/entity/Sheep.java index b62911aa0c..f4ce312ccd 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Sheep.java +++ b/paper-api/src/main/java/org/bukkit/entity/Sheep.java @@ -8,13 +8,11 @@ import org.bukkit.material.Colorable; public interface Sheep extends Animals, Colorable { /** - * @author Celtic Minstrel * @return Whether the sheep is sheared. */ public boolean isSheared(); /** - * @author Celtic Minstrel * @param flag Whether to shear the sheep */ public void setSheared(boolean flag); diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index 0658e003f8..af614c410e 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -375,6 +375,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.player.PlayerExpChangeEvent */ PLAYER_EXP_CHANGE(Category.PLAYER, PlayerExpChangeEvent.class), + /** + * Called when a player shears an entity + * + * @see org.bukkit.event.player.PlayerShearEntityEvent + */ + PLAYER_SHEAR_ENTITY(Category.LIVING_ENTITY, PlayerShearEntityEvent.class), /** * BLOCK EVENTS @@ -738,6 +744,18 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.EntityTargetEvent */ ENTITY_TARGET(Category.LIVING_ENTITY, EntityTargetEvent.class), + /** + * Called when a sheep regrows its wool + * + * @see org.bukkit.event.entity.SheepRegrowWoolEvent + */ + SHEEP_REGROW_WOOL(Category.LIVING_ENTITY, SheepRegrowWoolEvent.class), + /** + * Called when a sheep's wool is dyed + * + * @see org.bukkit.event.entity.SheepDyeWoolEvent + */ + SHEEP_DYE_WOOL(Category.LIVING_ENTITY, SheepDyeWoolEvent.class), /** * Called when an entity interacts with a block * This event specifically excludes player entities @@ -763,6 +781,14 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.EntityTameEvent */ ENTITY_TAME(Category.LIVING_ENTITY, EntityTameEvent.class), + /** + * Called when a LivingEntity changes a block + * + * This event specifically excludes player entities + * + * @see org.bukkit.event.entity.EntityChangeBlockEvent + */ + ENTITY_CHANGE_BLOCK(Category.LIVING_ENTITY, EntityChangeBlockEvent.class), /** * Called when a {@link Projectile} hits something * diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java new file mode 100644 index 0000000000..30790750d2 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java @@ -0,0 +1,62 @@ +package org.bukkit.event.entity; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +@SuppressWarnings("serial") +/** + * Called when a LivingEntity changes a block + * + * This event specifically excludes player entities + */ +public class EntityChangeBlockEvent extends EntityEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private Block block; + private boolean cancel; + private Material to; + + public EntityChangeBlockEvent(Entity what, Block block, Material to) { + super(Type.ENTITY_CHANGE_BLOCK, what); + this.block = block; + this.cancel = false; + this.to = to; + } + + /** + * Gets the block the entity is changing + * + * @return the block that is changing + */ + public Block getBlock() { + return block; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the Material that the block is changing into + * + * @return the material that the block is changing into + */ + public Material getTo() { + return to; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java new file mode 100644 index 0000000000..b69175ae30 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/SheepDyeWoolEvent.java @@ -0,0 +1,58 @@ +package org.bukkit.event.entity; + +import org.bukkit.DyeColor; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +@SuppressWarnings("serial") +/** + * Called when a sheep's wool is dyed + */ +public class SheepDyeWoolEvent extends EntityEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancel; + private DyeColor color; + + public SheepDyeWoolEvent(Entity what, DyeColor color) { + super(Type.SHEEP_DYE_WOOL, what); + this.cancel = false; + this.color = color; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the DyeColor the sheep is being dyed + * + * @return the DyeColor the sheep is being dyed + */ + public DyeColor getColor() { + return color; + } + + /** + * Sets the DyeColor the sheep is being dyed + * + * @param color the DyeColor the sheep will be dyed + */ + public void setColor(DyeColor color) { + this.color = color; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java new file mode 100644 index 0000000000..73ef7faba5 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/SheepRegrowWoolEvent.java @@ -0,0 +1,37 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +@SuppressWarnings("serial") +/** + * Called when a sheep regrows its wool + */ +public class SheepRegrowWoolEvent extends EntityEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancel; + + public SheepRegrowWoolEvent(Entity what) { + super(Type.SHEEP_REGROW_WOOL, what); + this.cancel = false; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java new file mode 100644 index 0000000000..8fb73f782e --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java @@ -0,0 +1,49 @@ +package org.bukkit.event.player; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +@SuppressWarnings("serial") +/** + * Called when a player shears an entity + */ +public class PlayerShearEntityEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean cancel; + private Entity what; + + public PlayerShearEntityEvent(Player who, Entity what) { + super(Type.PLAYER_SHEAR_ENTITY, who); + this.cancel = false; + this.what = what; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the entity the player is shearing + * + * @return the entity the player is shearing + */ + public Entity getEntity() { + return what; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + +}