Added PlayerInteractEntityEvent which fires when a player right clicks an entity. Thanks fullwall!

By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
Bukkit/Spigot 2011-05-02 04:30:10 -04:00
parent 33d8037626
commit 03ff88b71d
4 changed files with 68 additions and 0 deletions

View File

@ -232,6 +232,13 @@ public abstract class Event implements Serializable {
*/
PLAYER_INTERACT (Category.PLAYER),
/**
* Called when a player right clicks an entity
*
* @see org.bukkit.event.player.PlayerInteractEntityEvent
*/
PLAYER_INTERACT_ENTITY (Category.PLAYER),
/**
* Called when a player throws an egg and it might hatch
*

View File

@ -0,0 +1,47 @@
package org.bukkit.event.player;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
/**
* Represents an event that is called when a player right clicks an entity.
*/
public class PlayerInteractEntityEvent extends PlayerEvent implements Cancellable {
protected Entity clickedEntity;
boolean cancelled = false;
public PlayerInteractEntityEvent(Player who, Entity clickedEntity) {
super(Type.PLAYER_INTERACT_ENTITY, who);
this.clickedEntity = clickedEntity;
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancelled;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins.
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
/**
* Gets the entity that was rightclicked by the player.
*
* @return entity right clicked by player
*/
public Entity getRightClicked() {
return this.clickedEntity;
}
}

View File

@ -92,6 +92,14 @@ public class PlayerListener implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) {
}
/**
* Called when a player right clicks an entity.
*
* @param event Relevant event details
*/
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
}
/**
* Called when a player attempts to log in to the server
*

View File

@ -280,6 +280,12 @@ public final class JavaPluginLoader implements PluginLoader {
((PlayerListener) listener).onPlayerInteract((PlayerInteractEvent) event);
}
};
case PLAYER_INTERACT_ENTITY:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((PlayerListener) listener).onPlayerInteractEntity((PlayerInteractEntityEvent) event);
}
};
case PLAYER_LOGIN:
return new EventExecutor() {
public void execute(Listener listener, Event event) {