diff --git a/MCGalaxy/Commands/Information/CmdMapInfo.cs b/MCGalaxy/Commands/Information/CmdMapInfo.cs index 7707d675d..7715dd723 100644 --- a/MCGalaxy/Commands/Information/CmdMapInfo.cs +++ b/MCGalaxy/Commands/Information/CmdMapInfo.cs @@ -217,7 +217,7 @@ namespace MCGalaxy.Commands.Info { Width = dims.X; Height = dims.Y; Length = dims.Z; BlockDBEntries = BlockDBFile.CountEntries(name); - path = LevelInfo.FindPropertiesFile(name); + path = LevelInfo.PropertiesPath(name); LevelConfig cfg = new LevelConfig(); cfg.EdgeLevel = Height / 2; cfg.CloudsHeight = Height + 2; LevelConfig.Load(path, cfg); diff --git a/MCGalaxy/Commands/Information/CmdWorlds.cs b/MCGalaxy/Commands/Information/CmdWorlds.cs index 4745fbcb5..2d848af18 100644 --- a/MCGalaxy/Commands/Information/CmdWorlds.cs +++ b/MCGalaxy/Commands/Information/CmdWorlds.cs @@ -30,18 +30,15 @@ namespace MCGalaxy.Commands.Info { public override void Use(Player p, string message) { string[] files = LevelInfo.AllMapFiles(); - for (int i = 0; i < files.Length; i++) { - files[i] = Path.GetFileNameWithoutExtension(files[i]); - } - Player.Message(p, "Maps (&c[no] %Sif not visitable): "); - MultiPageOutput.Output(p, files, (map) => FormatMap(p, map), + MultiPageOutput.Output(p, files, (file) => FormatMap(p, file), "Worlds", "maps", message, false); } - static string FormatMap(Player p, string map) { + static string FormatMap(Player p, string file) { LevelPermission visitP, buildP; bool loadOnGoto; + string map = Path.GetFileNameWithoutExtension(file); RetrieveProps(map, out visitP, out buildP, out loadOnGoto); LevelPermission maxPerm = visitP; @@ -57,10 +54,9 @@ namespace MCGalaxy.Commands.Info { build = LevelPermission.Guest; loadOnGoto = true; - string file = LevelInfo.FindPropertiesFile(level); - if (file == null) return; + string propsPath = LevelInfo.PropertiesPath(level); SearchArgs args = new SearchArgs(); - PropertiesFile.Read(file, ref args, ProcessLine); + if (!PropertiesFile.Read(propsPath, ref args, ProcessLine)) return; visit = Group.ParsePermOrName(args.Visit, visit); build = Group.ParsePermOrName(args.Build, build); diff --git a/MCGalaxy/Commands/World/CmdMap.cs b/MCGalaxy/Commands/World/CmdMap.cs index 94c12776f..1139b7cd6 100644 --- a/MCGalaxy/Commands/World/CmdMap.cs +++ b/MCGalaxy/Commands/World/CmdMap.cs @@ -71,9 +71,9 @@ namespace MCGalaxy.Commands.World { Level lvl = LevelInfo.FindExact(map); if (lvl != null) return lvl.Config; - string propsPath = LevelInfo.FindPropertiesFile(map); + string propsPath = LevelInfo.PropertiesPath(map); LevelConfig cfg = new LevelConfig(); - if (propsPath != null) LevelConfig.Load(propsPath, cfg); + LevelConfig.Load(propsPath, cfg); return cfg; } diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index 3fc7fc202..ba53ace2f 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -221,8 +221,8 @@ namespace MCGalaxy { if (lvl.IsMuseum) return; // museums do not save properties lock (lvl.savePropsLock) { - string path = LevelInfo.PropertiesPath(lvl.MapName); - LevelConfig.Save(path, lvl.Config, lvl.name); + string propsPath = LevelInfo.PropertiesPath(lvl.MapName); + LevelConfig.Save(propsPath, lvl.Config, lvl.name); } } @@ -363,9 +363,10 @@ namespace MCGalaxy { public static void LoadMetadata(Level lvl) { try { - string propsPath = LevelInfo.FindPropertiesFile(lvl.MapName); - if (propsPath != null) { - LevelConfig.Load(propsPath, lvl.Config); + string propsPath = LevelInfo.PropertiesPath(lvl.MapName); + bool propsExisted = LevelConfig.Load(propsPath, lvl.Config); + + if (propsExisted) { lvl.setPhysics(lvl.Config.Physics); } else { Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName); diff --git a/MCGalaxy/Levels/LevelConfig.cs b/MCGalaxy/Levels/LevelConfig.cs index 797c2998f..bd18a88c5 100644 --- a/MCGalaxy/Levels/LevelConfig.cs +++ b/MCGalaxy/Levels/LevelConfig.cs @@ -201,8 +201,8 @@ namespace MCGalaxy { } - public static void Load(string path, LevelConfig config) { - PropertiesFile.Read(path, ref config, LineProcessor); + public static bool Load(string path, LevelConfig config) { + return PropertiesFile.Read(path, ref config, LineProcessor); } static void LineProcessor(string key, string value, ref LevelConfig config) { diff --git a/MCGalaxy/Levels/LevelInfo.cs b/MCGalaxy/Levels/LevelInfo.cs index 9e532cfbb..d0feba545 100644 --- a/MCGalaxy/Levels/LevelInfo.cs +++ b/MCGalaxy/Levels/LevelInfo.cs @@ -88,21 +88,15 @@ namespace MCGalaxy { public static string PropertiesPath(string name) { return "levels/level properties/" + name + ".properties"; } - - - public static string FindPropertiesFile(string name) { - string file = "levels/level properties/" + name + ".properties"; - if (!File.Exists(file)) file = "levels/level properties/" + name; - return File.Exists(file) ? file : null; - } + public static string FindOfflineProperty(string name, string propKey) { - string file = FindPropertiesFile(name); - if (file == null) return null; + string path = PropertiesPath(name); + if (!File.Exists(path)) return null; string[] lines = null; try { - lines = File.ReadAllLines(file); + lines = File.ReadAllLines(path); } catch { return null; } diff --git a/MCGalaxy/Player/PlayerActions.cs b/MCGalaxy/Player/PlayerActions.cs index 47cd56c50..af081519c 100644 --- a/MCGalaxy/Player/PlayerActions.cs +++ b/MCGalaxy/Player/PlayerActions.cs @@ -80,7 +80,7 @@ namespace MCGalaxy { } static bool LoadOfflineLevel(Player p, string name) { - string propsPath = LevelInfo.FindPropertiesFile(name); + string propsPath = LevelInfo.PropertiesPath(name); LevelConfig cfg = new LevelConfig(); LevelConfig.Load(propsPath, cfg); diff --git a/MCGalaxy/Server/Tasks/UpgradeTasks.cs b/MCGalaxy/Server/Tasks/UpgradeTasks.cs index 35f593119..04a3c1e9b 100644 --- a/MCGalaxy/Server/Tasks/UpgradeTasks.cs +++ b/MCGalaxy/Server/Tasks/UpgradeTasks.cs @@ -116,10 +116,11 @@ namespace MCGalaxy.Tasks { static void Combine(string envFile) { string name = Path.GetFileNameWithoutExtension(envFile); - string propFile = LevelInfo.FindPropertiesFile(name); + string propsPath = LevelInfo.PropertiesPath(name); + List lines = new List(); - if (propFile != null) { - lines = Utils.ReadAllLinesList(propFile); + if (File.Exists(propsPath)) { + lines = Utils.ReadAllLinesList(propsPath); } using (StreamReader r = new StreamReader(envFile)) { @@ -128,8 +129,7 @@ namespace MCGalaxy.Tasks { lines.Add(line); } - propFile = LevelInfo.PropertiesPath(name); - File.WriteAllLines(propFile, lines.ToArray()); + File.WriteAllLines(propsPath, lines.ToArray()); File.Delete(envFile); }