From 9f7719074f26194398bf586149a6fc922d91b594 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 9 Jan 2014 08:42:26 -0600 Subject: [PATCH] Two new variations of the set command are available thanks to sponsorship from Rhythmatic: /wb [world] set [radiusZ] spawn - uses the world's spawn point. /wb set [radiusZ] player - centers a border on the specified player. --- .../com/wimbli/WorldBorder/WBCommand.java | 130 +++++++++++------- src/main/resources/plugin.yml | 4 +- 2 files changed, 80 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/wimbli/WorldBorder/WBCommand.java b/src/main/java/com/wimbli/WorldBorder/WBCommand.java index fd31829..8ac1d12 100644 --- a/src/main/java/com/wimbli/WorldBorder/WBCommand.java +++ b/src/main/java/com/wimbli/WorldBorder/WBCommand.java @@ -9,6 +9,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.*; import org.bukkit.entity.Player; +import org.bukkit.Location; import org.bukkit.World; @@ -71,56 +72,46 @@ public class WBCommand implements CommandExecutor } // "set" command from player or console, world specified - if ((split.length == 5 || split.length == 6) && split[1].equalsIgnoreCase("set")) + if ((split.length >= 4) && split[1].equalsIgnoreCase("set")) { if (!Config.HasPermission(player, "set")) return true; + if (split.length == 4 && ! split[split.length - 1].equalsIgnoreCase("spawn")) + { // command can only be this short if "spawn" is specified rather than x + z or player name + sender.sendMessage(clrErr + "You have not provided a sufficient number of arguments. Check command list using root /wb command."); + return true; + } + World world = sender.getServer().getWorld(split[0]); if (world == null) sender.sendMessage("The world you specified (\"" + split[0] + "\") could not be found on the server, but data for it will be stored anyway."); - if(cmdSet(sender, split[0], split, 2, (split.length == 5)) && player != null) + if(cmdSet(sender, world, player, split, 2)) sender.sendMessage("Border has been set. " + Config.BorderDescription(split[0])); } - // "set" command from player, using current world, X and Z specified - else if ((split.length == 4 || split.length == 5) && split[0].equalsIgnoreCase("set") && player != null) + // "set" command from player using current world since it isn't specified, or allowed from console only if player name is specified + else if ((split.length >= 2) && split[0].equalsIgnoreCase("set")) { if (!Config.HasPermission(player, "set")) return true; - String world = player.getWorld().getName(); - - if (cmdSet(sender, world, split, 1, (split.length == 4))) - sender.sendMessage("Border has been set. " + Config.BorderDescription(world)); - } - - // "set" command from player, using current world, X and Z NOT specified - else if ((split.length == 2 || split.length == 3) && split[0].equalsIgnoreCase("set") && player != null) - { - if (!Config.HasPermission(player, "set")) return true; - - String world = player.getWorld().getName(); - - double x = player.getLocation().getX(); - double z = player.getLocation().getZ(); - int radiusX; - int radiusZ; - try + if (player == null) { - radiusX = Integer.parseInt(split[1]); - if (split.length == 3) - radiusZ = Integer.parseInt(split[2]); - else - radiusZ = radiusX; - } - catch(NumberFormatException ex) - { - sender.sendMessage(clrErr + "The radius value(s) must be integers."); - return true; + if (! split[split.length - 2].equalsIgnoreCase("player")) + { // command can only be called by console without world specified if player is specified instead + sender.sendMessage(clrErr + "You must specify a world name from console if not specifying a player name. Check command list using root \"wb\" command."); + return true; + } + player = Bukkit.getPlayer(split[split.length - 1]); + if (player == null || ! player.isOnline()) + { + sender.sendMessage(clrErr + "The player you specified (\"" + split[split.length - 1] + "\") does not appear to be online."); + return true; + } } - Config.setBorder(world, radiusX, radiusZ, x, z); - sender.sendMessage("Border has been set. " + Config.BorderDescription(world)); + if (cmdSet(sender, player.getWorld(), player, split, 1)) + sender.sendMessage("Border has been set. " + Config.BorderDescription(player.getWorld().getName())); } // "setcorners" command from player or console, world specified @@ -856,10 +847,10 @@ public class WBCommand implements CommandExecutor if (player != null) sender.sendMessage(cmd+" set " + clrReq + " " + clrOpt + "[radiusZ]" + clrDesc + " - set border, centered on you."); sender.sendMessage(cmdW+" set " + clrReq + " " + clrOpt + "[radiusZ] " + clrDesc + " - set border."); + sender.sendMessage(cmdW+" set " + clrReq + " " + clrOpt + "[radiusZ] spawn" + clrDesc + " - use spawn point."); + sender.sendMessage(cmd+" set " + clrReq + " " + clrOpt + "[radiusZ] player " + clrDesc + " - center on player."); sender.sendMessage(cmdW+" setcorners " + clrReq + " " + clrDesc + " - set by corners."); sender.sendMessage(cmdW+" radius " + clrReq + " " + clrOpt + "[radiusZ]" + clrDesc + " - change radius."); - sender.sendMessage(cmdW+" clear" + clrDesc + " - remove border for this world."); - sender.sendMessage(cmd+" clear all" + clrDesc + " - remove border for all worlds."); sender.sendMessage(cmd+" shape " + clrReq + "" + clrDesc + " - set the default shape."); sender.sendMessage(cmd+" shape " + clrReq + "" + clrDesc + " - same as above."); if (page == 1) @@ -867,13 +858,13 @@ public class WBCommand implements CommandExecutor } if (page == 0 || page == 2) { + sender.sendMessage(cmdW+" clear" + clrDesc + " - remove border for this world."); + sender.sendMessage(cmd+" clear all" + clrDesc + " - remove border for all worlds."); sender.sendMessage(cmd+" list" + clrDesc + " - show border information for all worlds."); - sender.sendMessage(cmdW+" fill " + clrOpt + "[freq] [pad] [force]" + clrDesc + " - generate world to border."); + sender.sendMessage(cmdW+" fill " + clrOpt + "[freq] [pad] [force]" + clrDesc + " - fill world to border."); sender.sendMessage(cmdW+" trim " + clrOpt + "[freq] [pad]" + clrDesc + " - trim world outside of border."); sender.sendMessage(cmd+" bypass " + ((player == null) ? clrReq + "" : clrOpt + "[player]") + clrOpt + " [on/off]" + clrDesc + " - let player go beyond border."); - sender.sendMessage(cmd+" wshape " + ((player == null) ? clrReq + "" : clrOpt + "[world]") + clrReq + " " + 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 + "" : clrOpt + "[world]") + clrReq + " " + clrDesc + " - same as above."); + sender.sendMessage(cmd+" knockback " + clrReq + "" + clrDesc + " - how far to move the player back."); sender.sendMessage(cmd+" wrap " + ((player == null) ? clrReq + "" : clrOpt + "[world]") + clrReq + " " + clrDesc + " - can make border crossings wrap."); if (page == 2) sender.sendMessage(cmd+" 3" + clrDesc + " - view third page of commands."); @@ -883,16 +874,18 @@ public class WBCommand implements CommandExecutor sender.sendMessage(cmd+" whoosh " + clrReq + "" + clrDesc + " - turn knockback effect on or off."); sender.sendMessage(cmd+" getmsg" + clrDesc + " - display border message."); sender.sendMessage(cmd+" setmsg " + clrReq + "" + clrDesc + " - set border message."); - sender.sendMessage(cmd+" knockback " + clrReq + "" + clrDesc + " - how far to move the player back."); sender.sendMessage(cmd+" delay " + clrReq + "" + clrDesc + " - time between border checks."); sender.sendMessage(cmd+" remount " + clrReq + "" + clrDesc + " - player remount delay after knockback."); - sender.sendMessage(cmd+" dynmap " + clrReq + "" + clrDesc + " - turn DynMap border display on or off."); - sender.sendMessage(cmd+" dynmapmsg " + clrReq + "" + clrDesc + " - DynMap border labels will show this."); + sender.sendMessage(cmd+" wshape " + ((player == null) ? clrReq + "" : clrOpt + "[world]") + clrReq + " " + 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 + "" : clrOpt + "[world]") + clrReq + " " + clrDesc + " - same as above."); if (page == 3) sender.sendMessage(cmd+" 4" + clrDesc + " - view fourth page of commands."); } if (page == 0 || page == 4) { + sender.sendMessage(cmd+" dynmap " + clrReq + "" + clrDesc + " - turn DynMap border display on or off."); + sender.sendMessage(cmd+" dynmapmsg " + clrReq + "" + clrDesc + " - DynMap border labels will show this."); sender.sendMessage(cmd+" bypasslist " + clrDesc + " - list players with border bypass enabled."); sender.sendMessage(cmd+" fillautosave " + clrReq + "" + clrDesc + " - world save interval for Fill."); sender.sendMessage(cmd+" portal " + clrReq + "" + clrDesc + " - turn portal redirection on or off."); @@ -922,23 +915,54 @@ public class WBCommand implements CommandExecutor return enabled ? clrReq+"enabled" : clrErr+"disabled"; } - private boolean cmdSet(CommandSender sender, String world, String[] data, int offset, boolean oneRadius) + private boolean cmdSet(CommandSender sender, World world, Player player, String[] data, int offset) { int radiusX, radiusZ; double x, z; + int radiusCount = data.length - offset; + try { - radiusX = Integer.parseInt(data[offset]); - if (oneRadius) - { - radiusZ = radiusX; - offset -= 1; + if (data[data.length - 1].equalsIgnoreCase("spawn")) + { // "spawn" specified for x/z coordinates + Location loc = world.getSpawnLocation(); + x = loc.getX(); + z = loc.getZ(); + radiusCount -= 1; + } + else if (data[data.length - 2].equalsIgnoreCase("player")) + { // player name specified for x/z coordinates + Player playerT = Bukkit.getPlayer(data[data.length - 1]); + if (playerT == null || ! playerT.isOnline()) + { + sender.sendMessage(clrErr + "The player you specified (\"" + data[data.length - 1] + "\") does not appear to be online."); + return false; + } + world = playerT.getWorld(); + x = playerT.getLocation().getX(); + z = playerT.getLocation().getZ(); + radiusCount -= 2; } else - radiusZ = Integer.parseInt(data[offset+1]); + { + if (player == null || radiusCount > 2) + { // x and z specified + x = Double.parseDouble(data[data.length - 2]); + z = Double.parseDouble(data[data.length - 1]); + radiusCount -= 2; + } + else + { // using coordinates of command sender (player) + x = player.getLocation().getX(); + z = player.getLocation().getZ(); + } + } - x = Double.parseDouble(data[offset+2]); - z = Double.parseDouble(data[offset+3]); + radiusX = Integer.parseInt(data[offset]); + if (radiusCount < 2) + radiusZ = radiusX; + else + radiusZ = Integer.parseInt(data[offset+1]); } catch(NumberFormatException ex) { @@ -946,7 +970,7 @@ public class WBCommand implements CommandExecutor return false; } - Config.setBorder(world, radiusX, radiusZ, x, z); + Config.setBorder(world.getName(), radiusX, radiusZ, x, z); return true; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1a5592e..f457ddb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: WorldBorder author: Brettflan description: Efficient, feature-rich plugin for limiting the size of your worlds. -version: 1.7.7 +version: 1.7.7_dev main: com.wimbli.WorldBorder.WorldBorder softdepend: - dynmap @@ -13,6 +13,8 @@ commands: / - list available commands (show help). / set [radiusZ] - set world border, centered on you. / [world] set [radiusZ] - set world border. + / [world] set [radiusZ] spawn - use spawn point. + / set [radiusZ] player - center on player. / [world] setcorners - set border from corners. / [world] radius [radiusZ] - change border's radius. / [world] clear - remove border for this world.