From 288d5c63fcace81ec2a85fe9e9de3a9d491f2510 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 19 Feb 2017 17:59:19 +1100 Subject: [PATCH] Load levels from different path instead of just replacing file --- MCGalaxy/Commands/CPE/CmdTexture.cs | 1 - MCGalaxy/Commands/World/CmdLoad.cs | 35 +++++++++++++---------------- MCGalaxy/Levels/Level.cs | 7 +++--- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/MCGalaxy/Commands/CPE/CmdTexture.cs b/MCGalaxy/Commands/CPE/CmdTexture.cs index 83c4cae93..be31ddeb9 100644 --- a/MCGalaxy/Commands/CPE/CmdTexture.cs +++ b/MCGalaxy/Commands/CPE/CmdTexture.cs @@ -100,7 +100,6 @@ namespace MCGalaxy.Commands.World { if (pl.level != p.level) continue; pl.SendCurrentMapAppearance(); } - p.level.Save(); Level.SaveSettings(p.level); } diff --git a/MCGalaxy/Commands/World/CmdLoad.cs b/MCGalaxy/Commands/World/CmdLoad.cs index 8e931ca69..d7931d270 100644 --- a/MCGalaxy/Commands/World/CmdLoad.cs +++ b/MCGalaxy/Commands/World/CmdLoad.cs @@ -86,28 +86,23 @@ namespace MCGalaxy.Commands.World { Player.Message(p, "Backup of {0} does not exist.", name); return null; } - if (LevelInfo.MapExists(name)) { - Server.s.Log(name + ".lvl file is corrupt. Deleting and replacing with " + name + ".lvl.backup file."); - File.Delete(LevelInfo.MapPath(name)); - } Server.s.Log("Attempting to load backup"); - File.Copy(LevelInfo.MapPath(name) + ".backup", LevelInfo.MapPath(name), true); + level = Level.Load(name, LevelInfo.MapPath(name) + ".backup", 0); + if (level != null) return level; - level = Level.Load(name); - if (level == null) { - Player.Message(p, "Loading backup failed."); - string backupPath = Server.backupLocation; - if (Directory.Exists(backupPath + "/" + name)) { - int backupNumber = Directory.GetDirectories(backupPath + "/" + name).Length; - Server.s.Log("Attempting to load latest backup, number " + backupNumber + " instead."); - File.Copy(LevelInfo.BackupPath(name, backupNumber.ToString()), LevelInfo.MapPath(name), true); - level = Level.Load(name); - if (level == null) { - Player.Message(p, "Loading latest backup failed as well."); - } - } else { - Player.Message(p, "Latest backup of {0} does not exist.", name); - } + Player.Message(p, "Loading backup failed."); + string backupPath = Server.backupLocation; + + if (Directory.Exists(backupPath + "/" + name)) { + int num = Directory.GetDirectories(backupPath + "/" + name).Length; + Server.s.Log("Attempting to load latest backup, number " + num + " instead."); + + string path = LevelInfo.BackupPath(name, num.ToString()); + level = Level.Load(name, path, 0); + if (level == null) + Player.Message(p, "Loading latest backup failed as well."); + } else { + Player.Message(p, "Latest backup of {0} does not exist.", name); } return level; } diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index ff5d60c97..67f80a921 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -334,14 +334,15 @@ namespace MCGalaxy { } } - public static Level Load(string name) { return Load(name, 0); } + public static Level Load(string name) { return Load(name, LevelInfo.MapPath(name), 0); } - public static Level Load(string name, byte phys) { + public static Level Load(string name, byte phys) { return Load(name, LevelInfo.MapPath(name), phys); } + + public static Level Load(string name, string path, byte phys) { if (LevelLoad != null) LevelLoad(name); OnLevelLoadEvent.Call(name); if (cancelload) { cancelload = false; return null; } - string path = LevelInfo.MapPath(name); if (!File.Exists(path)) { Server.s.Log("Attempted to load " + name + ", but the level file does not exist."); return null;