From 2e7978f890e635ec42f8dde5136aeeba1b5e3615 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 3 Apr 2011 23:51:57 -0500 Subject: [PATCH] made debug option configurable as well, changed text colors for optional/required command values, updated README.md --- README.md | 12 ++++++- src/com/wimbli/WorldBorder/Config.java | 16 ++++++++- src/com/wimbli/WorldBorder/WBCommand.java | 33 ++++++++++++++----- .../wimbli/WorldBorder/WBPlayerListener.java | 6 ++-- src/plugin.yml | 2 +- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3042383..27d8938 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,14 @@ WorldBorder =========== -A Bukkit plugin to provide borders for your worlds, to limit their sizes. \ No newline at end of file +A Bukkit plugin to provide borders for your worlds, to limit their sizes. + +Description +=========== + +This plugin is intended to be able to supersede BorderGuard Lite and rBorder in functionality, and to impact server performance as little as possible, hopefully very close to being on par with rBorder. And, like rBorder, the source is available. Configuration and border setup is done using commands in-game or through the server console. All commands support GroupManager and Permissions plugin, so you can use either to set up command permissions. + +More Info +========= + +Bukkit Forum discussion: \ No newline at end of file diff --git a/src/com/wimbli/WorldBorder/Config.java b/src/com/wimbli/WorldBorder/Config.java index c9de524..57aeec1 100644 --- a/src/com/wimbli/WorldBorder/Config.java +++ b/src/com/wimbli/WorldBorder/Config.java @@ -30,12 +30,12 @@ public class Config private static GroupManager GroupPlugin = null; private static final Logger mcLog = Logger.getLogger("Minecraft"); public static DecimalFormat coord = new DecimalFormat("0.0"); - public static final boolean DEBUG = false; // actual configuration values which can be changed private static boolean shapeRound = false; private static Map borders = Collections.synchronizedMap(new HashMap()); private static String message; + private static boolean DEBUG = false; public static void setBorder(String world, BorderData border) { @@ -113,6 +113,18 @@ public class Config return shapeRound; } + public static void setDebug(boolean debugMode) + { + DEBUG = debugMode; + Log("Debug mode " + (DEBUG ? "enabled" : "disabled") + "."); + save(true); + } + + public static boolean Debug() + { + return DEBUG; + } + public static void loadPermissions(WorldBorder plugin) { if (GroupPlugin != null || Permissions != null || plugin == null) @@ -193,6 +205,7 @@ public class Config message = cfg.getString("message"); shapeRound = cfg.getBoolean("round-border", false); LogConfig("Using " + (shapeRound ? "round" : "square") + " border shape."); + DEBUG = cfg.getBoolean("debug-mode", false); borders.clear(); @@ -228,6 +241,7 @@ public class Config cfg.setProperty("message", message); cfg.setProperty("round-border", shapeRound); + cfg.setProperty("debug-mode", DEBUG); cfg.removeProperty("worlds"); Iterator world = borders.entrySet().iterator(); diff --git a/src/com/wimbli/WorldBorder/WBCommand.java b/src/com/wimbli/WorldBorder/WBCommand.java index e161804..731d579 100644 --- a/src/com/wimbli/WorldBorder/WBCommand.java +++ b/src/com/wimbli/WorldBorder/WBCommand.java @@ -23,8 +23,8 @@ public class WBCommand implements CommandExecutor { Player player = (sender instanceof Player) ? (Player)sender : null; - String cmd = ChatColor.AQUA + ((player == null) ? "wborder" : "/wborder"); - String cmdW = ChatColor.AQUA + ((player == null) ? "wborder " + ChatColor.DARK_GREEN + "" : "/wborder " + ChatColor.GREEN + "[world]") + ChatColor.AQUA; + String cmd = ChatColor.AQUA + ((player == null) ? "wb" : "/wb"); + String cmdW = ChatColor.AQUA + ((player == null) ? "wb " + ChatColor.GREEN + "" : "/wb " + ChatColor.DARK_GREEN + "[world]") + ChatColor.AQUA; // "set" command from player or console, world specified if (split.length == 5 && split[1].equalsIgnoreCase("set")) @@ -271,24 +271,41 @@ public class WBCommand implements CommandExecutor sender.sendMessage("WorldBorder configuration reloaded."); } + // "debug" command from player or console + else if (split.length == 2 && split[0].equalsIgnoreCase("debug")) + { + if (!Config.HasPermission(player, "debug")) return true; + + Config.setDebug(split[1].equalsIgnoreCase("on")); + + if (player != null) + Config.Log((Config.Debug() ? "Enabling" : "Disabling") + " debug output at the command of player \"" + player.getName() + "\"."); + + if (player != null) + sender.sendMessage("Debug mode " + (Config.Debug() ? "enabled" : "disabled") + "."); + } + // we couldn't decipher any known commands, so show help else { if (!Config.HasPermission(player, "help")) return true; - sender.sendMessage(ChatColor.WHITE + plugin.getDescription().getFullName() + " - commands (" + (player != null ? ChatColor.GREEN + "[optional] " : "") + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + "):"); + sender.sendMessage(ChatColor.WHITE + plugin.getDescription().getFullName() + " - commands (" + (player != null ? ChatColor.DARK_GREEN + "[optional] " : "") + ChatColor.GREEN + "" + ChatColor.WHITE + "):"); if (player != null) - sender.sendMessage(cmd+" set " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - set world border, centered on you."); - sender.sendMessage(cmdW+" set " + ChatColor.DARK_GREEN + " " + ChatColor.WHITE + " - set world border."); - sender.sendMessage(cmdW+" radius " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - change a border radius."); + sender.sendMessage(cmd+" set " + ChatColor.GREEN + "" + ChatColor.WHITE + " - set world border, centered on you."); + sender.sendMessage(cmdW+" set " + ChatColor.GREEN + " " + ChatColor.WHITE + " - set world border."); + sender.sendMessage(cmdW+" radius " + ChatColor.GREEN + "" + ChatColor.WHITE + " - change a border radius."); sender.sendMessage(cmdW+" clear" + ChatColor.WHITE + " - remove border for this world."); sender.sendMessage(cmd+" clear all" + ChatColor.WHITE + " - remove border for all worlds."); sender.sendMessage(cmd+" list" + ChatColor.WHITE + " - show border information for all worlds."); - sender.sendMessage(cmd+" shape " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - set the border shape."); + sender.sendMessage(cmd+" shape " + ChatColor.GREEN + "" + ChatColor.WHITE + " - set the border shape."); sender.sendMessage(cmd+" getmsg" + ChatColor.WHITE + " - display border message."); - sender.sendMessage(cmd+" setmsg " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - set border message."); + sender.sendMessage(cmd+" setmsg " + ChatColor.GREEN + "" + ChatColor.WHITE + " - set border message."); if (player == null) + { sender.sendMessage(cmd+" reload" + ChatColor.WHITE + " - re-load data from config.yml."); + sender.sendMessage(cmd+" debug " + ChatColor.GREEN + "" + ChatColor.WHITE + " - turn console debug output on or off."); + } } return true; diff --git a/src/com/wimbli/WorldBorder/WBPlayerListener.java b/src/com/wimbli/WorldBorder/WBPlayerListener.java index b44d092..d2a224e 100644 --- a/src/com/wimbli/WorldBorder/WBPlayerListener.java +++ b/src/com/wimbli/WorldBorder/WBPlayerListener.java @@ -95,7 +95,7 @@ public class WBPlayerListener extends PlayerListener private static Location newLocation(Player player, Location loc, BorderData border) { - if (Config.DEBUG) + if (Config.Debug()) { Config.LogWarn("Border crossing. Border " + border.toString()); Config.LogWarn("Player position X: " + Config.coord.format(loc.getX()) + " Y: " + Config.coord.format(loc.getY()) + " Z: " + Config.coord.format(loc.getZ())); @@ -106,12 +106,12 @@ public class WBPlayerListener extends PlayerListener // it's remotely possible (such as in the Nether) a suitable location isn't available, in which case... if (newLoc == null) { - if (Config.DEBUG) + if (Config.Debug()) Config.LogWarn("Target new location unviable, using spawn."); newLoc = player.getServer().getWorlds().get(0).getSpawnLocation(); } - if (Config.DEBUG) + if (Config.Debug()) Config.LogWarn("New position X: " + Config.coord.format(newLoc.getX()) + " Y: " + Config.coord.format(newLoc.getY()) + " Z: " + Config.coord.format(newLoc.getZ())); player.sendMessage(ChatColor.RED + Config.Message()); diff --git a/src/plugin.yml b/src/plugin.yml index 514e504..cde72f9 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,7 @@ name: WorldBorder author: Brettflan description: Limit the size of your worlds with a border, round or square. -version: 0.9 PRE-RELEASE +version: 0.9 DEV main: com.wimbli.WorldBorder.WorldBorder commands: wborder: