diff --git a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java index 408e6a684a..4196188ec6 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlayerListener.java @@ -53,15 +53,21 @@ public class SamplePlayerListener extends PlayerListener { player.sendMessage("Usage: '/pos' to get current position, or '/pos x y z' to teleport to x,y,z"); } + event.setCancelled(true); + } else if (split[0].equalsIgnoreCase("/debug")) { + plugin.setDebugging(player, !plugin.isDebugging(player)); + event.setCancelled(true); } } @Override public void onPlayerMove(PlayerMoveEvent event) { - Location from = event.getFrom(); - Location to = event.getTo(); + if (plugin.isDebugging(event.getPlayer())) { + Location from = event.getFrom(); + Location to = event.getTo(); - System.out.println(String.format("From %2$f,%2$f,%2$f to %2$f,%2$f,%2$f", from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ())); + System.out.println(String.format("From %.2f,%.2f,%.2f to %.2f,%.2f,%.2f", from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ())); + } } } 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 2c623670ab..f0782d099e 100644 --- a/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java +++ b/paper-api/sample/src/com/dinnerbone/bukkit/sample/SamplePlugin.java @@ -2,6 +2,8 @@ package com.dinnerbone.bukkit.sample; import java.io.File; +import java.util.HashMap; +import org.bukkit.Player; import org.bukkit.Server; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event; @@ -16,12 +18,11 @@ import org.bukkit.plugin.java.JavaPlugin; */ public class SamplePlugin extends JavaPlugin { private final SamplePlayerListener playerListener = new SamplePlayerListener(this); + private final HashMap debugees = new HashMap(); public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { super(pluginLoader, instance, desc, plugin, cLoader); - System.out.println("Johnny five is alive!"); - registerEvents(); } @@ -39,4 +40,16 @@ public class SamplePlugin extends JavaPlugin { getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this); getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); } + + public boolean isDebugging(final Player player) { + if (debugees.containsKey(player)) { + return debugees.get(player); + } else { + return false; + } + } + + public void setDebugging(final Player player, final boolean value) { + debugees.put(player, value); + } }