Add leash API. Adds BUKKIT-4459 and BUKKIT-4583

By: T00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
Bukkit/Spigot
2013-07-30 15:40:12 -04:00
parent 47d09288b4
commit fcde9e65af
6 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package org.bukkit.event.entity;
import org.bukkit.entity.Entity;
import org.bukkit.event.HandlerList;
/**
* Called immediately prior to an entity being unleashed.
*/
public class EntityUnleashEvent extends EntityEvent {
private static final HandlerList handlers = new HandlerList();
private final UnleashReason reason;
public EntityUnleashEvent(Entity entity, UnleashReason reason) {
super(entity);
this.reason = reason;
}
/**
* Returns the reason for the unleashing.
*
* @return The reason
*/
public UnleashReason getReason() {
return reason;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public enum UnleashReason {
/**
* When the entity's leashholder has died or logged out, and so is
* unleashed
*/
HOLDER_GONE,
/**
* When the entity's leashholder attempts to unleash it
*/
PLAYER_UNLEASH,
/**
* When the entity's leashholder is more than 10 blocks away
*/
DISTANCE,
UNKNOWN;
}
}

View File

@@ -0,0 +1,68 @@
package org.bukkit.event.entity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* Called immediately prior to a creature being leashed by a player.
*/
public class PlayerLeashEntityEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Entity leashHolder;
private final Entity entity;
private boolean cancelled = false;
private final Player player;
public PlayerLeashEntityEvent(Entity what, Entity leashHolder, Player leasher) {
this.leashHolder = leashHolder;
this.entity = what;
this.player = leasher;
}
/**
* Returns the entity that is holding the leash.
*
* @return The leash holder
*/
public Entity getLeashHolder() {
return leashHolder;
}
/**
* Returns the entity being leashed.
*
* @return The entity
*/
public Entity getEntity() {
return entity;
}
/**
* Returns the player involved in this event
*
* @return Player who is involved in this event
*/
public final Player getPlayer() {
return player;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
public boolean isCancelled() {
return this.cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View File

@@ -0,0 +1,36 @@
package org.bukkit.event.player;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.entity.EntityUnleashEvent;
/**
* Called prior to an entity being unleashed due to a player's action.
*/
public class PlayerUnleashEntityEvent extends EntityUnleashEvent implements Cancellable {
private final Player player;
private boolean cancelled = false;
public PlayerUnleashEntityEvent(Entity entity, Player player) {
super(entity, UnleashReason.PLAYER_UNLEASH);
this.player = player;
}
/**
* Returns the player who is unleashing the entity.
*
* @return The player
*/
public Player getPlayer() {
return player;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}