diff --git a/src/com/wimbli/WorldBorder/BorderData.java b/src/com/wimbli/WorldBorder/BorderData.java index bec7d9f..2c4cec2 100644 --- a/src/com/wimbli/WorldBorder/BorderData.java +++ b/src/com/wimbli/WorldBorder/BorderData.java @@ -13,6 +13,7 @@ public class BorderData private double x = 0; private double z = 0; private int radius = 0; + private Boolean shapeRound = null; // some extra data kept handy for faster border checks private double maxX; @@ -23,6 +24,14 @@ public class BorderData private double DefiniteSquare; public BorderData(double x, double z, int radius) + { + setData(x, z, radius, null); + } + public BorderData(double x, double z, int radius, Boolean shapeRound) + { + setData(x, z, radius, shapeRound); + } + public void setData(double x, double z, int radius, Boolean shapeRound) { this.x = x; this.z = z; @@ -32,6 +41,7 @@ public class BorderData this.maxZ = z + radius; this.minZ = z - radius; this.radiusSquared = radius * radius; + this.shapeRound = shapeRound; this.DefiniteSquare = Math.sqrt(.5 * this.radiusSquared); } @@ -70,15 +80,28 @@ public class BorderData this.DefiniteSquare = Math.sqrt(.5 * this.radiusSquared); } + public Boolean getShape() + { + return shapeRound; + } + public void setShape(Boolean shapeRound) + { + this.shapeRound = shapeRound; + } + @Override public String toString() { - return "radius " + radius + " at X: " + Config.coord.format(x) + " Z: " + Config.coord.format(z); + return "radius " + radius + " at X: " + Config.coord.format(x) + " Z: " + Config.coord.format(z) + (shapeRound != null ? (" (shape override: " + (shapeRound.booleanValue() ? "round" : "square") + ")") : ""); } // 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 this border has a shape override set, use it + if (shapeRound != null) + round = shapeRound.booleanValue(); + // square border if (!round) return !(xLoc < minX || xLoc > maxX || zLoc < minZ || zLoc > maxZ); @@ -103,6 +126,10 @@ public class BorderData public Location correctedPosition(Location loc, boolean round) { + // if this border has a shape override set, use it + if (shapeRound != null) + round = shapeRound.booleanValue(); + double xLoc = loc.getX(); double zLoc = loc.getZ(); double yLoc = loc.getY(); @@ -159,11 +186,12 @@ public class BorderData ); } + static final private int limTop = 120, limBot = 1; + // find closest safe Y position from the starting position private double getSafeY(World world, int X, int Y, int Z) { // Expanding Y search method adapted from Acru's code in the Nether plugin - int limTop = 120, limBot = 1; for(int y1 = Y, y2 = Y; (y1 > limBot) || (y2 < limTop); y1--, y2++){ // Look below. diff --git a/src/com/wimbli/WorldBorder/Config.java b/src/com/wimbli/WorldBorder/Config.java index 3dd9cb4..79c4c3d 100644 --- a/src/com/wimbli/WorldBorder/Config.java +++ b/src/com/wimbli/WorldBorder/Config.java @@ -56,9 +56,15 @@ public class Config Log("Border set. " + BorderDescription(world)); save(true); } + public static void setBorder(String world, int radius, double x, double z, Boolean shapeRound) + { + setBorder(world, new BorderData(x, z, radius, shapeRound)); + } public static void setBorder(String world, int radius, double x, double z) { - setBorder(world, new BorderData(x, z, radius)); + BorderData old = Border(world); + Boolean oldShape = (old == null) ? null : old.getShape(); + setBorder(world, new BorderData(x, z, radius, oldShape)); } public static void removeBorder(String world) @@ -117,7 +123,7 @@ public class Config public static void setShape(boolean round) { shapeRound = round; - Log("Set border shape to " + (round ? "round" : "square") + "."); + Log("Set default border shape to " + (round ? "round" : "square") + "."); save(true); } @@ -302,7 +308,8 @@ public class Config name = ((String)wdata.getKey()).replace("/", "."); ConfigurationNode bord = (ConfigurationNode)wdata.getValue(); - BorderData border = new BorderData(bord.getDouble("x", 0), bord.getDouble("z", 0), bord.getInt("radius", 0)); + Boolean overrideShape = (Boolean) bord.getProperty("shape-round"); + BorderData border = new BorderData(bord.getDouble("x", 0), bord.getDouble("z", 0), bord.getInt("radius", 0), overrideShape); borders.put(name, border); LogConfig(BorderDescription(name)); } @@ -333,9 +340,13 @@ public class Config Entry wdata = (Entry)world.next(); String name = (String)wdata.getKey(); BorderData bord = (BorderData)wdata.getValue(); + cfg.setProperty("worlds." + name.replace(".", "¨") + ".x", bord.getX()); cfg.setProperty("worlds." + name.replace(".", "¨") + ".z", bord.getZ()); cfg.setProperty("worlds." + name.replace(".", "¨") + ".radius", bord.getRadius()); + + if (bord.getShape() != null) + cfg.setProperty("worlds." + name.replace(".", "¨") + ".shape-round", bord.getShape()); } cfg.save(); diff --git a/src/com/wimbli/WorldBorder/WBCommand.java b/src/com/wimbli/WorldBorder/WBCommand.java index bebb93f..468f2f1 100644 --- a/src/com/wimbli/WorldBorder/WBCommand.java +++ b/src/com/wimbli/WorldBorder/WBCommand.java @@ -190,7 +190,7 @@ public class WBCommand implements CommandExecutor { if (!Config.HasPermission(player, "list")) return true; - sender.sendMessage("Border shape for all worlds is \"" + (Config.ShapeRound() ? "round" : "square") + "\"."); + sender.sendMessage("Default border shape for all worlds is \"" + (Config.ShapeRound() ? "round" : "square") + "\"."); Set list = Config.BorderDescriptions(); @@ -223,7 +223,7 @@ public class WBCommand implements CommandExecutor } if (player != null) - sender.sendMessage("Border shape for all worlds is now set to \"" + (Config.ShapeRound() ? "round" : "square") + "\"."); + sender.sendMessage("Default border shape for all worlds is now set to \"" + (Config.ShapeRound() ? "round" : "square") + "\"."); } // "getmsg" command from player or console @@ -340,6 +340,57 @@ public class WBCommand implements CommandExecutor sender.sendMessage("Timer delay set to " + delay + " tick(s). That is roughly " + (delay * 50) + "ms."); } + // "wshape" command from player or console, world specified + else if (split.length == 3 && split[0].equalsIgnoreCase("wshape")) + { + if (!Config.HasPermission(player, "wshape")) return true; + + String world = split[1]; + BorderData border = Config.Border(world); + if (border == null) + { + sender.sendMessage("The world you specified (\"" + world + "\") does not have a border set."); + return true; + } + + Boolean shape = null; + if (split[2].equalsIgnoreCase("square")) + shape = false; + else if (split[2].equalsIgnoreCase("round")) + shape = true; + + border.setShape(shape); + Config.setBorder(world, border); + + if (player != null) + sender.sendMessage("Border shape for world \"" + world + "\" is now set to \"" + (shape == null ? "default" : (shape.booleanValue() ? "round" : "square")) + "\"."); + } + + // "wshape" command from player, using current world + else if (split.length == 2 && split[0].equalsIgnoreCase("wshape") && player != null) + { + if (!Config.HasPermission(player, "wshape")) return true; + + String world = player.getWorld().getName(); + BorderData border = Config.Border(world); + if (border == null) + { + sender.sendMessage("This world (\"" + world + "\") does not have a border set."); + return true; + } + + Boolean shape = null; + if (split[1].equalsIgnoreCase("square")) + shape = false; + else if (split[1].equalsIgnoreCase("round")) + shape = true; + + border.setShape(shape); + Config.setBorder(world, border); + + sender.sendMessage("Border shape for world \"" + world + "\" is now set to \"" + (shape == null ? "default" : (shape.booleanValue() ? "round" : "square")) + "\"."); + } + // we couldn't decipher any known commands, so show help else { @@ -370,7 +421,7 @@ public class WBCommand implements CommandExecutor 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.GREEN + "" + ChatColor.WHITE + " - set the default border shape."); sender.sendMessage(cmd+" knockback " + ChatColor.GREEN + "" + ChatColor.WHITE + " - how far to move the player back."); if (page == 1) sender.sendMessage(cmd+" 2" + ChatColor.WHITE + " - view second page of commands."); @@ -378,6 +429,7 @@ public class WBCommand implements CommandExecutor if (page == 0 || page == 2) { + sender.sendMessage(cmd+" wshape " + ((player == null) ? ChatColor.GREEN + "" : ChatColor.DARK_GREEN + "[world]") + ChatColor.GREEN + " " + ChatColor.WHITE + " - shape override."); sender.sendMessage(cmd+" getmsg" + ChatColor.WHITE + " - display border message."); sender.sendMessage(cmd+" setmsg " + ChatColor.GREEN + "" + ChatColor.WHITE + " - set border message."); sender.sendMessage(cmd+" delay " + ChatColor.GREEN + "" + ChatColor.WHITE + " - time between border checks."); diff --git a/src/plugin.yml b/src/plugin.yml index b9d7bc2..84792f2 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: 1.1.2 +description: Efficient, feature-rich plugin for limiting the size of your worlds. +version: 1.2 main: com.wimbli.WorldBorder.WorldBorder commands: wborder: @@ -15,8 +15,9 @@ commands: / [world] clear - remove border for this world. / clear all - remove border for all worlds. / list - show border information for all worlds. - / shape - set the border shape. + / shape - set the default border shape. / getmsg - display border message. / setmsg - set border message. / knockback - how far to move the player back. - / delay - time between border checks. \ No newline at end of file + / delay - time between border checks. + / wshape [world] - override shape. \ No newline at end of file