diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java new file mode 100644 index 0000000000..11a418ade5 --- /dev/null +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SampleBlockListener.java @@ -0,0 +1,31 @@ + +package com.dinnerbone.bukkit.sample; + +import org.bukkit.Block; +import org.bukkit.BlockFace; +import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPhysicsEvent; + +/** + * Sample block listener + * @author Dinnerbone + */ +public class SampleBlockListener extends BlockListener { + private final SamplePlugin plugin; + + public SampleBlockListener(final SamplePlugin plugin) { + this.plugin = plugin; + } + + @Override + public void onBlockPhysics(BlockPhysicsEvent event) { + Block block = event.getBlock(); + + if ((block.getType() == 12) || (block.getType() == 13)) { + Block above = block.getFace(BlockFace.Up); + if (above.getType() == 42) { + event.setCancelled(true); + } + } + } +} diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java index f0782d099e..69b84af448 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java @@ -18,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin; */ public class SamplePlugin extends JavaPlugin { private final SamplePlayerListener playerListener = new SamplePlayerListener(this); + private final SampleBlockListener blockListener = new SampleBlockListener(this); private final HashMap debugees = new HashMap(); public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { @@ -39,6 +40,7 @@ public class SamplePlugin extends JavaPlugin { getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); + getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this); } public boolean isDebugging(final Player player) { diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index 65726b85e5..b1c260d13a 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -14,6 +14,8 @@ 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.player.*; import org.bukkit.plugin.*; @@ -103,6 +105,14 @@ public final class JavaPluginLoader implements PluginLoader { trueListener.onPlayerLogin((PlayerLoginEvent)event); break; } + } else if (listener instanceof BlockListener) { + BlockListener trueListener = (BlockListener)listener; + + switch (event.getType()) { + case BLOCK_PHYSICS: + trueListener.onBlockPhysics((BlockPhysicsEvent)event); + break; + } } } }