From 10d7e607c85931d29486d03db5bca9b40bae6af8 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Thu, 9 Jun 2011 03:57:50 -0400 Subject: [PATCH] Added EntityTame event. Thanks halvors! By: EvilSeph --- .../src/main/java/org/bukkit/event/Event.java | 6 +++ .../bukkit/event/entity/EntityListener.java | 2 + .../bukkit/event/entity/EntityTameEvent.java | 49 +++++++++++++++++++ .../bukkit/plugin/java/JavaPluginLoader.java | 7 +++ 4 files changed, 64 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/entity/EntityTameEvent.java 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 0bf2ab4c09..f3f918493b 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -592,6 +592,12 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.entity.PigZapEvent */ PIG_ZAP (Category.LIVING_ENTITY), + /** + * Called when a LivingEntity is tamed + * + * @see org.bukkit.event.entity.EntityTameEvent + */ + ENTITY_TAME (Category.LIVING_ENTITY), /** * WEATHER EVENTS diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java index c820c2f9d1..ac4976395b 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -35,4 +35,6 @@ public class EntityListener implements Listener { public void onPigZap(PigZapEvent event) {} public void onCreeperPower(CreeperPowerEvent event) {} + + public void onEntityTame(EntityTameEvent event) {} } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityTameEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityTameEvent.java new file mode 100644 index 0000000000..6e8e954900 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityTameEvent.java @@ -0,0 +1,49 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.AnimalTamer; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * Thrown when a LivingEntity is tamed + */ +public class EntityTameEvent extends EntityEvent implements Cancellable { + private boolean cancelled; + private AnimalTamer owner; + + public EntityTameEvent(Entity entity, AnimalTamer owner) { + super(Type.ENTITY_TAME, entity); + this.owner = owner; + } + + /** + * Gets the cancellation state of this event. Set to true if you + * want to prevent the entity from being tamed + * + * @return boolean cancellation state + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * Sets the cancellation state of this event. A canceled event will not + * be executed in the server, but will still pass to other plugins + * + * Canceling this event will prevent the entity from being tamed + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + /** + * Gets the owning AnimalTamer + * + * @return the owning AnimalTamer + */ + public AnimalTamer getOwner() { + return owner; + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 023222221c..0fce84753e 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -669,6 +669,13 @@ public final class JavaPluginLoader implements PluginLoader { } }; + case ENTITY_TAME: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((EntityListener) listener).onEntityTame((EntityTameEvent) event); + } + }; + // Vehicle Events case VEHICLE_CREATE: return new EventExecutor() {