mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
Added debugging tools to sampleplugin
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
5ca171b422
commit
7e203ee761
2 changed files with 24 additions and 5 deletions
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Player, Boolean> debugees = new HashMap<Player, Boolean>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue