Skip to content

Commit

Permalink
Added PlayerInteractEntityEvent which fires when a player right click…
Browse files Browse the repository at this point in the history
…s an entity. Thanks fullwall!
  • Loading branch information
EvilSeph committed May 2, 2011
1 parent 5c4f940 commit 4e3d770
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/bukkit/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ public enum Type {
*/
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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/bukkit/event/player/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
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
*
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ public void execute(Listener listener, Event event) {
((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) {
Expand Down

0 comments on commit 4e3d770

Please sign in to comment.