Added debugging tools to sampleplugin

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-30 20:33:48 +00:00
parent 5ca171b422
commit 7e203ee761
2 changed files with 24 additions and 5 deletions

View file

@ -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"); 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); event.setCancelled(true);
} }
} }
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom(); if (plugin.isDebugging(event.getPlayer())) {
Location to = event.getTo(); 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()));
}
} }
} }

View file

@ -2,6 +2,8 @@
package com.dinnerbone.bukkit.sample; package com.dinnerbone.bukkit.sample;
import java.io.File; import java.io.File;
import java.util.HashMap;
import org.bukkit.Player;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -16,12 +18,11 @@ 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 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) {
super(pluginLoader, instance, desc, plugin, cLoader); super(pluginLoader, instance, desc, plugin, cLoader);
System.out.println("Johnny five is alive!");
registerEvents(); 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_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);
} }
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);
}
} }