added direct GroupManager support, several other bits and bobs

This commit is contained in:
Brettflan 2011-04-03 04:40:50 -05:00
parent 450692d439
commit 7378d58405
7 changed files with 95 additions and 86 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@
/lib/Permissions.jar
/nbproject/private
/build
/dist
/dist
/lib/GroupManager.jar

View File

@ -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

View File

@ -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
);
}

View File

@ -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<String, BorderData> borders = new HashMap<String, BorderData>();
private static Map<String, BorderData> borders = Collections.synchronizedMap(new HashMap<String, BorderData>());
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;
}

View File

@ -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 + "<world>" : "/wborder " + ChatColor.DARK_AQUA + "[world]") + ChatColor.AQUA;
String cmdW = ChatColor.AQUA + ((player == null) ? "wborder " + ChatColor.DARK_GREEN + "<world>" : "/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 + "<required>" + ChatColor.WHITE + "):");
sender.sendMessage(ChatColor.WHITE + plugin.getDescription().getFullName() + " - commands (" + (player != null ? ChatColor.GREEN + "[optional] " : "") + ChatColor.DARK_GREEN + "<required>" + ChatColor.WHITE + "):");
if (player != null)
sender.sendMessage(cmd+" set " + ChatColor.GREEN + "<radius>" + ChatColor.WHITE + " - set world border, centered on you.");
sender.sendMessage(cmdW+" set " + ChatColor.GREEN + "<radius> <x> <z>" + ChatColor.WHITE + " - set world border.");
sender.sendMessage(cmdW+" radius " + ChatColor.GREEN + "<radius>" + ChatColor.WHITE + " - change border radius for this world.");
sender.sendMessage(cmd+" set " + ChatColor.DARK_GREEN + "<radius>" + ChatColor.WHITE + " - set world border, centered on you.");
sender.sendMessage(cmdW+" set " + ChatColor.DARK_GREEN + "<radius> <x> <z>" + ChatColor.WHITE + " - set world border.");
sender.sendMessage(cmdW+" radius " + ChatColor.DARK_GREEN + "<radius>" + 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 + "<round|square>" + ChatColor.WHITE + " - set the border shape.");
sender.sendMessage(cmd+" shape " + ChatColor.DARK_GREEN + "<round|square>" + ChatColor.WHITE + " - set the border shape.");
sender.sendMessage(cmd+" getmsg" + ChatColor.WHITE + " - display border message.");
sender.sendMessage(cmd+" setmsg " + ChatColor.GREEN + "<text>" + ChatColor.WHITE + " - set border message.");
if (player != null)
sender.sendMessage(cmd+" setmsg " + ChatColor.DARK_GREEN + "<text>" + ChatColor.WHITE + " - set border message.");
if (player == null)
sender.sendMessage(cmd+" reload" + ChatColor.WHITE + " - re-load data from config.yml.");
}

View File

@ -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;
}
}

View File

@ -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:
/<command> - list available commands (show help).
/<command> set <radius> - set world border, centered on you.
/<command> [world] set <radius> <x> <z> - set world border.
/<command> radius <radius> - change border radius for this world.
/<command> [world] radius <radius> - change world's border radius.
/<command> [world] clear - remove border for this world.
/<command> clear all - remove border for all worlds.
/<command> list - show border information for all worlds.