mirror of
https://github.com/Brettflan/WorldBorder.git
synced 2025-02-12 17:41:26 +01:00
added ability to override shape (round/square) of individual worlds with new /wb wshape command
This commit is contained in:
parent
6fea83f8bd
commit
9bbea2af1a
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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<String> 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 + "<round|square>" + ChatColor.WHITE + " - set the border shape.");
|
||||
sender.sendMessage(cmd+" shape " + ChatColor.GREEN + "<round|square>" + ChatColor.WHITE + " - set the default border shape.");
|
||||
sender.sendMessage(cmd+" knockback " + ChatColor.GREEN + "<distance>" + 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 + "<world>" : ChatColor.DARK_GREEN + "[world]") + ChatColor.GREEN + " <round|square|default>" + ChatColor.WHITE + " - shape override.");
|
||||
sender.sendMessage(cmd+" getmsg" + ChatColor.WHITE + " - display border message.");
|
||||
sender.sendMessage(cmd+" setmsg " + ChatColor.GREEN + "<text>" + ChatColor.WHITE + " - set border message.");
|
||||
sender.sendMessage(cmd+" delay " + ChatColor.GREEN + "<amount>" + ChatColor.WHITE + " - time between border checks.");
|
||||
|
@ -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:
|
||||
/<command> [world] clear - remove border for this world.
|
||||
/<command> clear all - remove border for all worlds.
|
||||
/<command> list - show border information for all worlds.
|
||||
/<command> shape <round|square> - set the border shape.
|
||||
/<command> shape <round|square> - set the default border shape.
|
||||
/<command> getmsg - display border message.
|
||||
/<command> setmsg <text> - set border message.
|
||||
/<command> knockback <distance> - how far to move the player back.
|
||||
/<command> delay <amount> - time between border checks.
|
||||
/<command> delay <amount> - time between border checks.
|
||||
/<command> wshape [world] <round|square|default> - override shape.
|
Loading…
Reference in New Issue
Block a user