From d90fac8f7f1c3838d56cc2fc2dde6eb2d7bd0f58 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 16 Jul 2016 09:57:00 +1000 Subject: [PATCH] Unload old map (without saving) when a /restore is done. --- Commands/World/CmdNewLvl.cs | 31 +++++++++++++++---------------- Commands/World/CmdRestore.cs | 1 + Commands/World/CmdUnload.cs | 2 +- Levels/IO/LvlProperties.cs | 1 - Levels/Level.cs | 4 ++-- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Commands/World/CmdNewLvl.cs b/Commands/World/CmdNewLvl.cs index 3f0ff82d1..e40ef6d42 100644 --- a/Commands/World/CmdNewLvl.cs +++ b/Commands/World/CmdNewLvl.cs @@ -47,18 +47,7 @@ namespace MCGalaxy.Commands.World { if (LevelInfo.ExistsOffline(name)) { Player.Message(p, "Level \"" + name + "\" already exists!"); return; } - - if (p != null) { - int limit = p.Rank < LevelPermission.Admin ? - Server.MapGenLimit : Server.MapGenLimitAdmin; - if ((long)x * y * z > limit ) { - string text = "You cannot create a map with over "; - if (limit > 1000 * 1000) text += (limit / (1000 * 1000)) + " million blocks"; - else if (limit > 1000) text += (limit / 1000) + " thousand blocks"; - else text += limit + " blocks"; - Player.Message(p, text); return; - } - } + if (!CheckMapSize(p, x, y, z)) return; try { using (Level lvl = new Level(name, x, y, z, args[4], seed)) { @@ -72,10 +61,20 @@ namespace MCGalaxy.Commands.World { } string format = seed != "" ? "Level \"{0}\" created with seed \"{1}\"" : "Level \"{0}\" created"; - if (seed != "") - Player.GlobalMessage(String.Format(format, name, seed)); - else - Player.GlobalMessage(String.Format(format, name)); + Player.GlobalMessage(String.Format(format, name, seed)); + } + + internal static bool CheckMapSize(Player p, int x, int y, int z) { + if (p == null) return true; + int limit = p.Rank < LevelPermission.Admin ? Server.MapGenLimit : Server.MapGenLimitAdmin; + if ((long)x * y * z <= limit ) return true; + + string text = "You cannot create a map with over "; + if (limit > 1000 * 1000) text += (limit / (1000 * 1000)) + " million blocks"; + else if (limit > 1000) text += (limit / 1000) + " thousand blocks"; + else text += limit + " blocks"; + Player.Message(p, text); + return false; } public override void Help(Player p) { diff --git a/Commands/World/CmdRestore.cs b/Commands/World/CmdRestore.cs index b44f0d768..f2e7488ef 100644 --- a/Commands/World/CmdRestore.cs +++ b/Commands/World/CmdRestore.cs @@ -73,6 +73,7 @@ namespace MCGalaxy.Commands { pl.level = restore; CmdReload.ReloadMap(null, pl, false); } + lvl.Unload(true, false); } else { Server.s.Log("Restore nulled"); File.Copy(LevelInfo.LevelPath(lvl.name) + ".backup", LevelInfo.LevelPath(lvl.name), true); diff --git a/Commands/World/CmdUnload.cs b/Commands/World/CmdUnload.cs index 611baa60a..ad9f09601 100644 --- a/Commands/World/CmdUnload.cs +++ b/Commands/World/CmdUnload.cs @@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World { for (int i = 0; i < loaded.Length; i++) { Level lvl = loaded[i]; if (lvl.HasPlayers()) continue; - lvl.Unload(true, true); + lvl.Unload(true); } } else { Level level = LevelInfo.Find(name); diff --git a/Levels/IO/LvlProperties.cs b/Levels/IO/LvlProperties.cs index bea3c3f7c..b1273566f 100644 --- a/Levels/IO/LvlProperties.cs +++ b/Levels/IO/LvlProperties.cs @@ -19,7 +19,6 @@ using System; using System.IO; namespace MCGalaxy.Levels.IO { - public static class LvlProperties { public static void Save(Level level, string path) { diff --git a/Levels/Level.cs b/Levels/Level.cs index b58235d1e..a049cc4dd 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -398,8 +398,8 @@ namespace MCGalaxy } MovePlayersToMain(); - if (changed && ShouldSaveChanges()) Save(false, true); - if (ShouldSaveChanges()) saveChanges(); + if (save && changed && ShouldSaveChanges()) Save(false, true); + if (save && ShouldSaveChanges()) saveChanges(); if (TntWarsGame.Find(this) != null) {