From 7378d58405988bd6fd9f15d78f603b2387b7bd79 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 3 Apr 2011 04:40:50 -0500 Subject: [PATCH] added direct GroupManager support, several other bits and bobs --- .gitignore | 3 +- nbproject/project.properties | 4 +- src/com/wimbli/WorldBorder/BorderData.java | 26 +++--- src/com/wimbli/WorldBorder/Config.java | 35 ++++++-- src/com/wimbli/WorldBorder/WBCommand.java | 22 ++--- .../wimbli/WorldBorder/WBPlayerListener.java | 87 +++++++------------ src/plugin.yml | 4 +- 7 files changed, 95 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index 44adc68..95c35ea 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /lib/Permissions.jar /nbproject/private /build -/dist \ No newline at end of file +/dist +/lib/GroupManager.jar \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties index 1e83715..037c94e 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -28,12 +28,14 @@ endorsed.classpath= excludes= file.reference.CalcTest-src=src file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=lib/craftbukkit-0.0.1-SNAPSHOT.jar +file.reference.GroupManager.jar=lib\\GroupManager.jar file.reference.Permissions.jar=lib/Permissions.jar includes=** jar.compress=true javac.classpath=\ ${file.reference.craftbukkit-0.0.1-SNAPSHOT.jar}:\ - ${file.reference.Permissions.jar} + ${file.reference.Permissions.jar}:\ + ${file.reference.GroupManager.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/com/wimbli/WorldBorder/BorderData.java b/src/com/wimbli/WorldBorder/BorderData.java index 5b41957..f5b3a42 100644 --- a/src/com/wimbli/WorldBorder/BorderData.java +++ b/src/com/wimbli/WorldBorder/BorderData.java @@ -80,11 +80,14 @@ public class BorderData // This algorithm of course needs to be fast, since it will be run very frequently public boolean insideBorder(double xLoc, double zLoc, boolean round) { - if (!round) // square border - return (xLoc > minX && xLoc < maxX && zLoc > minZ && zLoc < maxZ); - else // round border + // square border + if (!round) + return !(xLoc < minX || xLoc > maxX || zLoc < minZ || zLoc > maxZ); + + // round border + else { - // round border checking algorithm is from rBorder by Reil with almost no changes, thanks + // elegant round border checking algorithm is from rBorder by Reil with almost no changes, all credit to him for it double X = Math.abs(x - xLoc); double Z = Math.abs(z - zLoc); @@ -93,7 +96,7 @@ public class BorderData else if (X >= radius || Z >= radius) return false; // Definitely outside else if (X * X + Z * Z < radiusSquared) - return true; // After much calculation, inside + return true; // After further calculation, inside else return false; // Apparently outside, then } @@ -105,7 +108,8 @@ public class BorderData double zLoc = loc.getZ(); double yLoc = loc.getY(); - if (!round) // square border + // square border + if (!round) { if (xLoc <= minX) xLoc = minX + 3; @@ -116,7 +120,9 @@ public class BorderData else if (zLoc >= maxZ) zLoc = maxZ - 3; } - else // round border + + // round border + else { // algorithm from: http://stackoverflow.com/questions/300871/best-way-to-find-a-point-on-a-circle-closest-to-a-given-point double vX = xLoc - x; @@ -147,9 +153,9 @@ public class BorderData private boolean isSafeSpot(World world, int X, int Y, int Z) { Integer below = (Integer)world.getBlockAt(X, Y - 1, Z).getTypeId(); - return (acceptableBlocks.contains((Integer)world.getBlockAt(X, Y, Z).getTypeId()) // target block breatheable - && acceptableBlocks.contains((Integer)world.getBlockAt(X, Y + 1, Z).getTypeId()) // above target block breathable - && !acceptableBlocks.contains(below) // below target block not breathable (probably solid) + return (acceptableBlocks.contains((Integer)world.getBlockAt(X, Y, Z).getTypeId()) // target block breathable, or is water + && acceptableBlocks.contains((Integer)world.getBlockAt(X, Y + 1, Z).getTypeId()) // above target block breathable, or is water + && (!acceptableBlocks.contains(below) || below == 8 || below == 9) // below target block not breathable (probably solid), or is water && !painfulBlocks.contains(below) // below target block not something painful ); } diff --git a/src/com/wimbli/WorldBorder/Config.java b/src/com/wimbli/WorldBorder/Config.java index 51d8018..c9de524 100644 --- a/src/com/wimbli/WorldBorder/Config.java +++ b/src/com/wimbli/WorldBorder/Config.java @@ -1,6 +1,7 @@ package com.wimbli.WorldBorder; import java.text.DecimalFormat; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -15,6 +16,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.util.config.Configuration; import org.bukkit.util.config.ConfigurationNode; +import org.anjocaido.groupmanager.GroupManager; import com.nijiko.permissions.PermissionHandler; import com.nijikokun.bukkit.Permissions.Permissions; @@ -25,13 +27,14 @@ public class Config private static WorldBorder plugin; private static Configuration cfg = null; private static PermissionHandler Permissions = null; + 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 = new HashMap(); + private static Map borders = Collections.synchronizedMap(new HashMap()); private static String message; public static void setBorder(String world, BorderData border) @@ -112,10 +115,24 @@ public class Config public static void loadPermissions(WorldBorder plugin) { - if (Permissions != null || plugin == null) + if (GroupPlugin != null || Permissions != null || plugin == null) return; - Plugin test = plugin.getServer().getPluginManager().getPlugin("Permissions"); + // try GroupManager first + Plugin test = plugin.getServer().getPluginManager().getPlugin("GroupManager"); + + if (test != null) + { + if (!test.isEnabled()) { + plugin.getServer().getPluginManager().enablePlugin(test); + } + GroupPlugin = (GroupManager) test; + LogConfig("Will use plugin for permissions: "+((GroupManager)test).getDescription().getFullName()); + return; + } + + // if GroupManager isn't available, try Permissions + test = plugin.getServer().getPluginManager().getPlugin("Permissions"); if (test != null) { @@ -132,9 +149,17 @@ public class Config return true; else if (player.isOp()) // Op, always permitted return true; - else if (Permissions == null // Permissions plugin not available, or doesn't have permission - || !Permissions.permission(player, "worldborder." + request)) + else if (GroupPlugin != null) // GroupManager plugin available { + if (GroupPlugin.getWorldsHolder().getWorldPermissions(player).has(player, "worldborder." + request)) + return true; + player.sendMessage("You do not have sufficient permissions to do that."); + return false; + } + else if (Permissions != null) // Permissions plugin available + { + if (Permissions.permission(player, "worldborder." + request)) + return true; player.sendMessage("You do not have sufficient permissions to do that."); return false; } diff --git a/src/com/wimbli/WorldBorder/WBCommand.java b/src/com/wimbli/WorldBorder/WBCommand.java index fe2be7b..e161804 100644 --- a/src/com/wimbli/WorldBorder/WBCommand.java +++ b/src/com/wimbli/WorldBorder/WBCommand.java @@ -24,7 +24,7 @@ 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.GREEN + "" : "/wborder " + ChatColor.DARK_AQUA + "[world]") + ChatColor.AQUA; + String cmdW = ChatColor.AQUA + ((player == null) ? "wborder " + ChatColor.DARK_GREEN + "" : "/wborder " + ChatColor.GREEN + "[world]") + ChatColor.AQUA; // "set" command from player or console, world specified if (split.length == 5 && split[1].equalsIgnoreCase("set")) @@ -93,7 +93,7 @@ public class WBCommand implements CommandExecutor int radius; try { - radius = Integer.parseInt(split[1]); + radius = Integer.parseInt(split[2]); } catch(NumberFormatException ex) { @@ -102,7 +102,9 @@ public class WBCommand implements CommandExecutor } Config.setBorder(world, radius, x, z); - sender.sendMessage("Radius has been set. " + Config.BorderDescription(world)); + + if (player != null) + sender.sendMessage("Radius has been set. " + Config.BorderDescription(world)); } // "radius" command from player, using current world @@ -274,18 +276,18 @@ public class WBCommand implements CommandExecutor { if (!Config.HasPermission(player, "help")) return true; - sender.sendMessage(ChatColor.WHITE + plugin.getDescription().getFullName() + " - commands (" + (player != null ? ChatColor.DARK_AQUA + "[optional] " : "") + ChatColor.GREEN + "" + ChatColor.WHITE + "):"); + sender.sendMessage(ChatColor.WHITE + plugin.getDescription().getFullName() + " - commands (" + (player != null ? ChatColor.GREEN + "[optional] " : "") + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + "):"); if (player != null) - 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 border radius for this world."); + 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(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.GREEN + "" + ChatColor.WHITE + " - set the border shape."); + sender.sendMessage(cmd+" shape " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - set the border shape."); sender.sendMessage(cmd+" getmsg" + ChatColor.WHITE + " - display border message."); - sender.sendMessage(cmd+" setmsg " + ChatColor.GREEN + "" + ChatColor.WHITE + " - set border message."); - if (player != null) + sender.sendMessage(cmd+" setmsg " + ChatColor.DARK_GREEN + "" + ChatColor.WHITE + " - set border message."); + if (player == null) sender.sendMessage(cmd+" reload" + ChatColor.WHITE + " - re-load data from config.yml."); } diff --git a/src/com/wimbli/WorldBorder/WBPlayerListener.java b/src/com/wimbli/WorldBorder/WBPlayerListener.java index 1797ff3..b44d092 100644 --- a/src/com/wimbli/WorldBorder/WBPlayerListener.java +++ b/src/com/wimbli/WorldBorder/WBPlayerListener.java @@ -25,26 +25,8 @@ public class WBPlayerListener extends PlayerListener if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return; - 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())); - } + Location newLoc = newLocation(player, loc, border); - Location newLoc = border.correctedPosition(loc, Config.ShapeRound()); - - // it's remotely possible (such as in the Nether) a suitable location isn't available, in which case... - if (newLoc == null) - { - if (Config.DEBUG) - Config.LogWarn("Target new location unviable, using spawn."); - newLoc = player.getServer().getWorlds().get(0).getSpawnLocation(); - } - - 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()); player.teleport(newLoc); } @@ -65,25 +47,7 @@ public class WBPlayerListener extends PlayerListener if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return; - 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())); - } - - Location newLoc = border.correctedPosition(loc, Config.ShapeRound()); - - if (newLoc == null) - { - if (Config.DEBUG) - Config.LogWarn("Target new location unviable, using spawn."); - newLoc = player.getServer().getWorlds().get(0).getSpawnLocation(); - } - - 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()); + Location newLoc = newLocation(player, loc, border); if (!player.isInsideVehicle()) player.teleport(newLoc); @@ -114,25 +78,7 @@ public class WBPlayerListener extends PlayerListener if (border.insideBorder(loc.getX(), loc.getZ(), Config.ShapeRound())) return; - 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())); - } - - Location newLoc = border.correctedPosition(loc, Config.ShapeRound()); - - if (newLoc == null) - { - if (Config.DEBUG) - Config.LogWarn("Target new location unviable, using spawn."); - newLoc = player.getServer().getWorlds().get(0).getSpawnLocation(); - } - - 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()); + Location newLoc = newLocation(player, loc, border); if (!player.isInsideVehicle()) player.teleport(newLoc); @@ -145,4 +91,31 @@ public class WBPlayerListener extends PlayerListener event.setTo(newLoc); } + + + private static Location newLocation(Player player, Location loc, BorderData border) + { + 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())); + } + + Location newLoc = border.correctedPosition(loc, Config.ShapeRound()); + + // it's remotely possible (such as in the Nether) a suitable location isn't available, in which case... + if (newLoc == null) + { + if (Config.DEBUG) + Config.LogWarn("Target new location unviable, using spawn."); + newLoc = player.getServer().getWorlds().get(0).getSpawnLocation(); + } + + 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()); + + return newLoc; + } } diff --git a/src/plugin.yml b/src/plugin.yml index aa05bcb..514e504 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 +version: 0.9 PRE-RELEASE main: com.wimbli.WorldBorder.WorldBorder commands: wborder: @@ -11,7 +11,7 @@ commands: / - list available commands (show help). / set - set world border, centered on you. / [world] set - set world border. - / radius - change border radius for this world. + / [world] radius - change world's border radius. / [world] clear - remove border for this world. / clear all - remove border for all worlds. / list - show border information for all worlds.