From 6dc4698062306af20cd03d44e2adf973a03bce88 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 31 Dec 2010 20:38:17 -0500 Subject: [PATCH 1/9] Added private static final UID --- src/org/bukkit/event/EventException.java | 3 ++- src/org/bukkit/plugin/InvalidDescriptionException.java | 3 ++- src/org/bukkit/plugin/InvalidPluginException.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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/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 From 2e3f21bcf2af4eb06466c8ef62610ce6910f7e87 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 31 Dec 2010 20:40:44 -0500 Subject: [PATCH 2/9] Added Cancellable interface --- src/org/bukkit/event/Cancellable.java | 6 ++++++ .../bukkit/event/block/BlockPlacedEvent.java | 19 ++++++++++++++++--- .../bukkit/event/player/PlayerChatEvent.java | 3 ++- .../bukkit/event/player/PlayerMoveEvent.java | 3 ++- 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/org/bukkit/event/Cancellable.java 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/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; From a44979c88b8f234b0d8776c146cd49a4bb436b85 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 31 Dec 2010 21:17:16 -0500 Subject: [PATCH 3/9] Reimplemented BlockFlow to use multiple BlockFromToEvents --- .../bukkit/event/block/BlockFlowEvent.java | 85 ------------------- .../bukkit/event/block/BlockFromToEvent.java | 15 +++- src/org/bukkit/event/block/BlockListener.java | 2 +- 3 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 src/org/bukkit/event/block/BlockFlowEvent.java 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..cc0a30fa 100644 --- a/src/org/bukkit/event/block/BlockFromToEvent.java +++ b/src/org/bukkit/event/block/BlockFromToEvent.java @@ -2,12 +2,13 @@ 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; @@ -34,4 +35,16 @@ public class BlockFromToEvent extends BlockEvent { public Block getFromBlock() { return from; } + + @Override + public boolean isCancelled() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setCancelled(boolean cancel) { + // TODO Auto-generated method stub + + } } diff --git a/src/org/bukkit/event/block/BlockListener.java b/src/org/bukkit/event/block/BlockListener.java index b9dd9c80..2165d4aa 100644 --- a/src/org/bukkit/event/block/BlockListener.java +++ b/src/org/bukkit/event/block/BlockListener.java @@ -27,7 +27,7 @@ public class BlockListener implements Listener { * * @param event Relevant event details */ - public void onBlockFlow(BlockFlowEvent event) { + public void onBlockFlow(BlockFromToEvent event) { } /** From e26e2d70e8720762046d3f53d7843c1b0dc55879 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 31 Dec 2010 22:42:45 -0500 Subject: [PATCH 4/9] Actually put the correct functionality in isCancelled and setCancelled --- src/org/bukkit/event/block/BlockFromToEvent.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/bukkit/event/block/BlockFromToEvent.java b/src/org/bukkit/event/block/BlockFromToEvent.java index cc0a30fa..eb2846f9 100644 --- a/src/org/bukkit/event/block/BlockFromToEvent.java +++ b/src/org/bukkit/event/block/BlockFromToEvent.java @@ -11,11 +11,13 @@ import org.bukkit.event.Event; 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; } /** @@ -38,13 +40,11 @@ public class BlockFromToEvent extends BlockEvent implements Cancellable { @Override public boolean isCancelled() { - // TODO Auto-generated method stub - return false; + return cancel; } @Override public void setCancelled(boolean cancel) { - // TODO Auto-generated method stub - + this.cancel = cancel; } } From f527fd439849729c8188d80872e793e668db3a1b Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 31 Dec 2010 22:44:11 -0500 Subject: [PATCH 5/9] Added BlockCanBuild Event. Fixed Event enumeration --- src/org/bukkit/event/Event.java | 3 +- .../event/block/BlockCanBuildEvent.java | 28 +++++++++++++++++++ src/org/bukkit/event/block/BlockListener.java | 6 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/org/bukkit/event/block/BlockCanBuildEvent.java 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/block/BlockCanBuildEvent.java b/src/org/bukkit/event/block/BlockCanBuildEvent.java new file mode 100644 index 00000000..ebbe83c9 --- /dev/null +++ b/src/org/bukkit/event/block/BlockCanBuildEvent.java @@ -0,0 +1,28 @@ +/** + * + */ +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) { + super(type, block); + } + + @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 2165d4aa..7bead1a7 100644 --- a/src/org/bukkit/event/block/BlockListener.java +++ b/src/org/bukkit/event/block/BlockListener.java @@ -22,6 +22,12 @@ 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 canBuild(BlockCanBuildEvent event) { + } + /** * Called when a block flows (water/lava) * From eadfe2adffc940eead34a2fd299bc7b74b084878 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 1 Jan 2011 01:20:44 -0500 Subject: [PATCH 6/9] Implemented BLOCK_CANBUILD --- .../bukkit/event/block/BlockCanBuildEvent.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/org/bukkit/event/block/BlockCanBuildEvent.java b/src/org/bukkit/event/block/BlockCanBuildEvent.java index ebbe83c9..859c8d30 100644 --- a/src/org/bukkit/event/block/BlockCanBuildEvent.java +++ b/src/org/bukkit/event/block/BlockCanBuildEvent.java @@ -12,15 +12,26 @@ import org.bukkit.event.Cancellable; public class BlockCanBuildEvent extends BlockEvent implements Cancellable { protected boolean cancel; - public BlockCanBuildEvent(Type type, Block block) { + 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; From 0b7cab13d0f5c7ab1202e65b872f14bb941f3a2e Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 1 Jan 2011 01:25:22 -0500 Subject: [PATCH 7/9] Implemented BLOCK_CANBUILD, had wrong Listener method name --- .../bukkit/event/block/BlockCanBuildEvent.java | 17 ++++++++++++++--- src/org/bukkit/event/block/BlockListener.java | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/org/bukkit/event/block/BlockCanBuildEvent.java b/src/org/bukkit/event/block/BlockCanBuildEvent.java index ebbe83c9..859c8d30 100644 --- a/src/org/bukkit/event/block/BlockCanBuildEvent.java +++ b/src/org/bukkit/event/block/BlockCanBuildEvent.java @@ -12,15 +12,26 @@ import org.bukkit.event.Cancellable; public class BlockCanBuildEvent extends BlockEvent implements Cancellable { protected boolean cancel; - public BlockCanBuildEvent(Type type, Block block) { + 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/BlockListener.java b/src/org/bukkit/event/block/BlockListener.java index 7bead1a7..cef040c3 100644 --- a/src/org/bukkit/event/block/BlockListener.java +++ b/src/org/bukkit/event/block/BlockListener.java @@ -25,7 +25,7 @@ public class BlockListener implements Listener { /** * Called when we try to place a block, to see if we can build it */ - public void canBuild(BlockCanBuildEvent event) { + public void onBlockCanBuild(BlockCanBuildEvent event) { } /** From f7fcfd22a585422a15eb156f2e4e5390ef0ec3d2 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 1 Jan 2011 01:40:02 -0500 Subject: [PATCH 8/9] Sample to let you place cactus anywhere --- .../dinnerbone/bukkit/sample/SampleBlockListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java index 11a418ad..85f93402 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(true); + } + } } From f9a002222495081534e641b92c7bc4bf863f1acf Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 1 Jan 2011 01:55:04 -0500 Subject: [PATCH 9/9] Added onBlockCanBuild to loader --- .../dinnerbone/bukkit/sample/SampleBlockListener.java | 2 +- src/org/bukkit/plugin/java/JavaPluginLoader.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java index 85f93402..366736d7 100644 --- a/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java +++ b/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java @@ -35,7 +35,7 @@ public class SampleBlockListener extends BlockListener { Block block = event.getBlock(); if (block.getType() == 81) { - event.setCancelled(true); + event.setCancelled(false); } } } 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; } } }