Use better format for /levels

This commit is contained in:
UnknownShadow200 2016-11-30 23:29:50 +11:00
parent 850004ba87
commit 603354ee7d
2 changed files with 21 additions and 25 deletions

View File

@ -31,32 +31,25 @@ namespace MCGalaxy.Commands {
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; }
string canVisit = "", canBuild = "";
Level[] loaded = LevelInfo.Loaded.Items; Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level lvl in loaded) { Player.Message(p, "Loaded maps [physics level] (&c[no] %Sif not visitable): ");
if (p == null || lvl.permissionvisit <= p.Rank) { MultiPageOutput.Output(p, loaded, (lvl, i) => FormatMap(p, lvl),
if (Group.findPerm(lvl.permissionbuild) != null) "levels", "maps", message, false);
canVisit += ", " + Group.findPerm(lvl.permissionbuild).color + lvl.name + " &b[&f" + lvl.physics + "&b]";
else
canVisit += ", " + lvl.name + " &b[" + lvl.physics + "]";
} else {
if (Group.findPerm(lvl.permissionvisit) != null)
canBuild += ", " + Group.findPerm(lvl.permissionvisit).color + lvl.name + " &b[&f" + lvl.physics + "&b]";
else
canBuild += ", " + lvl.name + " &b[&f" + lvl.physics + "&b]";
}
}
if (canVisit != "")
canVisit = canVisit.Remove(0, 2);
Player.Message(p, "Loaded levels [physics_level]: " + canVisit);
if (canBuild != "")
Player.Message(p, "Loaded levels you cannot visit: " + canBuild.Remove(0, 2));
Player.Message(p, "Use %T/unloaded %Sfor unloaded levels."); Player.Message(p, "Use %T/unloaded %Sfor unloaded levels.");
} }
static string FormatMap(Player p, Level lvl) {
bool canVisit = Player.IsSuper(p);
if (!canVisit) {
LevelAccess access = lvl.VisitAccess.Check(p);
canVisit = access == LevelAccess.Allowed || access == LevelAccess.Whitelisted;
}
string physics = " [" + lvl.physics + "]";
string visit = canVisit ? "" : " &c[no]";
return lvl.ColoredName + physics + visit;
}
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/levels"); Player.Message(p, "%T/levels");
Player.Message(p, "%HLists all loaded levels and their physics levels."); Player.Message(p, "%HLists all loaded levels and their physics levels.");

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] files = Directory.GetFiles("levels", "*.lvl"); string[] files = Directory.GetFiles("levels", "*.lvl");
Player.Message(p, "Unloaded maps (&c[no] %Sif not accessible): "); Player.Message(p, "Unloaded maps (&c[no] %Sif not visitable): ");
MultiPageOutput.Output(p, GetMaps(files), (map, i) => FormatMap(p, map), MultiPageOutput.Output(p, GetMaps(files), (map, i) => FormatMap(p, map),
"unloaded", "maps", message, false); "unloaded", "maps", message, false);
} }
@ -54,9 +54,12 @@ namespace MCGalaxy.Commands {
bool loadOnGoto; bool loadOnGoto;
RetrieveProps(map, out visitP, out buildP, out loadOnGoto); RetrieveProps(map, out visitP, out buildP, out loadOnGoto);
Group grp = Group.findPerm(buildP); LevelPermission perm = visitP;
if (perm < buildP) perm = buildP;
Group grp = Group.findPerm(perm);
string color = grp == null ? "&f" : grp.color; string color = grp == null ? "&f" : grp.color;
string visit = loadOnGoto && (p == null || p.Rank >= visitP) ? "" : " &c[no]" + color; string visit = loadOnGoto && (p == null || p.Rank >= visitP) ? "" : " &c[no]";
return color + map + visit; return color + map + visit;
} }