New command /wb wrap [world] <on/off> to toggle wrapping for a specific world; requires new permission "worldborder.wrap". Wrapping changed from a global setting to per-world only.

This commit is contained in:
Brettflan 2013-04-14 04:51:57 -05:00
parent 993d52a79c
commit c83b49090b
4 changed files with 88 additions and 19 deletions

View File

@ -16,6 +16,7 @@ public class BorderData
private int radiusX = 0;
private int radiusZ = 0;
private Boolean shapeRound = null;
private boolean wrapping = false;
// some extra data kept handy for faster border checks
private double maxX;
@ -28,6 +29,10 @@ public class BorderData
private double DefiniteRectangleZ;
private double radiusSquaredQuotient;
public BorderData(double x, double z, int radiusX, int radiusZ, Boolean shapeRound, boolean wrap)
{
setData(x, z, radiusX, radiusZ, shapeRound, wrap);
}
public BorderData(double x, double z, int radiusX, int radiusZ)
{
setData(x, z, radiusX, radiusZ, null);
@ -45,22 +50,27 @@ public class BorderData
setData(x, z, radius, shapeRound);
}
public final void setData(double x, double z, int radiusX, int radiusZ, Boolean shapeRound)
public final void setData(double x, double z, int radiusX, int radiusZ, Boolean shapeRound, boolean wrap)
{
this.x = x;
this.z = z;
this.shapeRound = shapeRound;
this.wrapping = wrap;
this.setRadiusX(radiusX);
this.setRadiusZ(radiusZ);
}
public final void setData(double x, double z, int radiusX, int radiusZ, Boolean shapeRound)
{
setData(x, z, radiusZ, radiusZ, shapeRound, false);
}
public final void setData(double x, double z, int radius, Boolean shapeRound)
{
setData(x, z, radius, radius, shapeRound);
setData(x, z, radius, radius, shapeRound, false);
}
public BorderData copy()
{
return new BorderData(x, z, radiusX, radiusZ, shapeRound);
return new BorderData(x, z, radiusX, radiusZ, shapeRound, wrapping);
}
public double getX()
@ -136,10 +146,21 @@ public class BorderData
this.shapeRound = shapeRound;
}
public boolean getWrapping()
{
return wrapping;
}
public void setWrapping(boolean wrap)
{
this.wrapping = wrap;
}
@Override
public String toString()
{
return "radius " + ((radiusX == radiusZ) ? radiusX : radiusX + "x" + radiusZ) + " at X: " + Config.coord.format(x) + " Z: " + Config.coord.format(z) + (shapeRound != null ? (" (shape override: " + Config.ShapeName(shapeRound.booleanValue()) + ")") : "");
return "radius " + ((radiusX == radiusZ) ? radiusX : radiusX + "x" + radiusZ) + " at X: " + Config.coord.format(x) + " Z: " + Config.coord.format(z) + (shapeRound != null ? (" (shape override: " + Config.ShapeName(shapeRound.booleanValue()) + ")") : "") + (wrapping ? (" (wrapping)") : "");
}
// This algorithm of course needs to be fast, since it will be run very frequently
@ -200,7 +221,7 @@ public class BorderData
// square border
if (!round)
{
if (Config.isWrapping())
if (wrapping)
{
if (xLoc <= minX)
xLoc = maxX - Config.KnockBack();
@ -236,7 +257,7 @@ public class BorderData
double dU = Math.sqrt(dX *dX + dZ * dZ); //distance of the untransformed point from the center
double dT = Math.sqrt(dX *dX / radiusXSquared + dZ * dZ / radiusZSquared); //distance of the transformed point from the center
double f = (1 / dT - Config.KnockBack() / dU); //"correction" factor for the distances
if (Config.isWrapping())
if (wrapping)
{
xLoc = x - dX * f;
zLoc = z - dZ * f;

View File

@ -40,7 +40,6 @@ public class Config
private static boolean whooshEffect = false;
private static boolean dynmapEnable = true;
private static String dynmapMessage;
private static boolean isWrapping = false;
// for monitoring plugin efficiency
// public static long timeUsed = 0;
@ -304,10 +303,6 @@ public class Config
LogConfig("Border-checking timed task stopped.");
}
public static boolean isWrapping() {
retirn isWrapping;
}
public static void StopFillTask()
{
if (fillTask != null && fillTask.valid())
@ -405,7 +400,6 @@ public class Config
timerTicks = cfg.getInt("timer-delay-ticks", 5);
dynmapEnable = cfg.getBoolean("dynmap-border-enabled", true);
dynmapMessage = cfg.getString("dynmap-border-message", "The border of the world.");
isWrapping = cfg.getBoolean("wrapping-world", false);
LogConfig("Using " + (ShapeName()) + " border, knockback of " + knockBack + " blocks, and timer delay of " + timerTicks + ".");
StartBorderTimer();
@ -442,7 +436,8 @@ public class Config
}
Boolean overrideShape = (Boolean) bord.get("shape-round");
BorderData border = new BorderData(bord.getDouble("x", 0), bord.getDouble("z", 0), bord.getInt("radiusX", 0), bord.getInt("radiusZ", 0), overrideShape);
boolean wrap = (boolean) bord.getBoolean("wrapping", false);
BorderData border = new BorderData(bord.getDouble("x", 0), bord.getDouble("z", 0), bord.getInt("radiusX", 0), bord.getInt("radiusZ", 0), overrideShape, wrap);
borders.put(worldName, border);
LogConfig(BorderDescription(worldName));
}
@ -488,7 +483,6 @@ public class Config
cfg.set("timer-delay-ticks", timerTicks);
cfg.set("dynmap-border-enabled", dynmapEnable);
cfg.set("dynmap-border-message", dynmapMessage);
cfg.set("wrapping-world", isWrapping);
cfg.set("worlds", null);
Iterator world = borders.entrySet().iterator();
@ -502,6 +496,7 @@ public class Config
cfg.set("worlds." + name + ".z", bord.getZ());
cfg.set("worlds." + name + ".radiusX", bord.getRadiusX());
cfg.set("worlds." + name + ".radiusZ", bord.getRadiusZ());
cfg.set("worlds." + name + ".wrapping", bord.getWrapping());
if (bord.getShape() != null)
cfg.set("worlds." + name + ".shape-round", bord.getShape());

View File

@ -516,6 +516,47 @@ public class WBCommand implements CommandExecutor
sender.sendMessage("Border shape for world \"" + world + "\" is now set to \"" + (shape == null ? "default" : Config.ShapeName(shape.booleanValue())) + "\".");
}
// "wrap" command from player or console, world specified
else if (split.length == 3 && split[0].equalsIgnoreCase("wrap"))
{
if (!Config.HasPermission(player, "wrap")) 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 wrap = strAsBool(split[2]);
border.setWrapping(wrap);
Config.setBorder(world, border);
if (player != null)
sender.sendMessage("Border for world \"" + world + "\" is now set to " + (wrap ? "" : "not ") + "wrap around.");
}
// "wrap" command from player, using current world
else if (split.length == 2 && split[0].equalsIgnoreCase("wrap") && player != null)
{
if (!Config.HasPermission(player, "wrap")) 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 wrap = strAsBool(split[1]);
border.setWrapping(wrap);
Config.setBorder(world, border);
sender.sendMessage("Border for world \"" + world + "\" is now set to " + (wrap ? "" : "not ") + "wrap around.");
}
// "fill" command from player or console, world specified
else if (split.length >= 2 && split[1].equalsIgnoreCase("fill"))
{
@ -710,11 +751,11 @@ public class WBCommand implements CommandExecutor
catch(NumberFormatException ex)
{
}
if (page > 3)
if (page > 4)
page = 1;
}
sender.sendMessage(clrHead + plugin.getDescription().getFullName() + " - commands (" + clrReq + "<required> " + clrOpt + "[optional]" + clrHead + ")" + (page > 0 ? " " + page + "/3" : "") + ":");
sender.sendMessage(clrHead + plugin.getDescription().getFullName() + " - commands (" + clrReq + "<required> " + clrOpt + "[optional]" + clrHead + ")" + (page > 0 ? " " + page + "/4" : "") + ":");
if (page == 0 || page == 1)
{
@ -737,22 +778,29 @@ public class WBCommand implements CommandExecutor
sender.sendMessage(cmdW+" trim " + clrOpt + "[freq] [pad]" + clrDesc + " - trim world outside of border.");
sender.sendMessage(cmd+" bypass " + ((player == null) ? clrReq + "<player>" : clrOpt + "[player]") + clrOpt + " [on/off]" + clrDesc + " - let player go beyond border.");
sender.sendMessage(cmd+" wshape " + ((player == null) ? clrReq + "<world>" : clrOpt + "[world]") + clrReq + " <elliptic|rectangular|default>" + clrDesc + " - shape override for this world.");
// above command takes 2 lines, so only 7 commands total listed for this page
sender.sendMessage(cmd+" wshape " + ((player == null) ? clrReq + "<world>" : clrOpt + "[world]") + clrReq + " <round|square|default>" + clrDesc + " - same as above.");
sender.sendMessage(cmd+" whoosh " + clrReq + "<on|off>" + clrDesc + " - turn knockback effect on or off.");
sender.sendMessage(cmd+" wrap " + ((player == null) ? clrReq + "<world>" : clrOpt + "[world]") + clrReq + " <on/off>" + clrDesc + " - can make border crossings wrap.");
if (page == 2)
sender.sendMessage(cmd+" 3" + clrDesc + " - view third page of commands.");
}
if (page == 0 || page == 3)
{
sender.sendMessage(cmd+" whoosh " + clrReq + "<on|off>" + clrDesc + " - turn knockback effect on or off.");
sender.sendMessage(cmd+" getmsg" + clrDesc + " - display border message.");
sender.sendMessage(cmd+" setmsg " + clrReq + "<text>" + clrDesc + " - set border message.");
sender.sendMessage(cmd+" knockback " + clrReq + "<distance>" + clrDesc + " - how far to move the player back.");
sender.sendMessage(cmd+" delay " + clrReq + "<amount>" + clrDesc + " - time between border checks.");
sender.sendMessage(cmd+" reload" + clrDesc + " - re-load data from config.yml.");
sender.sendMessage(cmd+" dynmap " + clrReq + "<on|off>" + clrDesc + " - turn DynMap border display on or off.");
sender.sendMessage(cmd+" dynmapmsg " + clrReq + "<text>" + clrDesc + " - DynMap border labels will show this.");
sender.sendMessage(cmd+" debug " + clrReq + "<on|off>" + clrDesc + " - turn console debug output on or off.");
if (page == 3)
sender.sendMessage(cmd+" 4" + clrDesc + " - view fourth page of commands.");
}
if (page == 0 || page == 4)
{
sender.sendMessage(cmd+" reload" + clrDesc + " - re-load data from config.yml.");
sender.sendMessage(cmd+" debug " + clrReq + "<on|off>" + clrDesc + " - turn console debug output on or off.");
if (page == 4)
sender.sendMessage(cmd + clrDesc + " - view first page of commands.");
}
}

View File

@ -27,6 +27,7 @@ commands:
/<command> delay <amount> - time between border checks.
/<command> wshape [world] <elliptic|rectangular|default> - override shape.
/<command> wshape [world] <round|square|default> - same as above values.
/<command> wrap [world] <on/off> - can make border crossings wrap around.
/<command> [world] fill [freq] [pad] - generate world out to border.
/<command> [world] trim [freq] [pad] - trim world outside of border.
/<command> bypass [player] [on/off] - let player go beyond border.
@ -56,6 +57,7 @@ permissions:
worldborder.dynmap: true
worldborder.dynmapmsg: true
worldborder.bypass: true
worldborder.wrap: true
worldborder.set:
description: Can set borders for any world
default: op
@ -92,6 +94,9 @@ permissions:
worldborder.wshape:
description: Can set an overriding border shape for a single world
default: op
worldborder.wrap:
description: Can set border crossings to wrap around to the other side of the world
default: op
worldborder.fill:
description: Can fill in (generate) any missing map chunks out to the border
default: op