diff --git a/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java index 11a418ad..366736d7 100644 --- a/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java +++ b/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java @@ -3,6 +3,7 @@ package com.dinnerbone.bukkit.sample; import org.bukkit.Block; import org.bukkit.BlockFace; +import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPhysicsEvent; @@ -28,4 +29,13 @@ public class SampleBlockListener extends BlockListener { } } } + + @Override + public void onBlockCanBuild(BlockCanBuildEvent event) { + Block block = event.getBlock(); + + if (block.getType() == 81) { + event.setCancelled(false); + } + } } diff --git a/src/org/bukkit/event/Cancellable.java b/src/org/bukkit/event/Cancellable.java new file mode 100644 index 00000000..05789dea --- /dev/null +++ b/src/org/bukkit/event/Cancellable.java @@ -0,0 +1,6 @@ +package org.bukkit.event; + +public interface Cancellable { + public boolean isCancelled(); + public void setCancelled(boolean cancel); +} diff --git a/src/org/bukkit/event/Event.java b/src/org/bukkit/event/Event.java index 1340b8f3..2362a31d 100644 --- a/src/org/bukkit/event/Event.java +++ b/src/org/bukkit/event/Event.java @@ -76,7 +76,8 @@ public abstract class Event { /** * Block Events */ - BLOCK_DAMAGED (Category.BLOCK), + BLOCK_BROKEN (Category.BLOCK), + BLOCK_CANBUILD (Category.BLOCK), BLOCK_FLOW (Category.BLOCK), BLOCK_IGNITE (Category.BLOCK), BLOCK_PHYSICS (Category.BLOCK), diff --git a/src/org/bukkit/event/EventException.java b/src/org/bukkit/event/EventException.java index 25134cbc..2abd7d94 100644 --- a/src/org/bukkit/event/EventException.java +++ b/src/org/bukkit/event/EventException.java @@ -1,7 +1,8 @@ package org.bukkit.event; public class EventException extends Exception { - private final Throwable cause; + private static final long serialVersionUID = 3532808232324183999L; + private final Throwable cause; /** * Constructs a new EventException based on the given Exception diff --git a/src/org/bukkit/event/block/BlockCanBuildEvent.java b/src/org/bukkit/event/block/BlockCanBuildEvent.java new file mode 100644 index 00000000..859c8d30 --- /dev/null +++ b/src/org/bukkit/event/block/BlockCanBuildEvent.java @@ -0,0 +1,39 @@ +/** + * + */ +package org.bukkit.event.block; + +import org.bukkit.Block; +import org.bukkit.event.Cancellable; + +/** + * @author durron597 + */ +public class BlockCanBuildEvent extends BlockEvent implements Cancellable { + protected boolean cancel; + + public BlockCanBuildEvent(Type type, Block block, boolean canBuild) { + super(type, block); + + cancel = canBuild; + } + + /** + * Returns whether or not the block can be built here. By default, returns + * Minecraft's answer on whether the block can be built + * + * @return boolean whether or not the block can be built + */ + @Override + public boolean isCancelled() { + return cancel; + } + + /** + * Set whether the block can be built here. + */ + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } +} diff --git a/src/org/bukkit/event/block/BlockFlowEvent.java b/src/org/bukkit/event/block/BlockFlowEvent.java deleted file mode 100644 index a91cedfd..00000000 --- a/src/org/bukkit/event/block/BlockFlowEvent.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.bukkit.event.block; - -import java.util.HashSet; -import java.util.List; - -import org.bukkit.Block; -import org.bukkit.BlockFace; -import org.bukkit.event.Event; - -/** - * Holds information for events with a source block and a destination block - */ -public class BlockFlowEvent extends BlockEvent { - protected final HashSet faceList; - - public BlockFlowEvent(final Event.Type type, final Block block, BlockFace... faces) { - super(type, block); - this.faceList = new HashSet(); - if (faces != null && faces.length > 0) { - for (BlockFace theFace : faces) { - faceList.add(new BlockFlow(theFace)); - } - } - } - - public BlockFlowEvent(final Event.Type type, final Block block, List faces) { - super(type, block); - this.faceList = new HashSet(); - if (faces != null && faces.size() > 0) { - for (BlockFace theFace : faces) { - faceList.add(new BlockFlow(theFace)); - } - } - } - - /** - * We don't want plugins changing the eligible flowing faces - * therefore give them a new HashSet instance - * - * @return Block the block is event originated from - */ - public HashSet getFaces() { - return new HashSet(faceList); - } - - /** - * Class that represents a flow direction and whether it's cancelled - */ - public class BlockFlow { - private final BlockFace flowDirection; - private boolean cancelled; - - public BlockFlow(BlockFace flowDirection) { - this.flowDirection = flowDirection; - cancelled = false; - } - - public BlockFace getFlowDirection() { - return flowDirection; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancel) { - cancelled = cancel; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof BlockFlow)) return false; - return equals((BlockFlow) o); - } - - public boolean equals(BlockFlow flow) { - return flowDirection.equals(flow.flowDirection); - } - - @Override - public int hashCode() { - return flowDirection.hashCode(); - } - } -} diff --git a/src/org/bukkit/event/block/BlockFromToEvent.java b/src/org/bukkit/event/block/BlockFromToEvent.java index 2fcbcf0c..eb2846f9 100644 --- a/src/org/bukkit/event/block/BlockFromToEvent.java +++ b/src/org/bukkit/event/block/BlockFromToEvent.java @@ -2,19 +2,22 @@ package org.bukkit.event.block; import org.bukkit.Block; import org.bukkit.BlockFace; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; /** * Holds information for events with a source block and a destination block */ -public class BlockFromToEvent extends BlockEvent { +public class BlockFromToEvent extends BlockEvent implements Cancellable { protected Block from; protected BlockFace face; - + protected boolean cancel; + public BlockFromToEvent(final Event.Type type, final Block block, final BlockFace face) { super(type, block); this.face = face; this.from = block.getRelative(face.getModX(), face.getModY(), face.getModZ()); + this.cancel = false; } /** @@ -34,4 +37,14 @@ public class BlockFromToEvent extends BlockEvent { public Block getFromBlock() { return from; } + + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } } diff --git a/src/org/bukkit/event/block/BlockListener.java b/src/org/bukkit/event/block/BlockListener.java index b9dd9c80..cef040c3 100644 --- a/src/org/bukkit/event/block/BlockListener.java +++ b/src/org/bukkit/event/block/BlockListener.java @@ -22,12 +22,18 @@ public class BlockListener implements Listener { 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(BlockFlowEvent event) { + public void onBlockFlow(BlockFromToEvent event) { } /** diff --git a/src/org/bukkit/event/block/BlockPlacedEvent.java b/src/org/bukkit/event/block/BlockPlacedEvent.java index e8e15e21..7b7710f4 100644 --- a/src/org/bukkit/event/block/BlockPlacedEvent.java +++ b/src/org/bukkit/event/block/BlockPlacedEvent.java @@ -1,19 +1,32 @@ package org.bukkit.event.block; import org.bukkit.Block; +import org.bukkit.event.Cancellable; /** * Not implemented yet */ -public class BlockPlacedEvent extends BlockEvent { - +public class BlockPlacedEvent extends BlockEvent implements Cancellable { + private boolean cancel; + /** * @param type * @param theBlock */ public BlockPlacedEvent(Type type, Block theBlock) { super(type, theBlock); - // TODO Auto-generated constructor stub + cancel = false; + } + + @Override + public boolean isCancelled() { + // TODO Auto-generated method stub + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; } } diff --git a/src/org/bukkit/event/player/PlayerChatEvent.java b/src/org/bukkit/event/player/PlayerChatEvent.java index d924b5e3..f67ebd86 100644 --- a/src/org/bukkit/event/player/PlayerChatEvent.java +++ b/src/org/bukkit/event/player/PlayerChatEvent.java @@ -2,11 +2,12 @@ package org.bukkit.event.player; import org.bukkit.Player; +import org.bukkit.event.Cancellable; /** * Holds information for player chat and commands */ -public class PlayerChatEvent extends PlayerEvent { +public class PlayerChatEvent extends PlayerEvent implements Cancellable { private boolean cancel = false; private String message; diff --git a/src/org/bukkit/event/player/PlayerMoveEvent.java b/src/org/bukkit/event/player/PlayerMoveEvent.java index bb08255d..24b31b59 100644 --- a/src/org/bukkit/event/player/PlayerMoveEvent.java +++ b/src/org/bukkit/event/player/PlayerMoveEvent.java @@ -3,12 +3,13 @@ package org.bukkit.event.player; import org.bukkit.Location; import org.bukkit.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; /** * Holds information for player movement and teleportation events */ -public class PlayerMoveEvent extends PlayerEvent { +public class PlayerMoveEvent extends PlayerEvent implements Cancellable { private boolean cancel = false; private Location from; private Location to; diff --git a/src/org/bukkit/plugin/InvalidDescriptionException.java b/src/org/bukkit/plugin/InvalidDescriptionException.java index 2d586a14..e6f03892 100644 --- a/src/org/bukkit/plugin/InvalidDescriptionException.java +++ b/src/org/bukkit/plugin/InvalidDescriptionException.java @@ -5,7 +5,8 @@ package org.bukkit.plugin; * Thrown when attempting to load an invalid PluginDescriptionFile */ public class InvalidDescriptionException extends Exception { - private final Throwable cause; + private static final long serialVersionUID = 5721389122281775894L; + private final Throwable cause; /** * Constructs a new InvalidDescriptionException based on the given Exception diff --git a/src/org/bukkit/plugin/InvalidPluginException.java b/src/org/bukkit/plugin/InvalidPluginException.java index 9ab904c1..4155723a 100644 --- a/src/org/bukkit/plugin/InvalidPluginException.java +++ b/src/org/bukkit/plugin/InvalidPluginException.java @@ -5,7 +5,8 @@ package org.bukkit.plugin; * Thrown when attempting to load an invalid Plugin file */ public class InvalidPluginException extends Exception { - private final Throwable cause; + private static final long serialVersionUID = -8242141640709409542L; + private final Throwable cause; /** * Constructs a new InvalidPluginException based on the given Exception diff --git a/src/org/bukkit/plugin/java/JavaPluginLoader.java b/src/org/bukkit/plugin/java/JavaPluginLoader.java index b1c260d1..40753b02 100644 --- a/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -14,8 +14,7 @@ import java.util.regex.Pattern; import org.bukkit.Server; import org.bukkit.event.Event; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockListener; -import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.*; import org.bukkit.event.player.*; import org.bukkit.plugin.*; @@ -112,6 +111,12 @@ public final class JavaPluginLoader implements PluginLoader { case BLOCK_PHYSICS: trueListener.onBlockPhysics((BlockPhysicsEvent)event); break; + case BLOCK_CANBUILD: + trueListener.onBlockCanBuild((BlockCanBuildEvent)event); + break; + case BLOCK_FLOW: + trueListener.onBlockFlow((BlockFromToEvent)event); + break; } } }