diff --git a/Commands/Economy/CmdEconomy.cs b/Commands/Economy/CmdEconomy.cs index f2de92a62..8cb2d9f43 100644 --- a/Commands/Economy/CmdEconomy.cs +++ b/Commands/Economy/CmdEconomy.cs @@ -385,7 +385,7 @@ namespace MCGalaxy.Commands { Economy.UpdateEcoStats(ecos); Command.all.Find("load").Use(null, p.name + "_" + par3); Thread.Sleep(250); - Level level = Level.Find(p.name + "_" + par3); + Level level = LevelInfo.Find(p.name + "_" + par3); if (level.permissionbuild > p.group.Permission) { level.permissionbuild = p.group.Permission; } if (level.permissionvisit > p.group.Permission) { level.permissionvisit = p.group.Permission; } Command.all.Find("goto").Use(p, p.name + "_" + par3); diff --git a/Commands/Fun/CmdCountdown.cs b/Commands/Fun/CmdCountdown.cs index ba42813e0..29465534e 100644 --- a/Commands/Fun/CmdCountdown.cs +++ b/Commands/Fun/CmdCountdown.cs @@ -312,7 +312,7 @@ namespace MCGalaxy.Commands try { Command.all.Find("load").Use(null, "countdown"); - Server.Countdown.mapon = Level.FindExact("countdown"); + Server.Countdown.mapon = LevelInfo.FindExact("countdown"); Server.Countdown.gamestatus = CountdownGameStatus.Enabled; Player.GlobalMessage("Countdown has been enabled!!"); } diff --git a/Commands/Fun/CmdLavaSurvival.cs b/Commands/Fun/CmdLavaSurvival.cs index 53f0f4cec..0b9e61834 100644 --- a/Commands/Fun/CmdLavaSurvival.cs +++ b/Commands/Fun/CmdLavaSurvival.cs @@ -104,7 +104,7 @@ namespace MCGalaxy.Commands if (s[1] == "map") { if (s.Length < 3) { SetupHelp(p, "map"); return; } - Level foundLevel = Level.Find(s[2]); + Level foundLevel = LevelInfo.Find(s[2]); if (foundLevel == null) { Player.SendMessage(p, "The level must be loaded to add/remove it."); diff --git a/Commands/Fun/CmdSlap.cs b/Commands/Fun/CmdSlap.cs index 66c6a0c8c..b365c3b74 100644 --- a/Commands/Fun/CmdSlap.cs +++ b/Commands/Fun/CmdSlap.cs @@ -34,7 +34,7 @@ namespace MCGalaxy.Commands if (who == null) { - Level which = Level.Find(message); + Level which = LevelInfo.Find(message); if (which == null) { diff --git a/Commands/Fun/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs index 6d5b3f209..c11ef4cab 100644 --- a/Commands/Fun/CmdTntWars.cs +++ b/Commands/Fun/CmdTntWars.cs @@ -106,7 +106,7 @@ namespace MCGalaxy.Commands } else { - Level lvl = Level.Find(text[1]); + Level lvl = LevelInfo.Find(text[1]); if (lvl == null) { Player.SendMessage(p, "TNT Wars Error: Couldn't find level '" + text[1] + "'"); @@ -673,7 +673,7 @@ namespace MCGalaxy.Commands } else { - it.lvl = Level.Find(text[2]); + it.lvl = LevelInfo.Find(text[2]); if (it.lvl == null) { Player.SendMessage(p, "TNT Wars Error: '" + text[2] + "' is not a level!"); diff --git a/Commands/Information/CmdMapInfo.cs b/Commands/Information/CmdMapInfo.cs index 79276bf13..1e18be8ef 100644 --- a/Commands/Information/CmdMapInfo.cs +++ b/Commands/Information/CmdMapInfo.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { - Level lvl = message == "" ? p.level : Level.Find(message); + Level lvl = message == "" ? p.level : LevelInfo.Find(message); if (lvl == null) { Player.SendMessage(p, "Could not find specified level."); return; } Player.SendMessage(p, "&b" + lvl.name + Server.DefaultColor + ": Width=" + lvl.Width + " Height=" + lvl.Height + " Depth=" + lvl.Length); diff --git a/Commands/Information/CmdUnloaded.cs b/Commands/Information/CmdUnloaded.cs index 652a83e93..12b117cce 100644 --- a/Commands/Information/CmdUnloaded.cs +++ b/Commands/Information/CmdUnloaded.cs @@ -96,62 +96,28 @@ namespace MCGalaxy.Commands //Exception catching since it needs to be tested on Ocean Flatgrass } - private LevelPermission GetPerVisitPermission(string level) { - string location = "levels/level properties/" + level + ".properties"; - LevelPermission lvlperm = LevelPermission.Guest; - try { - using (StreamReader reader = new StreamReader(location)) { - string line; - while ((line = reader.ReadLine()) != null) { - if (line.Split()[0].ToLower() == "pervisit") { - lvlperm = Group.Find(line.Split()[2]).Permission; - break; - } - } - } - } catch { return LevelPermission.Guest; } - - return lvlperm; + LevelPermission GetPerVisitPermission(string level) { + string value = LevelInfo.FindOfflineProperty(level, "pervisit"); + if (value == null) return LevelPermission.Guest; + Group grp = Group.Find(value); + return grp == null ? LevelPermission.Guest : grp.Permission; } - private LevelPermission GetPerBuildPermission(string level) { - string location = "levels/level properties/" + level + ".properties"; - LevelPermission lvlperm = LevelPermission.Guest; - try { - using (StreamReader reader = new StreamReader(location)) { - string line; - while ((line = reader.ReadLine()) != null) { - if (line.Split()[0].ToLower() == "perbuild") { - lvlperm = Group.Find(line.Split()[2]).Permission; - break; - } - } - } - } catch { return LevelPermission.Guest; } - - return lvlperm; + LevelPermission GetPerBuildPermission(string level) { + string value = LevelInfo.FindOfflineProperty(level, "perbuild"); + if (value == null) return LevelPermission.Guest; + Group grp = Group.Find(value); + return grp == null ? LevelPermission.Guest : grp.Permission; } - private bool GetLoadOnGoto(string level) { - string location = "levels/level properties/" + level + ".properties"; - bool loadOnGoto = false; - try { - using (StreamReader reader = new StreamReader(location)) { - string line; - while ((line = reader.ReadLine()) != null) { - if (line.Split()[0].ToLower() == "loadongoto") { - loadOnGoto = bool.Parse(line.Split()[2]); - break; - } - } - } - } catch { return false; } - - return loadOnGoto; + bool GetLoadOnGoto(string level) { + string value = LevelInfo.FindOfflineProperty(level, "loadongoto"); + bool load; + if (!bool.TryParse(value, out load)) return true; + return load; } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "%f/unloaded " + Server.DefaultColor + "- Lists all unloaded levels and their accessible state."); Player.SendMessage(p, "%f/unloaded <1/2/3/..> " + Server.DefaultColor + "- Shows a compact list."); } diff --git a/Commands/Moderation/CmdAllowGuns.cs b/Commands/Moderation/CmdAllowGuns.cs index 7283ca5b7..7ed21400a 100644 --- a/Commands/Moderation/CmdAllowGuns.cs +++ b/Commands/Moderation/CmdAllowGuns.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands { } lvl = p.level; } else { - lvl = Level.Find(message); + lvl = LevelInfo.Find(message); if (lvl == null || !File.Exists("levels/" + message + ".lvl")) { Player.SendMessage(p, "&9The level, &c" + message + " &9does not exist!"); return; } diff --git a/Commands/Moderation/CmdHighlight.cs b/Commands/Moderation/CmdHighlight.cs index f36d300e1..543cb7f41 100644 --- a/Commands/Moderation/CmdHighlight.cs +++ b/Commands/Moderation/CmdHighlight.cs @@ -76,7 +76,7 @@ namespace MCGalaxy.Commands try { Pos = who.UndoBuffer[CurrentPos]; - Level foundLevel = Level.Find(Pos.mapName); + Level foundLevel = LevelInfo.Find(Pos.mapName); if (foundLevel == p.level) { b = foundLevel.GetTile(Pos.x, Pos.y, Pos.z); @@ -153,7 +153,7 @@ namespace MCGalaxy.Commands { if (Convert.ToDateTime(fileContent[(i * 7) + 4].Replace('&', ' ')).AddSeconds(seconds) >= DateTime.Now) { - Level foundLevel = Level.Find(fileContent[i * 7]); + Level foundLevel = LevelInfo.Find(fileContent[i * 7]); if (foundLevel != null && foundLevel == p.level) { Pos.mapName = foundLevel.name; diff --git a/Commands/Moderation/CmdMoveAll.cs b/Commands/Moderation/CmdMoveAll.cs index f1b3ce0d8..2569dd753 100644 --- a/Commands/Moderation/CmdMoveAll.cs +++ b/Commands/Moderation/CmdMoveAll.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override void Use(Player p, string message) { - Level level = Level.Find(message.Split(' ')[0]); + Level level = LevelInfo.Find(message.Split(' ')[0]); if (level == null) { Player.SendMessage(p, "There is no level named '" + message.Split(' ')[0] + "'."); return; } if (p == null) foreach (Player pl in PlayerInfo.players) { Command.all.Find("move").Use(null, pl.name + " " + level.name); } diff --git a/Commands/Moderation/CmdRenameLvl.cs b/Commands/Moderation/CmdRenameLvl.cs index b4aa5f72e..8adea92de 100644 --- a/Commands/Moderation/CmdRenameLvl.cs +++ b/Commands/Moderation/CmdRenameLvl.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { if (message == "" || message.IndexOf(' ') == -1) { Help(p); return; } - Level foundLevel = Level.Find(message.Split(' ')[0]); + Level foundLevel = LevelInfo.Find(message.Split(' ')[0]); if (foundLevel == null) { Player.SendMessage(p, "Level not found"); diff --git a/Commands/Moderation/CmdReveal.cs b/Commands/Moderation/CmdReveal.cs index 0b927e2d6..19b044026 100644 --- a/Commands/Moderation/CmdReveal.cs +++ b/Commands/Moderation/CmdReveal.cs @@ -35,7 +35,7 @@ namespace MCGalaxy.Commands { Level lvl = null; if (parts.Length == 2) { - lvl = Level.Find(parts[1]); + lvl = LevelInfo.Find(parts[1]); } else if (p != null && p.level != null) { lvl = p.level; } diff --git a/Commands/World/CmdClearBlockChanges.cs b/Commands/World/CmdClearBlockChanges.cs index a4642515f..ac5a8b04f 100644 --- a/Commands/World/CmdClearBlockChanges.cs +++ b/Commands/World/CmdClearBlockChanges.cs @@ -34,7 +34,7 @@ namespace MCGalaxy.Commands { } Level lvl = p == null ? null : p.level; if (message != "") { - lvl = Level.Find(message.ToLower()); + lvl = LevelInfo.Find(message.ToLower()); if (lvl == null) { Player.SendMessage(p, "Could not find the entered level."); return; } diff --git a/Commands/World/CmdDeleteLvl.cs b/Commands/World/CmdDeleteLvl.cs index 8e0a3f050..f7fb94250 100644 --- a/Commands/World/CmdDeleteLvl.cs +++ b/Commands/World/CmdDeleteLvl.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message == "" || message.Split().Length > 1) { Help(p); return; } - Level foundLevel = Level.Find(message); + Level foundLevel = LevelInfo.Find(message); if (foundLevel != null) { if (foundLevel.permissionbuild > p.group.Permission) { Player.SendMessage(p, "%cYou can't delete levels with a perbuild rank higher than yours!"); diff --git a/Commands/World/CmdGoto.cs b/Commands/World/CmdGoto.cs index 3e7fc2d32..1e854f12e 100644 --- a/Commands/World/CmdGoto.cs +++ b/Commands/World/CmdGoto.cs @@ -32,12 +32,12 @@ namespace MCGalaxy.Commands { if (p == null) { MessageInGameOnly(p); return; } if (message == "") { Help(p); return; } - Level lvl = Level.FindExact(message); + Level lvl = LevelInfo.FindExact(message); if (lvl != null) { GoToLevel(p, lvl, message); } else if (Server.AutoLoad) { if (!File.Exists("levels/" + message + ".lvl")) { - lvl = Level.Find(message); + lvl = LevelInfo.Find(message); if (lvl == null) { Player.SendMessage(p, "Level \"" + message + "\" doesn't exist! Did you mean..."); Command.all.Find("search").Use(p, "levels " + message); @@ -46,7 +46,7 @@ namespace MCGalaxy.Commands { } } else if (Level.CheckLoadOnGoto(message)) { Command.all.Find("load").Use(p, message); - lvl = Level.Find(message); + lvl = LevelInfo.Find(message); if (lvl != null) { GoToLevel(p, lvl, message); } @@ -58,7 +58,7 @@ namespace MCGalaxy.Commands { } } } else { - lvl = Level.Find(message); + lvl = LevelInfo.Find(message); if (lvl == null) { Player.SendMessage(p, "There is no level \"" + message + "\" loaded. Did you mean.."); Command.all.Find("search").Use(p, "levels " + message); diff --git a/Commands/World/CmdMap.cs b/Commands/World/CmdMap.cs index 8d620bfbf..14a96659a 100644 --- a/Commands/World/CmdMap.cs +++ b/Commands/World/CmdMap.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands if (message.IndexOf(' ') == -1) { - lvl = Level.Find(message); + lvl = LevelInfo.Find(message); if (lvl == null) { if (p != null) @@ -66,7 +66,7 @@ namespace MCGalaxy.Commands } else { - lvl = Level.Find(message.Split(' ')[0]); + lvl = LevelInfo.Find(message.Split(' ')[0]); if (lvl == null || message.Split(' ')[0].ToLower() == "ps" || message.Split(' ')[0].ToLower() == "rp") lvl = p.level; else message = message.Substring(message.IndexOf(' ') + 1); diff --git a/Commands/World/CmdPause.cs b/Commands/World/CmdPause.cs index 77599778c..a7535136a 100644 --- a/Commands/World/CmdPause.cs +++ b/Commands/World/CmdPause.cs @@ -35,13 +35,13 @@ namespace MCGalaxy.Commands if (parts.Length == 1) { if (!int.TryParse(parts[0], out seconds)) { seconds = 30; - lvl = Level.Find(parts[0].ToLower()); + lvl = LevelInfo.Find(parts[0].ToLower()); } } else { if (!int.TryParse(parts[0], out seconds)) { Player.SendMessage(p, "You must specify pause time in seconds"); return; } - lvl = Level.Find(parts[1].ToLower()); + lvl = LevelInfo.Find(parts[1].ToLower()); } } diff --git a/Commands/World/CmdPermissions.cs b/Commands/World/CmdPermissions.cs index 7f5158863..6282add09 100644 --- a/Commands/World/CmdPermissions.cs +++ b/Commands/World/CmdPermissions.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands { return; } - Level level = args.Length == 1 ? p.level : Level.Find(args[0]); + Level level = args.Length == 1 ? p.level : LevelInfo.Find(args[0]); if (level == null) { Player.SendMessage(p, "There is no level \"" + args[0] + "\" loaded."); return; } diff --git a/Commands/World/CmdPhysics.cs b/Commands/World/CmdPhysics.cs index d7eb554d3..1b91d6d64 100644 --- a/Commands/World/CmdPhysics.cs +++ b/Commands/World/CmdPhysics.cs @@ -47,7 +47,7 @@ namespace MCGalaxy.Commands } if (args.Length == 2) { - level = Level.Find(args[0].ToLower()); + level = LevelInfo.Find(args[0].ToLower()); if (level == null) { Player.SendMessage(p, "Could not find entered level."); return; } diff --git a/Commands/World/CmdRestore.cs b/Commands/World/CmdRestore.cs index 9775249a8..2c956664a 100644 --- a/Commands/World/CmdRestore.cs +++ b/Commands/World/CmdRestore.cs @@ -49,7 +49,7 @@ namespace MCGalaxy.Commands if (message.Split(' ').Length >= 2) { - lvl = Level.Find(text[1]); + lvl = LevelInfo.Find(text[1]); if (lvl == null) { Player.SendMessage(p, "Level not found!"); diff --git a/Commands/World/CmdSave.cs b/Commands/World/CmdSave.cs index ca979dfb2..929441e4d 100644 --- a/Commands/World/CmdSave.cs +++ b/Commands/World/CmdSave.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Commands } } } else if (message.Split(' ').Length == 1) { //Just save level given - Level foundLevel = Level.Find(message); + Level foundLevel = LevelInfo.Find(message); if (foundLevel != null) { foundLevel.Save(true); Player.SendMessage(p, "Level \"" + foundLevel.name + "\" saved."); @@ -67,7 +67,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Could not find level specified"); } } else if (message.Split(' ').Length == 2) { - Level foundLevel = Level.Find(message.Split(' ')[0]); + Level foundLevel = LevelInfo.Find(message.Split(' ')[0]); string restoreName = message.Split(' ')[1].ToLower(); if (foundLevel != null) { foundLevel.Save(true); diff --git a/Commands/World/CmdUnload.cs b/Commands/World/CmdUnload.cs index dd8cff221..bef24142e 100644 --- a/Commands/World/CmdUnload.cs +++ b/Commands/World/CmdUnload.cs @@ -41,7 +41,7 @@ namespace MCGalaxy.Commands l.Unload(true, true); }); } else { - Level level = Level.Find(name); + Level level = LevelInfo.Find(name); if (level == null) { Player.SendMessage(p, "There is no level \"" + name + "\" loaded."); } else if (!level.Unload()) { diff --git a/Commands/building/CmdRedo.cs b/Commands/building/CmdRedo.cs index 41438ac1f..d3c3bbc8b 100644 --- a/Commands/building/CmdRedo.cs +++ b/Commands/building/CmdRedo.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands { for (int i = p.RedoBuffer.Count - 1; i >= 0; i--) { Player.UndoPos Pos = p.RedoBuffer[i]; - Level lvl = Level.FindExact(Pos.mapName); + Level lvl = LevelInfo.FindExact(Pos.mapName); if (lvl == null) continue; diff --git a/Commands/building/CmdUndo.cs b/Commands/building/CmdUndo.cs index 1620a1220..1bf80c159 100644 --- a/Commands/building/CmdUndo.cs +++ b/Commands/building/CmdUndo.cs @@ -159,7 +159,7 @@ namespace MCGalaxy.Commands } bool CheckBlockPlayer(Player p, long seconds, Player.UndoPos undo, ref Level saveLevel) { - Level lvl = Level.FindExact(undo.mapName); + Level lvl = LevelInfo.FindExact(undo.mapName); saveLevel = lvl; byte b = lvl.GetTile(undo.x, undo.y, undo.z); if (undo.timePlaced.AddSeconds(seconds) < DateTime.Now) diff --git a/Commands/other/CmdMove.cs b/Commands/other/CmdMove.cs index 422999683..e960e1b2f 100644 --- a/Commands/other/CmdMove.cs +++ b/Commands/other/CmdMove.cs @@ -48,7 +48,7 @@ namespace MCGalaxy.Commands if (param.Length == 2) // /move name map { Player who = PlayerInfo.Find(param[0]); - Level where = Level.Find(param[1]); + Level where = LevelInfo.Find(param[1]); if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; } if (where == null) { Player.SendMessage(p, "Could not find level specified"); return; } if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; } diff --git a/Commands/other/CmdWarp.cs b/Commands/other/CmdWarp.cs index 80c079cb7..0af36f93a 100644 --- a/Commands/other/CmdWarp.cs +++ b/Commands/other/CmdWarp.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Warps:"); foreach (Warp.Wrp wr in Warp.Warps) { - if (Level.Find(wr.lvlname) != null) + if (LevelInfo.Find(wr.lvlname) != null) { Player.SendMessage(p, wr.name + " : " + wr.lvlname); Thread.Sleep(300); // I feel this is needed so that if there are a lot of warps, they do not immediatly go off the screen! @@ -137,7 +137,7 @@ namespace MCGalaxy.Commands { Warp.Wrp w = new Warp.Wrp(); w = Warp.GetWarp(par0); - Level lvl = Level.Find(w.lvlname); + Level lvl = LevelInfo.Find(w.lvlname); if (lvl != null) { if (p.level != lvl) diff --git a/Commands/other/CmdWaypoint.cs b/Commands/other/CmdWaypoint.cs index adedb2eb6..a3492d72f 100644 --- a/Commands/other/CmdWaypoint.cs +++ b/Commands/other/CmdWaypoint.cs @@ -83,7 +83,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Waypoints:"); foreach (Waypoint wp in p.Waypoints) { - if (Level.Find(wp.lvlname) != null) + if (LevelInfo.Find(wp.lvlname) != null) { Player.SendMessage(p, wp.name + ":" + wp.lvlname); } diff --git a/GUI/PropertyWindow.cs b/GUI/PropertyWindow.cs index 3cd54ada4..a504e5c0f 100644 --- a/GUI/PropertyWindow.cs +++ b/GUI/PropertyWindow.cs @@ -1515,9 +1515,9 @@ txtBackupLocation.Text = folderDialog.SelectedPath; try { name = lsMapNoUse.Items[lsMapNoUse.SelectedIndex].ToString(); } catch { return; } - if ( Level.Find(name) == null ) + if ( LevelInfo.Find(name) == null ) Command.all.Find("load").Use(null, name); - Level level = Level.Find(name); + Level level = LevelInfo.Find(name); if ( level == null ) return; Server.lava.AddMap(name); @@ -1550,9 +1550,9 @@ txtBackupLocation.Text = folderDialog.SelectedPath; try { name = lsMapUse.Items[lsMapUse.SelectedIndex].ToString(); } catch { return; } - if ( Level.Find(name) == null ) + if ( LevelInfo.Find(name) == null ) Command.all.Find("load").Use(null, name); - Level level = Level.Find(name); + Level level = LevelInfo.Find(name); if ( level == null ) return; Server.lava.RemoveMap(name); @@ -1942,7 +1942,7 @@ txtBackupLocation.Text = folderDialog.SelectedPath; return; } string[] split = slctd.Split(new string[] { " - " }, StringSplitOptions.None); - TntWarsGame.GuiLoaded = TntWarsGame.Find(Level.Find(split[0])); + TntWarsGame.GuiLoaded = TntWarsGame.Find(LevelInfo.Find(split[0])); LoadTNTWarsTab(sender, e); } catch { } @@ -1955,7 +1955,7 @@ txtBackupLocation.Text = folderDialog.SelectedPath; private void TntWrsCrtNwTntWrsBt_Click(object sender, EventArgs e) { TntWarsGame it = null; try { - it = new TntWarsGame(Level.Find(TntWrsMpsList.Items[TntWrsMpsList.SelectedIndex].ToString())); + it = new TntWarsGame(LevelInfo.Find(TntWrsMpsList.Items[TntWrsMpsList.SelectedIndex].ToString())); } catch { } if ( it == null ) return; diff --git a/GUI/Window.cs b/GUI/Window.cs index e9a019ca3..25e2bfd51 100644 --- a/GUI/Window.cs +++ b/GUI/Window.cs @@ -986,7 +986,7 @@ namespace MCGalaxy.Gui foreach (FileInfo file in fi) { name = file.Name.Replace(".lvl", ""); - if (Level.Find(name.ToLower()) == null) + if (LevelInfo.Find(name.ToLower()) == null) UnloadedList.Items.Add(name); } }); @@ -1125,9 +1125,9 @@ namespace MCGalaxy.Gui catch { } foreach (Object obj in MapCombo.Items) { - if (Level.Find(obj.ToString()) != null) + if (LevelInfo.Find(obj.ToString()) != null) { - if (p.level == Level.Find(obj.ToString())) + if (p.level == LevelInfo.Find(obj.ToString())) { MapCombo.SelectedItem = obj; } @@ -1264,7 +1264,7 @@ namespace MCGalaxy.Gui PlayersTextBox.AppendTextAndScroll("The player is already on that map"); return; } - if (!Server.levels.Contains(Level.Find(MapCombo.Text))) + if (!Server.levels.Contains(LevelInfo.Find(MapCombo.Text))) { PlayersTextBox.AppendTextAndScroll("That map doesn't exist!!"); return; diff --git a/Games/CTF/Auto_CTF.cs b/Games/CTF/Auto_CTF.cs index 6c535489a..203fe0928 100644 --- a/Games/CTF/Auto_CTF.cs +++ b/Games/CTF/Auto_CTF.cs @@ -228,7 +228,7 @@ namespace MCGalaxy File.Delete("levels/ctf.lvl"); File.Copy("CTF/maps/" + mapname + ".lvl", "levels/ctf.lvl"); Command.all.Find("load").Use(null, "ctf"); - mainlevel = Level.Find("ctf"); + mainlevel = LevelInfo.Find("ctf"); } /// /// Create a new CTF object @@ -272,7 +272,7 @@ namespace MCGalaxy tagging.Dispose(); mainlevel = null; started = false; - if (Level.Find("ctf") != null) + if (LevelInfo.Find("ctf") != null) Command.all.Find("unload").Use(null, "ctf"); } void tagging_Elapsed(object sender, System.Timers.ElapsedEventArgs e) @@ -358,7 +358,7 @@ namespace MCGalaxy /// public void Start() { - if (Level.Find("ctf") != null) + if (LevelInfo.Find("ctf") != null) { Command.all.Find("unload").Use(null, "ctf"); Thread.Sleep(1000); diff --git a/Games/LavaSurvival.cs b/Games/LavaSurvival.cs index b7a82f83d..610d27bb2 100644 --- a/Games/LavaSurvival.cs +++ b/Games/LavaSurvival.cs @@ -280,7 +280,7 @@ namespace MCGalaxy Level oldMap = null; if (active && map != null) oldMap = map; Command.all.Find("load").Use(null, name); - map = Level.Find(name); + map = LevelInfo.Find(name); if (map != null) { diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 0a80f266c..37c5039d5 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -418,7 +418,7 @@ namespace MCGalaxy } Level current = Server.mainLevel; - if (Server.lastLevelVote1 == level || Server.lastLevelVote2 == level2 || Server.lastLevelVote1 == level2 || Server.lastLevelVote2 == level || current == Level.Find(level) || currentZombieLevel == level || current == Level.Find(level2) || currentZombieLevel == level2) + if (Server.lastLevelVote1 == level || Server.lastLevelVote2 == level2 || Server.lastLevelVote1 == level2 || Server.lastLevelVote2 == level || current == LevelInfo.Find(level) || currentZombieLevel == level || current == LevelInfo.Find(level2) || currentZombieLevel == level2) goto LevelChoice; else if (selectedLevel1 == "") { selectedLevel1 = level; goto LevelChoice; } else @@ -565,7 +565,7 @@ namespace MCGalaxy String oldLevel = Server.mainLevel.name; if (changeMainLevel) { - Server.mainLevel = Level.Find(next.ToLower()); + Server.mainLevel = LevelInfo.Find(next.ToLower()); PlayerInfo.players.ForEach(delegate(Player player) { if (player.level.name != next && player.level.name == currentLevelName) diff --git a/Levels/Level.cs b/Levels/Level.cs index 984b2d1a3..a6db83d02 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -1,7 +1,7 @@ /* Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - Dual-licensed under the Educational Community License, Version 2.0 and + Dual-licensed under the Educational Community License, Version 2.0 and the GNU General Public License, Version 3 (the "Licenses"); you may not use this file except in compliance with the Licenses. You may obtain a copy of the Licenses at @@ -375,23 +375,11 @@ namespace MCGalaxy return x >= 0 && y >= 0 && z >= 0 && x < Width && y < Height && z < Length; } - public static Level Find(string name) { - name = name.ToLower(); - Level match = null; int matches = 0; - - foreach (Level level in Server.levels) { - if (level.name.ToLower() == name) return level; - if (level.name.ToLower().Contains(name)) { - match = level; matches++; - } - } - return matches == 1 ? match : null; - } + [Obsolete] + public static Level Find(string name) { return LevelInfo.Find(name); } - public static Level FindExact(string levelName) - { - return Server.levels.Find(lvl => levelName.ToLower() == lvl.name.ToLower()); - } + [Obsolete] + public static Level FindExact(string name) { return LevelInfo.FindExact(name); } public static void SaveSettings(Level level) { LvlProperties.Save(level, "levels/level properties/" + level.name); @@ -652,40 +640,12 @@ namespace MCGalaxy return null; } - public static bool CheckLoadOnGoto(string givenName) - { - try - { - string foundLocation; - foundLocation = "levels/level properties/" + givenName + ".properties"; - if (!File.Exists(foundLocation)) - foundLocation = "levels/level properties/" + givenName; - if (!File.Exists(foundLocation)) - return true; - - foreach (string line in File.ReadAllLines(foundLocation)) - { - try - { - if (line[0] == '#') continue; - string value = line.Substring(line.IndexOf(" = ") + 3); - - switch (line.Substring(0, line.IndexOf(" = ")).ToLower()) - { - case "loadongoto": - return bool.Parse(value); - } - } - catch (Exception e) - { - Server.ErrorLog(e); - } - } - } - catch - { - } - return true; + public static bool CheckLoadOnGoto(string givenName) { + string value = LevelInfo.FindOfflineProperty(givenName, "loadongoto"); + if (value == null) return true; + bool load; + if (!bool.Parse(value)) return true; + return load; } public void ChatLevel(string message) { ChatLevel(message, LevelPermission.Banned); } diff --git a/Levels/LevelInfo.cs b/Levels/LevelInfo.cs new file mode 100644 index 000000000..869798b67 --- /dev/null +++ b/Levels/LevelInfo.cs @@ -0,0 +1,76 @@ +/* + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Collections.Generic; +using System.IO; + +namespace MCGalaxy { + + public static class LevelInfo { + + public static Level Find(string name) { + name = name.ToLower(); + Level match = null; int matches = 0; + + foreach (Level level in Server.levels) { + if (level.name.ToLower() == name) return level; + if (level.name.ToLower().Contains(name)) { + match = level; matches++; + } + } + return matches == 1 ? match : null; + } + + public static Level FindExact(string name) { + name = name.ToLower(); + + foreach (Level level in Server.levels) { + if (level.name.ToLower() == name) return level; + } + return null; + } + + public static string FindOfflineProperty(string name, string propKey) { + string file = "levels/level properties/" + name + ".properties"; + if (!File.Exists(file)) + file = "levels/level properties/" + name; + if (!File.Exists(file)) return null; + + string[] lines = null; + try { + lines = File.ReadAllLines(file); + } catch { + return null; + } + + foreach (string line in lines) { + try { + if (line == "" || line[0] == '#') continue; + int index = line.IndexOf(" = "); + if (index == -1) continue; + + string key = line.Substring(0, index).ToLower(); + if (key == propKey) return line.Substring(index + 3); + } catch (Exception e) { + Server.ErrorLog(e); + } + } + return null; + } + } +} \ No newline at end of file diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 42a00406d..b17956a3d 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -407,6 +407,7 @@ + diff --git a/Player/Undo/UndoFileBin.cs b/Player/Undo/UndoFileBin.cs index 78dd9587a..5a4759b2f 100644 --- a/Player/Undo/UndoFileBin.cs +++ b/Player/Undo/UndoFileBin.cs @@ -173,7 +173,7 @@ namespace MCGalaxy.Util { if (time.AddSeconds(65536).AddSeconds(seconds) < now) return false; // we can safely discard the entire chunk - lvl = Level.FindExact(chunk.LevelName); + lvl = LevelInfo.FindExact(chunk.LevelName); return true; } diff --git a/Player/Undo/UndoFileText.cs b/Player/Undo/UndoFileText.cs index dc012932a..322eb0e52 100644 --- a/Player/Undo/UndoFileText.cs +++ b/Player/Undo/UndoFileText.cs @@ -71,7 +71,7 @@ namespace MCGalaxy.Util { try { // line format: mapName x y z date oldblock newblock if (!InTime(lines[(i * 7) - 3], seconds)) return false; - Level foundLevel = Level.FindExact(lines[(i * 7) - 7]); + Level foundLevel = LevelInfo.FindExact(lines[(i * 7) - 7]); if (foundLevel == null) continue; Pos.mapName = foundLevel.name; @@ -104,7 +104,7 @@ namespace MCGalaxy.Util { try { // line format: mapName x y z date oldblock newblock if (!InTime(lines[(i * 7) - 3], seconds)) return false; - Level foundLevel = Level.FindExact(lines[(i * 7) - 7]); + Level foundLevel = LevelInfo.FindExact(lines[(i * 7) - 7]); if (foundLevel == null || foundLevel != p.level) continue; Pos.mapName = foundLevel.name; diff --git a/Player/Waypoint.cs b/Player/Waypoint.cs index 2bdc5bb1b..0c170873e 100644 --- a/Player/Waypoint.cs +++ b/Player/Waypoint.cs @@ -47,7 +47,7 @@ namespace MCGalaxy { public static void Goto(string waypoint, Player p) { if ( !Exists(waypoint, p) ) return; Waypoint wp = Find(waypoint, p); - Level lvl = Level.Find(wp.lvlname); + Level lvl = LevelInfo.Find(wp.lvlname); if ( wp == null ) return; if ( lvl != null ) { if ( p.level != lvl ) { diff --git a/Server/Server.cs b/Server/Server.cs index 0d79d1349..079399bc6 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -685,7 +685,7 @@ namespace MCGalaxy if (!key.Equals(mainLevel.name)) { Command.all.Find("load").Use(null, key + " " + value); - Level l = Level.FindExact(key); + Level l = LevelInfo.FindExact(key); } else {