Fix /levels and /unloaded from console.

This commit is contained in:
UnknownShadow200 2016-01-23 22:00:49 +11:00
parent 270e62ac05
commit 8cad8ad507
3 changed files with 42 additions and 69 deletions

View File

@ -1,25 +1,25 @@
/* /*
Copyright 2012 MCGalaxy Copyright 2012 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 the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdLevels : Command public sealed class CmdLevels : Command {
{
public override string name { get { return "levels"; } } public override string name { get { return "levels"; } }
public override string shortcut { get { return "maps"; } } public override string shortcut { get { return "maps"; } }
public override string type { get { return CommandTypes.Information; } } public override string type { get { return CommandTypes.Information; } }
@ -27,62 +27,35 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public CmdLevels() { } public CmdLevels() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (message != "") { Help(p); return; }
try
{
if (!String.IsNullOrEmpty(message.Trim())) string canVisit = "", canBuild = "";
Server.levels.ForEach(
(level) =>
{ {
Help(p); if (p == null || level.permissionvisit <= p.group.Permission) {
return;
}
message = "";
string message2 = "";
bool Once = false;
Server.levels.ForEach((level) =>
{
if (p != null && level.permissionvisit <= p.group.Permission)
{
if (Group.findPerm(level.permissionbuild) != null) 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 else
message += ", " + level.name + " &b[" + level.physics + "]"; canVisit += ", " + level.name + " &b[" + level.physics + "]";
} } else {
else if (Group.findPerm(level.permissionvisit) != null)
{ canBuild += ", " + Group.findPerm(level.permissionvisit).color + level.name + " &b[&f" + level.physics + "&b]";
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 + "]";
}
else else
{ canBuild += ", " + level.name + " &b[&f" + level.physics + "&b]";
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]";
}
} }
}); });
Player.SendMessage(p, "Loaded levels [physics_level]: " + message.Remove(0, 2)); if (canVisit != "")
if (message2 != "") canVisit = canVisit.Remove(0, 2);
Player.SendMessage(p, "Can't Goto: " + message2); Player.SendMessage(p, "Loaded levels [physics_level]: " + canVisit);
Player.SendMessage(p, "Use &f/unloaded" + Server.DefaultColor + " for unloaded levels."); if (canBuild != "")
} Player.SendMessage(p, "Loaded levsl you cannot visit: " + canBuild.Remove(0, 2));
catch (Exception e) Player.SendMessage(p, "Use &f/unloaded" + Server.DefaultColor + " for unloaded levels.");
{
Server.ErrorLog(e);
}
} }
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."); Player.SendMessage(p, "%f/levels " + Server.DefaultColor + "- Lists all loaded levels and their physics levels.");
} }
} }

View File

@ -34,7 +34,6 @@ namespace MCGalaxy.Commands
try try
{ {
List<string> levels = new List<string>(Server.levels.Count); List<string> levels = new List<string>(Server.levels.Count);
string unloadedLevels = ""; int currentNum = 0; int maxMaps = 0; string unloadedLevels = ""; int currentNum = 0; int maxMaps = 0;
if (message != "") if (message != "")
@ -58,7 +57,7 @@ namespace MCGalaxy.Commands
if (!levels.Contains(file.Name.Replace(".lvl", "").ToLower())) if (!levels.Contains(file.Name.Replace(".lvl", "").ToLower()))
{ {
string level = file.Name.Replace(".lvl", ""); 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]"; 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())) if (!levels.Contains(fi[i].Name.Replace(".lvl", "").ToLower()))
{ {
string level = fi[i].Name.Replace(".lvl", ""); 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]"; unloadedLevels += ", " + Group.findPerm(GetPerBuildPermission(level)).color + level + " &b[" + visit + "&b]";
} }
} }

View File

@ -21,5 +21,6 @@ namespace MCGalaxy.Games {
public abstract class IGame { public abstract class IGame {
} }
} }