From 8cad8ad507f3beb4d65f51bab927f0e6fa7d3acd Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Jan 2016 22:00:49 +1100 Subject: [PATCH] Fix /levels and /unloaded from console. --- Commands/Information/CmdLevels.cs | 105 +++++++++++----------------- Commands/Information/CmdUnloaded.cs | 5 +- Games/IGame.cs | 1 + 3 files changed, 42 insertions(+), 69 deletions(-) diff --git a/Commands/Information/CmdLevels.cs b/Commands/Information/CmdLevels.cs index 8247af3a6..46a50e7a8 100644 --- a/Commands/Information/CmdLevels.cs +++ b/Commands/Information/CmdLevels.cs @@ -1,25 +1,25 @@ /* - Copyright 2012 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. + Copyright 2012 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; -namespace MCGalaxy.Commands -{ - public sealed class CmdLevels : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdLevels : Command { + public override string name { get { return "levels"; } } public override string shortcut { get { return "maps"; } } public override string type { get { return CommandTypes.Information; } } @@ -27,62 +27,35 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public CmdLevels() { } - public override void Use(Player p, string message) - { - try - { + public override void Use(Player p, string message) { + if (message != "") { Help(p); return; } - if (!String.IsNullOrEmpty(message.Trim())) + string canVisit = "", canBuild = ""; + Server.levels.ForEach( + (level) => { - Help(p); - return; - } - - message = ""; - string message2 = ""; - bool Once = false; - Server.levels.ForEach((level) => - { - if (p != null && level.permissionvisit <= p.group.Permission) - { + if (p == null || level.permissionvisit <= p.group.Permission) { if (Group.findPerm(level.permissionbuild) != null) - message += ", " + Group.findPerm(level.permissionbuild).color + level.name + " &b[&f" + level.physics + "&b]"; + canVisit += ", " + Group.findPerm(level.permissionbuild).color + level.name + " &b[&f" + level.physics + "&b]"; else - message += ", " + level.name + " &b[" + level.physics + "]"; - } - else - { - if (!Once) - { - Once = true; - if (Group.findPerm(level.permissionvisit) != null) - message2 += Group.findPerm(level.permissionvisit).color + level.name + " &b[&f" + level.physics + "&b]"; - else - message2 += level.name + " &b[" + level.physics + "]"; - } + canVisit += ", " + level.name + " &b[" + level.physics + "]"; + } else { + if (Group.findPerm(level.permissionvisit) != null) + canBuild += ", " + Group.findPerm(level.permissionvisit).color + level.name + " &b[&f" + level.physics + "&b]"; else - { - if (Group.findPerm(level.permissionvisit) != null) - message2 += ", " + Group.findPerm(level.permissionvisit).color + level.name + " &b[&f" + level.physics + "&b]"; - else - message2 += ", " + level.name + " &b[&f" + level.physics + "&b]"; - } + canBuild += ", " + level.name + " &b[&f" + level.physics + "&b]"; } }); - Player.SendMessage(p, "Loaded levels [physics_level]: " + message.Remove(0, 2)); - if (message2 != "") - Player.SendMessage(p, "Can't Goto: " + message2); - Player.SendMessage(p, "Use &f/unloaded" + Server.DefaultColor + " for unloaded levels."); - } - catch (Exception e) - { - Server.ErrorLog(e); - } - + if (canVisit != "") + canVisit = canVisit.Remove(0, 2); + Player.SendMessage(p, "Loaded levels [physics_level]: " + canVisit); + if (canBuild != "") + Player.SendMessage(p, "Loaded levsl you cannot visit: " + canBuild.Remove(0, 2)); + Player.SendMessage(p, "Use &f/unloaded" + Server.DefaultColor + " for unloaded levels."); } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "%f/levels " + Server.DefaultColor + "- Lists all loaded levels and their physics levels."); } } diff --git a/Commands/Information/CmdUnloaded.cs b/Commands/Information/CmdUnloaded.cs index 63c26fdff..652a83e93 100644 --- a/Commands/Information/CmdUnloaded.cs +++ b/Commands/Information/CmdUnloaded.cs @@ -34,7 +34,6 @@ namespace MCGalaxy.Commands try { List levels = new List(Server.levels.Count); - string unloadedLevels = ""; int currentNum = 0; int maxMaps = 0; if (message != "") @@ -58,7 +57,7 @@ namespace MCGalaxy.Commands if (!levels.Contains(file.Name.Replace(".lvl", "").ToLower())) { string level = file.Name.Replace(".lvl", ""); - string visit = GetLoadOnGoto(level) && p.group.Permission >= GetPerVisitPermission(level) ? "%aYes" : "%cNo"; + string visit = GetLoadOnGoto(level) && (p == null || p.group.Permission >= GetPerVisitPermission(level)) ? "%aYes" : "%cNo"; unloadedLevels += ", " + Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]"; } } @@ -81,7 +80,7 @@ namespace MCGalaxy.Commands if (!levels.Contains(fi[i].Name.Replace(".lvl", "").ToLower())) { string level = fi[i].Name.Replace(".lvl", ""); - string visit = GetLoadOnGoto(level) && p.group.Permission >= GetPerVisitPermission(level) ? "%aYes" : "%cNo"; + string visit = GetLoadOnGoto(level) && (p == null || p.group.Permission >= GetPerVisitPermission(level)) ? "%aYes" : "%cNo"; unloadedLevels += ", " + Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]"; } } diff --git a/Games/IGame.cs b/Games/IGame.cs index 72d3d252c..a1227841e 100644 --- a/Games/IGame.cs +++ b/Games/IGame.cs @@ -21,5 +21,6 @@ namespace MCGalaxy.Games { public abstract class IGame { + } }