Change /unloaded to /worlds, which just outputs all maps, regardless of whether loaded or not.

This commit is contained in:
UnknownShadow200 2017-08-11 18:11:04 +10:00
parent 2697c934cd
commit fc27c18379
4 changed files with 21 additions and 32 deletions

View File

@ -21,29 +21,22 @@ using System.IO;
using System.Text;
namespace MCGalaxy.Commands.Info {
public sealed class CmdUnloaded : Command {
public override string name { get { return "Unloaded"; } }
public sealed class CmdWorlds : Command {
public override string name { get { return "Worlds"; } }
public override string shortcut { get { return "Unloaded"; } }
public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message) {
string[] files = LevelInfo.AllMapFiles();
Player.Message(p, "Unloaded maps (&c[no] %Sif not visitable): ");
MultiPageOutput.Output(p, GetMaps(files), (map) => FormatMap(p, map),
"Unloaded", "maps", message, false);
}
static List<string> GetMaps(string[] files) {
List<string> maps = new List<string>(files.Length);
Level[] loaded = LevelInfo.Loaded.Items;
foreach (string file in files) {
string map = Path.GetFileNameWithoutExtension(file);
if (IsLoaded(loaded, map)) continue;
maps.Add(map);
for (int i = 0; i < files.Length; i++) {
files[i] = Path.GetFileNameWithoutExtension(files[i]);
}
return maps;
Player.Message(p, "Maps (&c[no] %Sif not visitable): ");
MultiPageOutput.Output(p, files, (map) => FormatMap(p, map),
"Worlds", "maps", message, false);
}
static string FormatMap(Player p, string map) {
@ -58,13 +51,6 @@ namespace MCGalaxy.Commands.Info {
return Group.GetColor(maxPerm) + map + visit;
}
static bool IsLoaded(Level[] loaded, string level) {
foreach (Level lvl in loaded) {
if (lvl.name.CaselessEq(level)) return true;
}
return false;
}
static void RetrieveProps(string level, out LevelPermission visit,
out LevelPermission build, out bool loadOnGoto) {
visit = LevelPermission.Guest;
@ -95,8 +81,8 @@ namespace MCGalaxy.Commands.Info {
struct SearchArgs { public string Visit, Build, LoadOnGoto; }
public override void Help(Player p) {
Player.Message(p, "%T/Unloaded");
Player.Message(p, "%H Lists unloaded maps/levels, and their accessible state.");
Player.Message(p, "%T/Worlds");
Player.Message(p, "%HLists maps/levels, and their accessible state.");
}
}
}

View File

@ -273,7 +273,7 @@
<Compile Include="Commands\Information\CmdDevs.cs" />
<Compile Include="Commands\Information\CmdTime.cs" />
<Compile Include="Commands\Information\CmdTop.cs" />
<Compile Include="Commands\Information\CmdUnloaded.cs" />
<Compile Include="Commands\Information\CmdWorlds.cs" />
<Compile Include="Commands\Information\CmdView.cs" />
<Compile Include="Commands\Information\CmdViewRanks.cs" />
<Compile Include="Commands\Information\CmdWhere.cs" />

View File

@ -74,12 +74,8 @@ namespace MCGalaxy.Network {
}
static int PlayerCount() {
Player[] players = PlayerInfo.Online.Items;
int count = 0;
foreach (Player p in players) {
if (!p.hidden) count++;
}
// This may happen if a VIP or a dev/mod joins an already full server.
int count = PlayerInfo.NonHiddenCount();
// This may happen if a VIP joins an already full server.
if (count > ServerConfig.MaxPlayers)
count = ServerConfig.MaxPlayers;
return count;

View File

@ -36,6 +36,13 @@ namespace MCGalaxy {
target.ColoredName : GetColor(name) + name.RemoveLastPlus(); // TODO: select color from database?
}
public static int NonHiddenCount() {
Player[] players = Online.Items;
int count = 0;
foreach (Player p in players) { if (!p.hidden) count++; }
return count;
}
[Obsolete("Prefer FindMatches() or FindExact()")]
public static Player Find(string name) {