summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErik Broes <erikbroes@ripe.net>2011-03-23 12:30:54 +0100
committerErik Broes <erikbroes@grum.nl>2011-03-23 16:58:43 +0100
commit700c8a20ddfdafa98767ff587a0692e4449f16ff (patch)
tree62a75a0fc4abce727a932a25562230c0a2c3587d /src
parentf0544a90fcf8cdb72d9b48974a5df5cffeb86a58 (diff)
downloadbukkit-700c8a20ddfdafa98767ff587a0692e4449f16ff.tar
bukkit-700c8a20ddfdafa98767ff587a0692e4449f16ff.tar.gz
bukkit-700c8a20ddfdafa98767ff587a0692e4449f16ff.tar.lz
bukkit-700c8a20ddfdafa98767ff587a0692e4449f16ff.tar.xz
bukkit-700c8a20ddfdafa98767ff587a0692e4449f16ff.zip
Add PLAYER_INTERACT, remove BLOCK_RIGHT_CLICK, BLOCK_INTERACT and PLAYER_ITEM
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/event/Event.java38
-rw-r--r--src/main/java/org/bukkit/event/block/Action.java24
-rw-r--r--src/main/java/org/bukkit/event/block/BlockListener.java16
-rw-r--r--src/main/java/org/bukkit/event/player/PlayerInteractEvent.java171
-rw-r--r--src/main/java/org/bukkit/event/player/PlayerListener.java4
-rw-r--r--src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java14
6 files changed, 222 insertions, 45 deletions
diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java
index ea703032..cf636ce0 100644
--- a/src/main/java/org/bukkit/event/Event.java
+++ b/src/main/java/org/bukkit/event/Event.java
@@ -213,7 +213,7 @@ public abstract class Event implements Serializable {
*
* @see org.bukkit.event.player.PlayerItemEvent
*/
- PLAYER_ITEM (Category.PLAYER),
+ PLAYER_INTERACT (Category.PLAYER),
/**
* Called when a player throws an egg and it might hatch
@@ -314,25 +314,11 @@ public abstract class Event implements Serializable {
/**
* Called when a player is attempting to place a block
*
- * @see org.bukkit.event.block.BlockRightClickEvent
- */
- BLOCK_RIGHTCLICK (Category.BLOCK),
-
- /**
- * Called when a player is attempting to place a block
- *
* @see org.bukkit.event.block.BlockPlaceEvent
*/
BLOCK_PLACE (Category.BLOCK),
/**
- * Called when an entity interacts with a block (lever, door, pressure plate, chest, furnace)
- *
- * @see org.bukkit.event.block.BlockInteractEvent
- */
- BLOCK_INTERACT (Category.BLOCK),
-
- /**
* Called when a block is destroyed from being burnt by fire
*
* @see org.bukkit.event.block.BlockBurnEvent
@@ -624,4 +610,26 @@ public abstract class Event implements Serializable {
return category;
}
}
+
+ public enum Result {
+ /**
+ * Deny the event.
+ * Depending on the event, the action indicated by the event will either not take place or will be reverted.
+ * Some actions may not be denied.
+ */
+ DENY,
+
+ /**
+ * Neither deny nor allow the event.
+ * The server will proceed with its normal handling.
+ */
+ DEFAULT,
+
+ /**
+ * Allow / Force the event.
+ * The action indicated by the event will take place if possible, even if the server would not normally allow the action.
+ * Some actions may not be allowed.
+ */
+ ALLOW;
+ }
}
diff --git a/src/main/java/org/bukkit/event/block/Action.java b/src/main/java/org/bukkit/event/block/Action.java
new file mode 100644
index 00000000..097cd800
--- /dev/null
+++ b/src/main/java/org/bukkit/event/block/Action.java
@@ -0,0 +1,24 @@
+package org.bukkit.event.block;
+
+public enum Action {
+ /**
+ * Left-clicking a block
+ */
+ LEFT_CLICK_BLOCK,
+ /**
+ * Right-clicking a block
+ */
+ RIGHT_CLICK_BLOCK,
+ /**
+ * Left-clicking the air
+ */
+ LEFT_CLICK_AIR,
+ /**
+ * Right-clicking the air
+ */
+ RIGHT_CLICK_AIR,
+ /**
+ * Ass-pressure
+ */
+ PHYSICAL,
+}
diff --git a/src/main/java/org/bukkit/event/block/BlockListener.java b/src/main/java/org/bukkit/event/block/BlockListener.java
index 7cf893c9..39c7bc2e 100644
--- a/src/main/java/org/bukkit/event/block/BlockListener.java
+++ b/src/main/java/org/bukkit/event/block/BlockListener.java
@@ -61,22 +61,6 @@ public class BlockListener implements Listener {
}
/**
- * Called when a block is interacted with
- *
- * @param event Relevant event details
- */
- public void onBlockInteract(BlockInteractEvent event) {
- }
-
- /**
- * Called when a player right clicks a block
- *
- * @param event Relevant event details
- */
- public void onBlockRightClick(BlockRightClickEvent event) {
- }
-
- /**
* Called when redstone changes
* From: the source of the redstone change
* To: The redstone dust that changed
diff --git a/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java b/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java
new file mode 100644
index 00000000..4f06f4d7
--- /dev/null
+++ b/src/main/java/org/bukkit/event/player/PlayerInteractEvent.java
@@ -0,0 +1,171 @@
+package org.bukkit.event.player;
+
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.Event.Result;
+import org.bukkit.event.block.Action;
+
+/**
+ *
+ * @author durron597
+ *
+ */
+public class PlayerInteractEvent extends PlayerEvent implements Cancellable {
+ protected ItemStack item;
+ protected Action action;
+ protected Block blockClicked;
+ protected BlockFace blockFace;
+
+ private Result useClickedBlock;
+ private Result useItemInHand;
+
+ public PlayerInteractEvent(Player who, Action action, ItemStack item, Block clickedBlock, BlockFace clickedFace) {
+ super(Type.PLAYER_INTERACT, who);
+ this.action = action;
+ this.item = item;
+ this.blockClicked = clickedBlock;
+ this.blockFace = clickedFace;
+
+ useItemInHand = item == null ? Result.DENY : Result.ALLOW;
+ useClickedBlock = clickedBlock == null ? Result.DENY : Result.ALLOW;
+ }
+
+ /**
+ * Returns the action type
+ *
+ * @return Action returns the type of interaction
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * Gets the cancellation state of this event. Set to true if you
+ * want to prevent buckets from placing water and so forth
+ *
+ * @return boolean cancellation state
+ */
+ public boolean isCancelled() {
+ return useInteractedBlock() == Result.DENY;
+ }
+
+ /**
+ * 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 use of food (player won't lose the
+ * food item), prevent bows/snowballs/eggs from firing, etc. (player won't
+ * lose the ammo)
+ *
+ * @param cancel true if you wish to cancel this event
+ */
+ public void setCancelled(boolean cancel) {
+ setUseInteractedBlock(cancel ? Result.DENY : useInteractedBlock() == Result.DENY ? Result.DEFAULT : useInteractedBlock());
+ }
+
+ /**
+ * Returns the item in hand represented by this event
+ *
+ * @return ItemStack the item used
+ */
+ public ItemStack getItem() {
+ return this.item;
+ }
+
+ /**
+ * Convenience method. Returns the material of the item represented by this
+ * event
+ *
+ * @return Material the material of the item used
+ */
+ public Material getMaterial() {
+ if (!hasItem()) return Material.AIR;
+
+ return item.getType();
+ }
+
+ /**
+ * Check if this event involved a block
+ *
+ * return boolean true if it did
+ */
+ public boolean hasBlock() {
+ return this.blockClicked != null;
+ }
+
+ /**
+ * Check if this event involved an item
+ *
+ * return boolean true if it did
+ */
+ public boolean hasItem() {
+ return this.item != null;
+ }
+
+ /**
+ * Convenience method to inform the user whether this was a block placement
+ * event.
+ *
+ * @return boolean true if the item in hand was a block
+ */
+ public boolean isBlockInHand() {
+ if (!hasItem()) return false;
+
+ return item.getType().isBlock();
+ }
+
+ /**
+ * Returns the clicked block
+ *
+ * @return Block returns the block clicked with this item.
+ */
+ public Block getClickedBlock() {
+ return blockClicked;
+ }
+
+ /**
+ * Returns the face of the block that was clicked
+ *
+ * @return BlockFace returns the face of the block that was clicked
+ */
+ public BlockFace getBlockFace() {
+ return blockFace;
+ }
+
+ /**
+ * This controls the action to take with the block (if any) that was clicked on
+ * This event gets processed for all blocks, but most don't have a default action
+ * @return the action to take with the interacted block
+ */
+ public Result useInteractedBlock() {
+ return useClickedBlock;
+ }
+
+ /**
+ * @param useInteractedBlock the action to take with the interacted block
+ */
+ public void setUseInteractedBlock(Result useInteractedBlock) {
+ this.useClickedBlock = useInteractedBlock;
+ }
+
+ /**
+ * This controls the action to take with the item the player is holding
+ * This includes both blocks and items (such as flint and steel or records)
+ * When this is set to default, it will be allowed if no action is taken on the interacted block
+ * @return the action to take with the item in hand
+ */
+ public Result useItemInHand() {
+ return useItemInHand;
+ }
+
+ /**
+ * @param useItemInHand the action to take with the item in hand
+ */
+ public void setUseItemInHand(Result useItemInHand) {
+ this.useItemInHand = useItemInHand;
+ }
+}
diff --git a/src/main/java/org/bukkit/event/player/PlayerListener.java b/src/main/java/org/bukkit/event/player/PlayerListener.java
index bc18d131..0c817c1d 100644
--- a/src/main/java/org/bukkit/event/player/PlayerListener.java
+++ b/src/main/java/org/bukkit/event/player/PlayerListener.java
@@ -76,11 +76,11 @@ public class PlayerListener implements Listener {
}
/**
- * Called when a player uses an item
+ * Called when a player interacts
*
* @param event Relevant event details
*/
- public void onPlayerItem(PlayerItemEvent event) {
+ public void onPlayerInteract(PlayerInteractEvent event) {
}
/**
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index d0170bbb..ee0a1a01 100644
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -197,9 +197,9 @@ public final class JavaPluginLoader implements PluginLoader {
((PlayerListener)listener).onPlayerTeleport( (PlayerMoveEvent)event );
}
};
- case PLAYER_ITEM:
+ case PLAYER_INTERACT:
return new EventExecutor() { public void execute( Listener listener, Event event ) {
- ((PlayerListener)listener).onPlayerItem( (PlayerItemEvent)event );
+ ((PlayerListener)listener).onPlayerInteract( (PlayerInteractEvent)event );
}
};
case PLAYER_LOGIN:
@@ -266,11 +266,6 @@ public final class JavaPluginLoader implements PluginLoader {
((BlockListener)listener).onBlockCanBuild( (BlockCanBuildEvent)event );
}
};
- case BLOCK_RIGHTCLICK:
- return new EventExecutor() { public void execute( Listener listener, Event event ) {
- ((BlockListener)listener).onBlockRightClick( (BlockRightClickEvent)event );
- }
- };
case BLOCK_PLACE:
return new EventExecutor() { public void execute( Listener listener, Event event ) {
((BlockListener)listener).onBlockPlace( (BlockPlaceEvent)event );
@@ -281,11 +276,6 @@ public final class JavaPluginLoader implements PluginLoader {
((BlockListener)listener).onBlockDamage( (BlockDamageEvent)event );
}
};
- case BLOCK_INTERACT:
- return new EventExecutor() { public void execute( Listener listener, Event event ) {
- ((BlockListener)listener).onBlockInteract( (BlockInteractEvent)event );
- }
- };
case BLOCK_FROMTO:
return new EventExecutor() { public void execute( Listener listener, Event event ) {
((BlockListener)listener).onBlockFlow( (BlockFromToEvent)event );