mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
Updated sample plugin to test physics
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
ddd950ae40
commit
4124f9e7bb
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
*/
|
*/
|
||||||
public class SamplePlugin extends JavaPlugin {
|
public class SamplePlugin extends JavaPlugin {
|
||||||
private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
|
private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
|
||||||
|
private final SampleBlockListener blockListener = new SampleBlockListener(this);
|
||||||
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
|
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
|
||||||
|
|
||||||
public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
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_QUIT, playerListener, Priority.Normal, this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, 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.PLAYER_MOVE, playerListener, Priority.Normal, this);
|
||||||
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PHYSICS, blockListener, Priority.Normal, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDebugging(final Player player) {
|
public boolean isDebugging(final Player player) {
|
||||||
|
@ -14,6 +14,8 @@ import java.util.regex.Pattern;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
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.event.player.*;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
@ -103,6 +105,14 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||||||
trueListener.onPlayerLogin((PlayerLoginEvent)event);
|
trueListener.onPlayerLogin((PlayerLoginEvent)event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (listener instanceof BlockListener) {
|
||||||
|
BlockListener trueListener = (BlockListener)listener;
|
||||||
|
|
||||||
|
switch (event.getType()) {
|
||||||
|
case BLOCK_PHYSICS:
|
||||||
|
trueListener.onBlockPhysics((BlockPhysicsEvent)event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user