From c5274783107be8c824ced357c01885b40124a2de Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 7 Jan 2017 17:31:54 +1100 Subject: [PATCH] Add /os map resize --- MCGalaxy/Commands/CmdOverseer.SubCommands.cs | 12 ++++++++-- MCGalaxy/Commands/CmdOverseer.cs | 1 + MCGalaxy/Commands/World/CmdResizeLvl.cs | 23 +++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/MCGalaxy/Commands/CmdOverseer.SubCommands.cs b/MCGalaxy/Commands/CmdOverseer.SubCommands.cs index b545c6c9a..8f0695091 100644 --- a/MCGalaxy/Commands/CmdOverseer.SubCommands.cs +++ b/MCGalaxy/Commands/CmdOverseer.SubCommands.cs @@ -73,7 +73,7 @@ namespace MCGalaxy.Commands { string lbArgs = (arg1 + " " + arg2).Trim(); CustomBlockCommand.Execute(p, lbArgs, false, "/os lb"); } - + static void HandleMap(Player p, string opt, string value) { bool mapOnly = !(opt == "ADD" || opt == "DELETE" || opt == "SAVE"); @@ -106,6 +106,14 @@ namespace MCGalaxy.Commands { } } else if (opt == "RESTORE") { Command.all.Find("restore").Use(p, value); + } else if (opt == "RESIZE") { + value = p.level.name + " " + value; + string[] args = value.Split(' '); + if (args.Length < 4) { Command.all.Find("resizelvl").Help(p); return; } + + if (CmdResizeLvl.DoResize(p, args)) return; + Player.Message(p, "Type %T/os map resize {0} {1} {2} confirm %Sif you're sure.", + args[1], args[2], args[3]); } else if (opt == "PERVISIT") { string rank = value == "" ? Server.defaultRank : value; Command.all.Find("pervisit").Use(p, rank); @@ -206,7 +214,7 @@ namespace MCGalaxy.Commands { static void HandleSpawn(Player p, string ignored1, string ignored2) { Command.all.Find("setspawn").Use(p, ""); } - + static void HandleZone(Player p, string cmd, string name) { if (cmd == "LIST") { diff --git a/MCGalaxy/Commands/CmdOverseer.cs b/MCGalaxy/Commands/CmdOverseer.cs index 6c1eb0e0a..6f1c71d49 100644 --- a/MCGalaxy/Commands/CmdOverseer.cs +++ b/MCGalaxy/Commands/CmdOverseer.cs @@ -171,6 +171,7 @@ namespace MCGalaxy.Commands { "%T/os map physics [level] %H- Sets the physics on your map.", "%T/os map delete [num] %H- Deletes your nth map", "%T/os map restore [num] %H- Restores backup [num] of your map", + "%T/os map resize [width] [length] [height] %H- Resizes your map", "%T/os map save %H- Saves your map", "%T/os map pervisit [rank] %H- Sets the pervisit of you map", "%T/os map perbuild [rank] %H- Sets the perbuild of you map", diff --git a/MCGalaxy/Commands/World/CmdResizeLvl.cs b/MCGalaxy/Commands/World/CmdResizeLvl.cs index f4c041dd6..c437d517f 100644 --- a/MCGalaxy/Commands/World/CmdResizeLvl.cs +++ b/MCGalaxy/Commands/World/CmdResizeLvl.cs @@ -31,28 +31,35 @@ namespace MCGalaxy.Commands.World { public override void Use(Player p, string message) { string[] args = message.Split(' '); if (args.Length < 4) { Help(p); return; } + + if (DoResize(p, args)) return; + Player.Message(p, "Type %T/resizelvl {0} {1} {2} {3} confirm %Sif you're sure.", + args[0], args[1], args[2], args[3]); + } + + public static bool DoResize(Player p, string[] args) { Level lvl = LevelInfo.FindMatches(p, args[0]); - if (lvl == null) return; + if (lvl == null) return true; ushort x, y, z; if (!UInt16.TryParse(args[1], out x) || !UInt16.TryParse(args[2], out y) || !UInt16.TryParse(args[3], out z)) { - Player.Message(p, "Invalid dimensions."); return; + Player.Message(p, "Invalid dimensions."); return true; } - if (!MapGen.OkayAxis(x)) { Player.Message(p, "width must be divisible by 16, and >= 16"); return; } - if (!MapGen.OkayAxis(y)) { Player.Message(p, "height must be divisible by 16, and >= 16"); return; } - if (!MapGen.OkayAxis(z)) { Player.Message(p, "length must be divisible by 16, and >= 16."); return; } - if (!CmdNewLvl.CheckMapSize(p, x, y, z)) return; + if (!MapGen.OkayAxis(x)) { Player.Message(p, "width must be divisible by 16, and >= 16"); return true; } + if (!MapGen.OkayAxis(y)) { Player.Message(p, "height must be divisible by 16, and >= 16"); return true; } + if (!MapGen.OkayAxis(z)) { Player.Message(p, "length must be divisible by 16, and >= 16."); return true; } + if (!CmdNewLvl.CheckMapSize(p, x, y, z)) return true; bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm"); if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length)) { Player.Message(p, "New level dimensions are smaller than the current dimensions, &cyou will lose blocks%S."); - Player.Message(p, "Type %T/resizelvl {0} {1} {2} {3} confirm %Sif you're sure.", args[0], x, y, z); - return; + return false; } Level newLvl = ResizeLevel(lvl, x, y, z); LevelActions.Replace(lvl, newLvl); + return true; } static Level ResizeLevel(Level lvl, ushort width, ushort height, ushort length) {