diff options
author | md_5 <git@md-5.net> | 2016-03-03 19:20:28 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-03-04 15:23:14 +1100 |
commit | 325dae0d06bbce001d246884b3724f8df3d0eb65 (patch) | |
tree | 9fd6cbe2d355e8cb32ae43c5ce791182dd78acba /src | |
parent | e0f09419b372afc2149b071ada8345c194848e85 (diff) | |
download | bukkit-325dae0d06bbce001d246884b3724f8df3d0eb65.tar bukkit-325dae0d06bbce001d246884b3724f8df3d0eb65.tar.gz bukkit-325dae0d06bbce001d246884b3724f8df3d0eb65.tar.lz bukkit-325dae0d06bbce001d246884b3724f8df3d0eb65.tar.xz bukkit-325dae0d06bbce001d246884b3724f8df3d0eb65.zip |
SPIGOT-1608: Add a way to get the hand used in PlayerInteract*Events
Diffstat (limited to 'src')
3 files changed, 40 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/event/player/PlayerInteractAtEntityEvent.java b/src/main/java/org/bukkit/event/player/PlayerInteractAtEntityEvent.java index 3293b115..15f9624a 100644 --- a/src/main/java/org/bukkit/event/player/PlayerInteractAtEntityEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerInteractAtEntityEvent.java @@ -3,6 +3,7 @@ package org.bukkit.event.player; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.util.Vector; /** @@ -14,10 +15,14 @@ public class PlayerInteractAtEntityEvent extends PlayerInteractEntityEvent { private final Vector position; public PlayerInteractAtEntityEvent(Player who, Entity clickedEntity, Vector position) { - super(who, clickedEntity); + this(who, clickedEntity, position, EquipmentSlot.HAND); + } + + public PlayerInteractAtEntityEvent(Player who, Entity clickedEntity, Vector position, EquipmentSlot hand) { + super(who, clickedEntity, hand); this.position = position; } - + public Vector getClickedPosition() { return position.clone(); } diff --git a/src/main/java/org/bukkit/event/player/PlayerInteractEntityEvent.java b/src/main/java/org/bukkit/event/player/PlayerInteractEntityEvent.java index 935211df..94609579 100644 --- a/src/main/java/org/bukkit/event/player/PlayerInteractEntityEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerInteractEntityEvent.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.EquipmentSlot; /** * Represents an event that is called when a player right clicks an entity. @@ -12,10 +13,16 @@ public class PlayerInteractEntityEvent extends PlayerEvent implements Cancellabl private static final HandlerList handlers = new HandlerList(); protected Entity clickedEntity; boolean cancelled = false; + private EquipmentSlot hand; public PlayerInteractEntityEvent(final Player who, final Entity clickedEntity) { + this(who, clickedEntity, EquipmentSlot.HAND); + } + + public PlayerInteractEntityEvent(final Player who, final Entity clickedEntity, final EquipmentSlot hand) { super(who); this.clickedEntity = clickedEntity; + this.hand = hand; } public boolean isCancelled() { @@ -35,6 +42,15 @@ public class PlayerInteractEntityEvent extends PlayerEvent implements Cancellabl return this.clickedEntity; } + /** + * The hand used to perform this interaction. + * + * @return the hand used to interact + */ + public EquipmentSlot getHand() { + return hand; + } + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java b/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java index b12382f4..818b4813 100644 --- a/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java @@ -8,6 +8,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.block.Action; +import org.bukkit.inventory.EquipmentSlot; /** * Called when a player interacts with an object or air. @@ -23,13 +24,19 @@ public class PlayerInteractEvent extends PlayerEvent implements Cancellable { protected BlockFace blockFace; private Result useClickedBlock; private Result useItemInHand; + private EquipmentSlot hand; public PlayerInteractEvent(final Player who, final Action action, final ItemStack item, final Block clickedBlock, final BlockFace clickedFace) { + this(who, action, item, clickedBlock, clickedFace, EquipmentSlot.HAND); + } + + public PlayerInteractEvent(final Player who, final Action action, final ItemStack item, final Block clickedBlock, final BlockFace clickedFace, final EquipmentSlot hand) { super(who); this.action = action; this.item = item; this.blockClicked = clickedBlock; this.blockFace = clickedFace; + this.hand = hand; useItemInHand = Result.DEFAULT; useClickedBlock = clickedBlock == null ? Result.DENY : Result.ALLOW; @@ -179,6 +186,16 @@ public class PlayerInteractEvent extends PlayerEvent implements Cancellable { this.useItemInHand = useItemInHand; } + /** + * The hand used to perform this interaction. May be null in the case of + * {@link Action#PHYSICAL}. + * + * @return the hand used to interact. May be null. + */ + public EquipmentSlot getHand() { + return hand; + } + @Override public HandlerList getHandlers() { return handlers; |