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; using System.Text;
namespace MCGalaxy.Commands.Info { namespace MCGalaxy.Commands.Info {
public sealed class CmdUnloaded : Command { public sealed class CmdWorlds : Command {
public override string name { get { return "Unloaded"; } } public override string name { get { return "Worlds"; } }
public override string shortcut { get { return "Unloaded"; } }
public override string type { get { return CommandTypes.Information; } } public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] files = LevelInfo.AllMapFiles(); string[] files = LevelInfo.AllMapFiles();
Player.Message(p, "Unloaded maps (&c[no] %Sif not visitable): "); for (int i = 0; i < files.Length; i++) {
MultiPageOutput.Output(p, GetMaps(files), (map) => FormatMap(p, map), files[i] = Path.GetFileNameWithoutExtension(files[i]);
"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);
} }
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) { static string FormatMap(Player p, string map) {
@ -58,13 +51,6 @@ namespace MCGalaxy.Commands.Info {
return Group.GetColor(maxPerm) + map + visit; 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, static void RetrieveProps(string level, out LevelPermission visit,
out LevelPermission build, out bool loadOnGoto) { out LevelPermission build, out bool loadOnGoto) {
visit = LevelPermission.Guest; visit = LevelPermission.Guest;
@ -95,8 +81,8 @@ namespace MCGalaxy.Commands.Info {
struct SearchArgs { public string Visit, Build, LoadOnGoto; } struct SearchArgs { public string Visit, Build, LoadOnGoto; }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/Unloaded"); Player.Message(p, "%T/Worlds");
Player.Message(p, "%H Lists unloaded maps/levels, and their accessible state."); 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\CmdDevs.cs" />
<Compile Include="Commands\Information\CmdTime.cs" /> <Compile Include="Commands\Information\CmdTime.cs" />
<Compile Include="Commands\Information\CmdTop.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\CmdView.cs" />
<Compile Include="Commands\Information\CmdViewRanks.cs" /> <Compile Include="Commands\Information\CmdViewRanks.cs" />
<Compile Include="Commands\Information\CmdWhere.cs" /> <Compile Include="Commands\Information\CmdWhere.cs" />

View File

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

View File

@ -35,6 +35,13 @@ namespace MCGalaxy {
return target != null && Entities.CanSee(p, target) ? return target != null && Entities.CanSee(p, target) ?
target.ColoredName : GetColor(name) + name.RemoveLastPlus(); // TODO: select color from database? 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()")] [Obsolete("Prefer FindMatches() or FindExact()")]