From 4ef3cfa0e873a5ed41d2be1373de6186f5aed894 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 31 Dec 2010 20:38:17 -0500 Subject: [PATCH 1/9] Added private static final UID By: durron597 --- paper-api/src/org/bukkit/event/EventException.java | 3 ++- .../src/org/bukkit/plugin/InvalidDescriptionException.java | 3 ++- paper-api/src/org/bukkit/plugin/InvalidPluginException.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/paper-api/src/org/bukkit/event/EventException.java b/paper-api/src/org/bukkit/event/EventException.java index 25134cbc5f..2abd7d9403 100644 --- a/paper-api/src/org/bukkit/event/EventException.java +++ b/paper-api/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/paper-api/src/org/bukkit/plugin/InvalidDescriptionException.java b/paper-api/src/org/bukkit/plugin/InvalidDescriptionException.java index 2d586a14fa..e6f038927e 100644 --- a/paper-api/src/org/bukkit/plugin/InvalidDescriptionException.java +++ b/paper-api/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/paper-api/src/org/bukkit/plugin/InvalidPluginException.java b/paper-api/src/org/bukkit/plugin/InvalidPluginException.java index 9ab904c153..4155723abe 100644 --- a/paper-api/src/org/bukkit/plugin/InvalidPluginException.java +++ b/paper-api/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 7d88f008394153cd5c2d19c4aeb759a750536898 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 31 Dec 2010 20:40:44 -0500 Subject: [PATCH 2/9] Added Cancellable interface By: durron597 --- .../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 paper-api/src/org/bukkit/event/Cancellable.java diff --git a/paper-api/src/org/bukkit/event/Cancellable.java b/paper-api/src/org/bukkit/event/Cancellable.java new file mode 100644 index 0000000000..05789dea84 --- /dev/null +++ b/paper-api/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/paper-api/src/org/bukkit/event/block/BlockPlacedEvent.java b/paper-api/src/org/bukkit/event/block/BlockPlacedEvent.java index e8e15e21cd..7b7710f452 100644 --- a/paper-api/src/org/bukkit/event/block/BlockPlacedEvent.java +++ b/paper-api/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/paper-api/src/org/bukkit/event/player/PlayerChatEvent.java b/paper-api/src/org/bukkit/event/player/PlayerChatEvent.java index d924b5e335..f67ebd8627 100644 --- a/paper-api/src/org/bukkit/event/player/PlayerChatEvent.java +++ b/paper-api/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/paper-api/src/org/bukkit/event/player/PlayerMoveEvent.java b/paper-api/src/org/bukkit/event/player/PlayerMoveEvent.java index bb08255d34..24b31b5941 100644 --- a/paper-api/src/org/bukkit/event/player/PlayerMoveEvent.java +++ b/paper-api/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 1ec5689002ceb8e6a94240502dd2a59b53953f04 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 31 Dec 2010 21:17:16 -0500 Subject: [PATCH 3/9] Reimplemented BlockFlow to use multiple BlockFromToEvents By: durron597 --- .../bukkit/event/block/BlockFlowEvent.java | 85 ------------------- .../bukkit/event/block/BlockFromToEvent.java | 15 +++- .../org/bukkit/event/block/BlockListener.java | 2 +- 3 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 paper-api/src/org/bukkit/event/block/BlockFlowEvent.java diff --git a/paper-api/src/org/bukkit/event/block/BlockFlowEvent.java b/paper-api/src/org/bukkit/event/block/BlockFlowEvent.java deleted file mode 100644 index a91cedfdcd..0000000000 --- a/paper-api/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/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java b/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java index 2fcbcf0c76..cc0a30fa3c 100644 --- a/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java +++ b/paper-api/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/paper-api/src/org/bukkit/event/block/BlockListener.java b/paper-api/src/org/bukkit/event/block/BlockListener.java index b9dd9c8041..2165d4aab8 100644 --- a/paper-api/src/org/bukkit/event/block/BlockListener.java +++ b/paper-api/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 1c88da4e9373683c6ac40e08baa57b6af1a46b42 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 31 Dec 2010 22:42:45 -0500 Subject: [PATCH 4/9] Actually put the correct functionality in isCancelled and setCancelled By: durron597 --- .../src/org/bukkit/event/block/BlockFromToEvent.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java b/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java index cc0a30fa3c..eb2846f9c6 100644 --- a/paper-api/src/org/bukkit/event/block/BlockFromToEvent.java +++ b/paper-api/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 be1ad0e0409117bf5b87e818fae0e454a8aca59c Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 31 Dec 2010 22:44:11 -0500 Subject: [PATCH 5/9] Added BlockCanBuild Event. Fixed Event enumeration By: durron597 --- paper-api/src/org/bukkit/event/Event.java | 3 +- .../event/block/BlockCanBuildEvent.java | 28 +++++++++++++++++++ .../org/bukkit/event/block/BlockListener.java | 6 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java diff --git a/paper-api/src/org/bukkit/event/Event.java b/paper-api/src/org/bukkit/event/Event.java index 1340b8f3c6..2362a31d61 100644 --- a/paper-api/src/org/bukkit/event/Event.java +++ b/paper-api/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/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java b/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java new file mode 100644 index 0000000000..ebbe83c9a8 --- /dev/null +++ b/paper-api/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/paper-api/src/org/bukkit/event/block/BlockListener.java b/paper-api/src/org/bukkit/event/block/BlockListener.java index 2165d4aab8..7bead1a76e 100644 --- a/paper-api/src/org/bukkit/event/block/BlockListener.java +++ b/paper-api/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 6c30c83e910dd46e731a46d570d2a39ce5b1ecbb Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 1 Jan 2011 01:20:44 -0500 Subject: [PATCH 6/9] Implemented BLOCK_CANBUILD By: durron597 --- .../bukkit/event/block/BlockCanBuildEvent.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java b/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java index ebbe83c9a8..859c8d3067 100644 --- a/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java +++ b/paper-api/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 7aac860d94617df8cefe004a193467f15031cafc Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 1 Jan 2011 01:25:22 -0500 Subject: [PATCH 7/9] Implemented BLOCK_CANBUILD, had wrong Listener method name By: durron597 --- .../bukkit/event/block/BlockCanBuildEvent.java | 17 ++++++++++++++--- .../org/bukkit/event/block/BlockListener.java | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java b/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java index ebbe83c9a8..859c8d3067 100644 --- a/paper-api/src/org/bukkit/event/block/BlockCanBuildEvent.java +++ b/paper-api/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/paper-api/src/org/bukkit/event/block/BlockListener.java b/paper-api/src/org/bukkit/event/block/BlockListener.java index 7bead1a76e..cef040c330 100644 --- a/paper-api/src/org/bukkit/event/block/BlockListener.java +++ b/paper-api/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 b5cbcfbcdb0d0fec3e7d2cec8afb1363fb538c20 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 1 Jan 2011 01:40:02 -0500 Subject: [PATCH 8/9] Sample to let you place cactus anywhere By: durron597 --- .../dinnerbone/bukkit/sample/SampleBlockListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java index 11a418ade5..85f93402d8 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java +++ b/paper-api/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 29cb3a3a793e96c0efba5fbd46647eb207148f72 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 1 Jan 2011 01:55:04 -0500 Subject: [PATCH 9/9] Added onBlockCanBuild to loader By: durron597 --- .../dinnerbone/bukkit/sample/SampleBlockListener.java | 2 +- .../src/org/bukkit/plugin/java/JavaPluginLoader.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java index 85f93402d8..366736d7ff 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java +++ b/paper-api/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/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index b1c260d13a..40753b0271 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/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; } } }