Merge remote branch 'remotes/origin/master'
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
@@ -170,6 +170,33 @@ public abstract class Event {
|
||||
*/
|
||||
PLAYER_ANIMATION (Category.PLAYER),
|
||||
|
||||
/**
|
||||
* Always called when a player uses an item while pointing at a block
|
||||
* Sometimes, cancelling this event doesn't do anything.
|
||||
*
|
||||
* This is the event that is called on block placement. Cancel this
|
||||
* to prevent block placement. This will ALWAYS be called, even if
|
||||
* universe physics prevents the block from being placed. This allows
|
||||
* you to add functionality to rightclicking with block items even
|
||||
* if the universe won't allow them to get placed. Use BLOCK_CANBUILD
|
||||
* to override notch's block placement rules.
|
||||
*
|
||||
* Example: This event is also called, for example when redstone is
|
||||
* placed, when a sign is placed, when minecarts are placed on a track,
|
||||
* when boats are placed (in both water and air)
|
||||
*/
|
||||
PLAYER_BLOCKITEM (Category.PLAYER),
|
||||
|
||||
/**
|
||||
* Called when a player uses an item while pointing at the air
|
||||
* This can also be additionally called while pointing at the ground
|
||||
*
|
||||
* Example: all food will also call this event while pointing at the
|
||||
* ground, bows/snowballs/eggs will all call this while pointing at
|
||||
* the ground, buckets call this event.
|
||||
*/
|
||||
PLAYER_ITEM (Category.PLAYER),
|
||||
|
||||
/**
|
||||
* Called when a player teleports from one position to another
|
||||
*/
|
||||
@@ -185,7 +212,8 @@ public abstract class Event {
|
||||
BLOCK_DAMAGED (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a block is undergoing a check on whether it can be built
|
||||
* Called when a block is undergoing a universe physics
|
||||
* check on whether it can be built
|
||||
*
|
||||
* For example, cacti cannot be built on grass unless overridden here
|
||||
*/
|
||||
@@ -210,16 +238,16 @@ public abstract class Event {
|
||||
* type
|
||||
*/
|
||||
BLOCK_PHYSICS (Category.BLOCK),
|
||||
|
||||
|
||||
/**
|
||||
* Called when a player is attempting to place a block
|
||||
*/
|
||||
BLOCK_PLACED (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a specific block is being sent to a player
|
||||
* Called when leaves are decaying naturally
|
||||
*/
|
||||
BLOCK_SENT (Category.BLOCK),
|
||||
LEAVES_DECAY (Category.BLOCK),
|
||||
|
||||
/**
|
||||
* Called when a liquid attempts to flow into a block which already
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to Blocks
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockListener implements Listener {
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public BlockListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is broken (or destroyed)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockBroken(BlockBrokenEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we try to place a block, to see if we can build it
|
||||
*/
|
||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block flows (water/lava)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player right clicks a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRightClicked(BlockRightClickedEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to Blocks
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockListener implements Listener {
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public BlockListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is broken (or destroyed)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockBroken(BlockBrokenEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we try to place a block, to see if we can build it
|
||||
*/
|
||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block flows (water/lava)
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockFlow(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block gets ignited
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when block physics occurs
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player places a block
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when redstone changes
|
||||
* From: the source of the redstone change
|
||||
* To: The redstone dust that changed
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when leaves are decaying naturally
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,24 +11,36 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable {
|
||||
private boolean cancel;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param theBlock
|
||||
*/
|
||||
public BlockPlacedEvent(Type type, Block theBlock) {
|
||||
super(type, theBlock);
|
||||
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
|
||||
*
|
||||
* @return true if this event is cancelled
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Player;
|
||||
|
||||
/**
|
||||
* @author durron597
|
||||
*/
|
||||
public class BlockRightClickedEvent extends BlockEvent {
|
||||
protected Player clicker;
|
||||
protected BlockFace direction;
|
||||
protected ItemStack clickedWith;
|
||||
|
||||
/**
|
||||
* @param type The type of event this is
|
||||
* @param theBlock The clicked block
|
||||
* @param direction The face we clicked from
|
||||
* @param clicker The player who clicked a block
|
||||
* @param clickedWith Item in player's hand
|
||||
*/
|
||||
public BlockRightClickedEvent(Type type, Block theBlock, BlockFace direction, Player clicker, ItemStack clickedWith) {
|
||||
super(type, theBlock);
|
||||
this.direction = direction;
|
||||
this.clicker = clicker;
|
||||
this.clickedWith = clickedWith;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clicker
|
||||
*/
|
||||
public Player getClicker() {
|
||||
return clicker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public BlockFace getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clickedWith
|
||||
*/
|
||||
public ItemStack getClickedWith() {
|
||||
return clickedWith;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* Called on leaves decaying
|
||||
*/
|
||||
public class LeavesDecayEvent extends BlockEvent implements Cancellable {
|
||||
private boolean cancel = false;
|
||||
|
||||
public LeavesDecayEvent(final Type type, final Block block) {
|
||||
super(type, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.BlockFace;
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* Represents an event that a block was clicked with an item.
|
||||
*
|
||||
* Note: while this is the event that is thrown on block placement, there is no
|
||||
* BlockPlaced associated with this event. This is because the event is thrown
|
||||
* before the block is written to the universe, so the returned block would not
|
||||
* be the new placed block. In hMod, BlockPlaced worked by UNDOING the block
|
||||
* placement; in Bukkit, we catch the event before it even gets written to the
|
||||
* universe, so the concept of a placed block is meaningless.
|
||||
*
|
||||
* To get the type of block that's being placed, use the method getItem (for
|
||||
* the item in your hand).
|
||||
*
|
||||
* @author durron597
|
||||
*/
|
||||
public class PlayerBlockItemEvent extends PlayerItemEvent implements Cancellable {
|
||||
protected Block blockClicked;
|
||||
protected BlockFace direction;
|
||||
protected boolean canBuild;
|
||||
|
||||
public PlayerBlockItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace direction, boolean canBuild) {
|
||||
super(type, who, item);
|
||||
this.blockClicked = blockClicked;
|
||||
this.canBuild = canBuild;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 isBlock() {
|
||||
if (item == null) return false;
|
||||
|
||||
return item.getType().isBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the clicked block
|
||||
*
|
||||
* @return Block returns the block clicked with this item.
|
||||
*/
|
||||
public Block getBlockClicked() {
|
||||
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 direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.event.Cancellable;
|
||||
public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
||||
private boolean cancel = false;
|
||||
private String message;
|
||||
private String format = "<%1$s> %2$s";
|
||||
|
||||
public PlayerChatEvent(final Type type, final Player player, final String message) {
|
||||
super(type, player);
|
||||
@@ -63,4 +64,22 @@ public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
||||
public void setPlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format to use to display this chat message
|
||||
*
|
||||
* @return String.Format compatible format string
|
||||
*/
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the format to use to display this chat message
|
||||
*
|
||||
* @param format String.Format compatible format string
|
||||
*/
|
||||
public void setFormat(final String format) {
|
||||
this.format = format;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author durron597
|
||||
*
|
||||
*/
|
||||
public class PlayerItemEvent extends PlayerEvent implements Cancellable {
|
||||
protected ItemStack item;
|
||||
protected boolean cancel;
|
||||
|
||||
public PlayerItemEvent(Type type, Player who, ItemStack item) {
|
||||
super(type, who);
|
||||
this.item = item;
|
||||
cancel = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*
|
||||
* Cancelling 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) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (this.item == null) return Material.Air;
|
||||
|
||||
return item.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
package org.bukkit.event.world;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
|
||||
/**
|
||||
* Called when a chunk is loaded
|
||||
*/
|
||||
public class ChunkLoadedEvent extends WorldEvent {
|
||||
private final Chunk chunk;
|
||||
|
||||
public ChunkLoadedEvent(final Type type, final Chunk chunk) {
|
||||
super(type, chunk.getWorld());
|
||||
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chunk being loaded/unloaded
|
||||
*
|
||||
* @return Chunk that triggered this event
|
||||
*/
|
||||
public Chunk getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
package org.bukkit.event.world;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* Called when a chunk is unloaded
|
||||
*/
|
||||
public class ChunkUnloadedEvent extends ChunkLoadedEvent implements Cancellable {
|
||||
private boolean cancel = false;
|
||||
|
||||
public ChunkUnloadedEvent(final Type type, final Chunk chunk) {
|
||||
super(type, chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
package org.bukkit.event.world;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* Represents events within a world
|
||||
*/
|
||||
public class WorldEvent extends Event {
|
||||
private final World world;
|
||||
|
||||
public WorldEvent(final Type type, final World world) {
|
||||
super(type);
|
||||
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the world primarily involved with this event
|
||||
*
|
||||
* @return World which caused this event
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package org.bukkit.event.world;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all World related events
|
||||
*/
|
||||
public class WorldListener implements Listener {
|
||||
/**
|
||||
* Called when a chunk is loaded
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onChunkLoaded(ChunkLoadedEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a chunk is unloaded
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onChunkUnloaded(ChunkUnloadedEvent event) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user