Updated sample plugin to test physics

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-31 21:45:55 +00:00
parent ddd950ae40
commit 4124f9e7bb
3 changed files with 43 additions and 0 deletions

View File

@ -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);
}
}
}
}

View File

@ -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<Player, Boolean> debugees = new HashMap<Player, Boolean>();
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) {

View File

@ -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;
}
}
}
}