Implemented BlockInteract, BlockRightClicked and PlayerItem. Removed
BlockItem as we're not doing it that way anymore. By: durron597 <martin.jared@gmail.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Entity;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* This event is triggered whenever an entity interacts with the universe
|
||||
* it's always called, on a left click or a right click, or walking on
|
||||
* (as in the case of pressure plates). Use cancellable to prevent things
|
||||
* from happening (doors opening, buttons, pressure plates being walked
|
||||
* on, etc). Note: even though pressure plates work totally differently
|
||||
* than the other interact events, it's still thrown in with this event.
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockInteractEvent extends BlockEvent implements Cancellable {
|
||||
protected boolean cancel;
|
||||
protected Entity theEntity;
|
||||
|
||||
/**
|
||||
* @param type The type of this event
|
||||
* @param interactedBlock the block that was interacted with
|
||||
* @param who The entity that interacted with
|
||||
*/
|
||||
public BlockInteractEvent(Type type, Block interactedBlock, Entity who) {
|
||||
super(type, interactedBlock);
|
||||
theEntity = who;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity that triggered this event
|
||||
*
|
||||
* @return Entity the entity that triggered this event
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return theEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for seeing if this event was triggered by a player
|
||||
*
|
||||
* @return boolean whether this event was triggered by a player
|
||||
*/
|
||||
public boolean isPlayer() {
|
||||
return theEntity instanceof Player;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,22 @@ public class BlockListener implements Listener {
|
||||
*/
|
||||
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is interacted with
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockInteracted(BlockInteractEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRightClicked(BlockRightClickedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
@@ -8,23 +9,21 @@ import org.bukkit.event.Cancellable;
|
||||
* Not implemented yet
|
||||
*/
|
||||
public class BlockPlacedEvent extends BlockEvent implements Cancellable {
|
||||
private boolean cancel;
|
||||
private Player player;
|
||||
protected boolean cancel;
|
||||
protected boolean canBuild;
|
||||
protected Block placedAgainst;
|
||||
protected ItemStack itemInHand;
|
||||
protected Player player;
|
||||
|
||||
public BlockPlacedEvent(Type type, Block theBlock) {
|
||||
super(type, theBlock);
|
||||
public BlockPlacedEvent(Type type, Block placedBlock, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild) {
|
||||
super(type, placedBlock);
|
||||
this.placedAgainst = placedAgainst;
|
||||
this.itemInHand = itemInHand;
|
||||
this.player = thePlayer;
|
||||
this.canBuild = canBuild;
|
||||
cancel = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player who placed this block
|
||||
*
|
||||
* @return Player who placed the block
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cancellation state of this event. A cancelled event will not
|
||||
* be executed in the server, but will still pass to other plugins
|
||||
@@ -45,4 +44,62 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player who placed this block
|
||||
*
|
||||
* @return Player who placed the block
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clarity method for getting the placed block. Not really needed
|
||||
* except for reasons of clarity
|
||||
*
|
||||
* @return Block the block that was placed
|
||||
*/
|
||||
public Block getBlockPlaced() {
|
||||
return getBlock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the block that this block was placed against
|
||||
*
|
||||
* @return Block the block that the new block was placed against
|
||||
*/
|
||||
public Block getBlockAgainst() {
|
||||
return placedAgainst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item in your hand when you placed the block
|
||||
*
|
||||
* @return ItemStack the item in your hand when placing the block
|
||||
*/
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value whether the player would be allowed to build here.
|
||||
* Defaults to spawn if the server was going to stop them (such as, the
|
||||
* player is in Spawn). Note that this is an entirely different check
|
||||
* than BLOCK_CANBUILD, as this refers to a player, not universe-physics
|
||||
* rule like cactus on dirt.
|
||||
*
|
||||
* @return boolean whether the server would allow a player to build here
|
||||
*/
|
||||
public boolean canBuild() {
|
||||
return this.canBuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the canBuild state of this event. Set to true if you want the
|
||||
* player to be able to build.
|
||||
*/
|
||||
public void setBuild(boolean canBuild) {
|
||||
this.canBuild = canBuild;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Player;
|
||||
|
||||
/**
|
||||
* Not implemented yet
|
||||
*/
|
||||
public class BlockRightClickedEvent extends BlockEvent {
|
||||
protected Block clickedBlock;
|
||||
protected BlockFace direction;
|
||||
protected ItemStack itemInHand;
|
||||
protected Player player;
|
||||
|
||||
public BlockRightClickedEvent(Type type, Block placedAgainst, BlockFace direction, ItemStack itemInHand, Player thePlayer) {
|
||||
super(type, placedAgainst);
|
||||
this.clickedBlock = placedAgainst;
|
||||
this.direction = direction;
|
||||
this.itemInHand = itemInHand;
|
||||
this.player = thePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player who placed this block
|
||||
*
|
||||
* @return Player who placed the block
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the block that this block was placed against
|
||||
*
|
||||
* @return Block the block that the new block was placed against
|
||||
*/
|
||||
public Block getBlockAgainst() {
|
||||
return clickedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BlockFace the direction this block was clicked
|
||||
*/
|
||||
public BlockFace getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item in your hand when you placed the block
|
||||
*
|
||||
* @return ItemStack the item in your hand when placing the block
|
||||
*/
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user