Now /commands uses multi-page output.

This commit is contained in:
UnknownShadow200 2016-09-06 23:25:33 +10:00
parent 5a2aac4573
commit 037b4396ae
4 changed files with 76 additions and 77 deletions

View File

@ -43,10 +43,6 @@ namespace MCGalaxy.Commands {
p.ignoreIRC = !p.ignoreIRC; p.ignoreIRC = !p.ignoreIRC;
Player.Message(p, "{0} ignoring IRC chat", p.ignoreIRC ? "&cNow " : "&aNo longer "); Player.Message(p, "{0} ignoring IRC chat", p.ignoreIRC ? "&cNow " : "&aNo longer ");
CreateIgnoreFile(p); return; CreateIgnoreFile(p); return;
} else if (action == "global") {
p.ignoreGlobal = !p.ignoreGlobal;
Player.Message(p, "{0} ignoring global chat", p.ignoreGlobal ? "&cNow " : "&aNo longer ");
CreateIgnoreFile(p); return;
} else if (action == "titles") { } else if (action == "titles") {
p.ignoreTitles = !p.ignoreTitles; p.ignoreTitles = !p.ignoreTitles;
Player.Message(p, "{0} show before names in chat", Player.Message(p, "{0} show before names in chat",
@ -63,7 +59,6 @@ namespace MCGalaxy.Commands {
if (names != "") Player.Message(p, names); if (names != "") Player.Message(p, names);
if (p.ignoreAll) Player.Message(p, "&cIgnoring all chat"); if (p.ignoreAll) Player.Message(p, "&cIgnoring all chat");
if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat"); if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat");
if (p.ignoreGlobal) Player.Message(p, "&cIgnoring global chat");
if (p.ignoreTitles) Player.Message(p, "&cPlayer titles do not show before names in chat."); if (p.ignoreTitles) Player.Message(p, "&cPlayer titles do not show before names in chat.");
if (p.ignoreNicks) Player.Message(p, "&cCustom player nicks do not show in chat."); if (p.ignoreNicks) Player.Message(p, "&cCustom player nicks do not show in chat.");
return; return;
@ -109,7 +104,6 @@ namespace MCGalaxy.Commands {
Player.Message(p, "%T/ignore [name]"); Player.Message(p, "%T/ignore [name]");
Player.Message(p, "%HUsing the same name again will unignore."); Player.Message(p, "%HUsing the same name again will unignore.");
Player.Message(p, "%H If name is \"all\", all chat is ignored."); Player.Message(p, "%H If name is \"all\", all chat is ignored.");
Player.Message(p, "%H If name is \"global\", MCGalaxy global chat is ignored.");
Player.Message(p, "%H If name is \"irc\", IRC chat is ignored."); Player.Message(p, "%H If name is \"irc\", IRC chat is ignored.");
Player.Message(p, "%H If name is \"titles\", player titles before names are ignored."); Player.Message(p, "%H If name is \"titles\", player titles before names are ignored.");
Player.Message(p, "%H If name is \"nicks\", custom player nicks do not show in chat."); Player.Message(p, "%H If name is \"nicks\", custom player nicks do not show in chat.");

View File

@ -35,32 +35,42 @@ namespace MCGalaxy.Commands {
internal static bool DoCommand(Player p, string message) { internal static bool DoCommand(Player p, string message) {
string[] args = message.Split(' '); string[] args = message.Split(' ');
string sort = args.Length > 1 ? args[1].ToLower() : null; string sort = args.Length > 1 ? args[1].ToLower() : "";
string modifier = args.Length > 2 ? args[2] : sort;
// if user only provided name/names/rank/ranks, don't treat that as the modifier
if (args.Length == 2) {
if (modifier == "name" || modifier == "names" || modifier == "rank" || modifier == "ranks") {
modifier = "";
} else {
sort = "";
}
}
switch (args[0].ToLower()) { switch (args[0].ToLower()) {
case "build": case "build":
case "building": case "building":
PrintHelpForGroup(p, sort, "build", "Building"); break; PrintHelpForGroup(p, sort, modifier, "build", "Building"); break;
case "chat": case "chat":
PrintHelpForGroup(p, sort, "chat", "Chat"); break; PrintHelpForGroup(p, sort, modifier, "chat", "Chat"); break;
case "eco": case "eco":
case "economy": case "economy":
PrintHelpForGroup(p, sort, "eco", "Economy"); break; PrintHelpForGroup(p, sort, modifier, "eco", "Economy"); break;
case "mod": case "mod":
case "moderation": case "moderation":
PrintHelpForGroup(p, sort, "mod", "Moderation"); break; PrintHelpForGroup(p, sort, modifier, "mod", "Moderation"); break;
case "info": case "info":
case "information": case "information":
PrintHelpForGroup(p, sort, "info", "Information"); break; PrintHelpForGroup(p, sort, modifier, "info", "Information"); break;
case "game": case "game":
case "games": case "games":
PrintHelpForGroup(p, sort, "game", "Game"); break; PrintHelpForGroup(p, sort, modifier, "game", "Game"); break;
case "other": case "other":
case "others": case "others":
PrintHelpForGroup(p, sort, "other", "Other"); break; PrintHelpForGroup(p, sort, modifier, "other", "Other"); break;
case "maps": case "maps":
case "world": case "world":
PrintHelpForGroup(p, sort, "world", "World"); break; PrintHelpForGroup(p, sort, modifier, "world", "World"); break;
case "short": case "short":
case "shortcut": case "shortcut":
case "shortcuts": case "shortcuts":
@ -70,79 +80,76 @@ namespace MCGalaxy.Commands {
case "command": case "command":
case "": case "":
Group pGroup = p != null ? p.group : Group.findPerm(LevelPermission.Nobody); Group pGroup = p != null ? p.group : Group.findPerm(LevelPermission.Nobody);
PrintRankCommands(p, sort, pGroup, true); break; PrintRankCommands(p, sort, modifier, pGroup, true); break;
case "commandsall": case "commandsall":
case "commandall": case "commandall":
case "all": case "all":
PrintAllCommands(p, sort); break; PrintAllCommands(p, sort, modifier); break;
default: default:
Group grp = Group.Find(args[0]); Group grp = Group.Find(args[0]);
if (grp == null) return false; if (grp == null) return false;
PrintRankCommands(p, sort, grp, false); break; PrintRankCommands(p, sort, modifier, grp, false); break;
} }
return true; return true;
} }
static void PrintShortcuts(Player p, string sort) { static void PrintShortcuts(Player p, string modifier) {
bool list1 = sort == null || sort != "2"; List<Command> shortcuts = new List<Command>();
List<string> shortcuts = new List<string>(); foreach (Command cmd in Command.all.commands) {
foreach (Command c in Command.all.commands) { if (cmd.shortcut == "") continue;
if (p != null && !p.group.CanExecute(c) || c.shortcut == "") continue; if (p != null && !p.group.CanExecute(cmd)) continue;
shortcuts.Add(c.shortcut + " %S[" + c.name + "]"); shortcuts.Add(cmd);
} }
int top = list1 ? shortcuts.Count / 2 : shortcuts.Count; MultiPageOutput.Output(p, shortcuts,
StringBuilder cmds = new StringBuilder(); (cmd, i) => "&b" + cmd.shortcut + " %S[" + cmd.name + "]",
for (int i = list1 ? 0 : shortcuts.Count / 2; i < top; i++) "cmds shortcuts", "shortcuts", modifier, false);
cmds.Append(", &b").Append(shortcuts[i]);
if (list1) {
Player.Message(p, "Available shortcuts (1):");
Player.Message(p, cmds.ToString(2, cmds.Length - 2));
Player.Message(p, "Type %T/cmds shortcuts 2 %Sto view the rest of the list ");
} else {
Player.Message(p, "Available shortcuts (2):");
Player.Message(p, cmds.ToString(2, cmds.Length - 2));
Player.Message(p, "Type %T/cmds shortcuts 1 %Sto view the rest of the list ");
}
} }
static void PrintRankCommands(Player p, string sort, Group group, bool own) { static void PrintRankCommands(Player p, string sort, string modifier, Group group, bool own) {
List<Command> cmds = new List<Command>(); List<Command> cmds = new List<Command>();
foreach (Command c in Command.all.commands) { foreach (Command c in Command.all.commands) {
string disabled = Command.GetDisabledReason(c.Enabled); string disabled = Command.GetDisabledReason(c.Enabled);
if (!group.CanExecute(c) || disabled != null || c.name == null) continue; if (!group.CanExecute(c) || disabled != null || c.name == null) continue;
cmds.Add(c); cmds.Add(c);
} }
StringBuilder list = FormatCommands(cmds, sort); if (cmds.Count == 0) {
Player.Message(p, "{0} %Scannot use any commands.", group.ColoredName); return;
}
SortCommands(cmds, sort);
if (own) if (own)
Player.Message(p, "Available commands:"); Player.Message(p, "Available commands:");
else else
Player.Message(p, "Commands available to " + group.ColoredName + " %Srank:"); Player.Message(p, "Commands available to " + group.ColoredName + " %Srank:");
Player.Message(p, list.ToString(2, list.Length - 2)); string type = "cmds " + group.name;
if (sort != "") type += " " + sort;
MultiPageOutput.Output(p, cmds,
(cmd, i) => CmdHelp.GetColor(cmd) + cmd.name,
type, "commands", modifier, false);
Player.Message(p, "Type %T/help <command> %Sfor more help on a command."); Player.Message(p, "Type %T/help <command> %Sfor more help on a command.");
Player.Message(p, "Type %T/cmds shortcuts %Sfor a list of command shortcuts.");
Player.Message(p, "%bIf you can't see all commands, type %f/help %band choose a help category.");
} }
static void PrintAllCommands(Player p, string sort) { static void PrintAllCommands(Player p, string sort, string modifier) {
List<Command> cmds = new List<Command>(); List<Command> cmds = new List<Command>();
foreach (Command c in Command.all.commands) { foreach (Command c in Command.all.commands) {
if (c.name == null) continue; if (c.name == null) continue;
cmds.Add(c); cmds.Add(c);
} }
StringBuilder list = FormatCommands(cmds, sort); SortCommands(cmds, sort);
Player.Message(p, "All commands:"); Player.Message(p, "All commands:");
Player.Message(p, list.ToString(2, list.Length - 2));
string type = "cmds all";
if (sort != "") type += " " + sort;
MultiPageOutput.Output(p, cmds,
(cmd, i) => CmdHelp.GetColor(cmd) + cmd.name,
type, "commands", modifier, false);
Player.Message(p, "Type %T/help <command> %Sfor more help on a command."); Player.Message(p, "Type %T/help <command> %Sfor more help on a command.");
Player.Message(p, "Type %T/cmds shortcuts %Sfor a list of command shortcuts.");
Player.Message(p, "%bIf you can't see all commands, type %f/help %band choose a help category.");
} }
static void PrintHelpForGroup(Player p, string sort, static void PrintHelpForGroup(Player p, string sort, string modifier,
string type, string category) { string type, string category) {
List<Command> cmds = new List<Command>(); List<Command> cmds = new List<Command>();
foreach (Command c in Command.all.commands) { foreach (Command c in Command.all.commands) {
@ -151,37 +158,37 @@ namespace MCGalaxy.Commands {
if (!c.type.Contains(type) || c.name == null) continue; if (!c.type.Contains(type) || c.name == null) continue;
cmds.Add(c); cmds.Add(c);
} }
} }
StringBuilder list = FormatCommands(cmds, sort); if (cmds.Count == 0) {
if (list.Length == 0) { Player.Message(p, "You cannot use any of the " + category + " commands."); return;
Player.Message(p, "You cannot use any of the " + category + " commands."); }
} else { SortCommands(cmds, sort);
Player.Message(p, category + " commands you may use:"); Player.Message(p, category + " commands you may use:");
Player.Message(p, list.ToString(2, list.Length - 2) + ".");
} type = "cmds " + category;
if (sort != "") type += " " + sort;
MultiPageOutput.Output(p, cmds,
(cmd, i) => CmdHelp.GetColor(cmd) + cmd.name,
type, "commands", modifier, false);
Player.Message(p, "Type %T/help <command> %Sfor more help on a command.");
} }
static StringBuilder FormatCommands(List<Command> cmds, string sort) { static void SortCommands(List<Command> cmds, string sort) {
if (sort != null && (sort == "name" || sort == "names")) { if (sort == "name" || sort == "names") {
cmds.Sort((a, b) => a.name cmds.Sort((a, b) => a.name
.CompareTo(b.name)); .CompareTo(b.name));
} }
if (sort != null && (sort == "rank" || sort == "ranks")) { if (sort == "rank" || sort == "ranks") {
cmds.Sort((a, b) => GrpCommands.MinPerm(a) cmds.Sort((a, b) => GrpCommands.MinPerm(a)
.CompareTo(GrpCommands.MinPerm(b))); .CompareTo(GrpCommands.MinPerm(b)));
} }
StringBuilder list = new StringBuilder();
foreach (Command c in cmds)
list.Append(", ").Append(CmdHelp.GetColor(c)).Append(c.name);
return list;
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/commands [category] [sort]"); Player.Message(p, "%T/commands [category] <sort>");
Player.Message(p, "%HIf no category is given, outputs all commands you can use."); Player.Message(p, "%HIf no category is given, outputs all commands you can use.");
Player.Message(p, " %H\"shortcuts\" category outputs all command shortcuts."); Player.Message(p, " %H\"shortcuts\" category outputs all command shortcuts.");
Player.Message(p, " %H\"all\" category outputs all commands."); Player.Message(p, " %H\"all\" category outputs all commands.");
Player.Message(p, " %HIf category is a rank name, outputs all commands that rank can use."); Player.Message(p, " %HIf category is a rank name, outputs all commands that rank can use.");
Player.Message(p, "%HOther command categories:"); Player.Message(p, "%HOther command categories:");

View File

@ -525,7 +525,6 @@ namespace MCGalaxy {
try { try {
using (StreamWriter w = new StreamWriter(path)) { using (StreamWriter w = new StreamWriter(path)) {
if (ignoreAll) w.WriteLine("&all"); if (ignoreAll) w.WriteLine("&all");
if (ignoreGlobal) w.WriteLine("&global");
if (ignoreIRC) w.WriteLine("&irc"); if (ignoreIRC) w.WriteLine("&irc");
if (ignoreTitles) w.WriteLine("&titles"); if (ignoreTitles) w.WriteLine("&titles");
if (ignoreNicks) w.WriteLine("&nicks"); if (ignoreNicks) w.WriteLine("&nicks");
@ -546,8 +545,8 @@ namespace MCGalaxy {
try { try {
string[] lines = File.ReadAllLines(path); string[] lines = File.ReadAllLines(path);
foreach (string line in lines) { foreach (string line in lines) {
if (line == "&global") ignoreGlobal = true; if (line == "&global") continue; // deprecated /ignore global
else if (line == "&all") ignoreAll = true; if (line == "&all") ignoreAll = true;
else if (line == "&irc") ignoreIRC = true; else if (line == "&irc") ignoreIRC = true;
else if (line == "&titles") ignoreTitles = true; else if (line == "&titles") ignoreTitles = true;
else if (line == "&nicks") ignoreNicks = true; else if (line == "&nicks") ignoreNicks = true;
@ -558,8 +557,7 @@ namespace MCGalaxy {
Server.s.Log("Failed to load ignore list for: " + name); Server.s.Log("Failed to load ignore list for: " + name);
} }
if (ignoreAll || ignoreGlobal || ignoreIRC if (ignoreAll || ignoreIRC || ignoreTitles || ignoreNicks || listignored.Count > 0)
|| ignoreTitles || ignoreNicks || listignored.Count > 0)
SendMessage("&cType &a/ignore list &cto see who you are still ignoring"); SendMessage("&cType &a/ignore list &cto see who you are still ignoring");
} }

View File

@ -24,18 +24,18 @@ namespace MCGalaxy {
public static class MultiPageOutput { public static class MultiPageOutput {
public static void Output<T>(Player p, IList<T> items, Func<T, int, string> formatter, public static void Output<T>(Player p, IList<T> items, Func<T, int, string> formatter,
string cmd, string type, string input, bool lines) { string cmd, string type, string modifier, bool lines) {
int page = 0, total = items.Count; int page = 0, total = items.Count;
int perPage = lines ? 10 : 30; int perPage = lines ? 10 : 30;
if (input == "") { if (modifier == "") {
OutputPage(p, items, formatter, cmd, type, 1, lines); OutputPage(p, items, formatter, cmd, type, 1, lines);
if (total <= perPage) return; if (total <= perPage) return;
Player.Message(p, "To see all {0}, use %T/{1} all", type, cmd); Player.Message(p, "To see all {0}, use %T/{1} all", type, cmd);
} else if (input.CaselessEq("all")) { } else if (modifier.CaselessEq("all")) {
OutputItems(p, items, 0, items.Count, lines, formatter); OutputItems(p, items, 0, items.Count, lines, formatter);
Player.Message(p, "Showing {0} 1-{1} (out of {1})", type, items.Count); Player.Message(p, "Showing {0} 1-{1} (out of {1})", type, items.Count);
} else if (!int.TryParse(input, out page)) { } else if (!int.TryParse(modifier, out page)) {
Player.Message(p, "Page must be either \"all\" or an integer."); Player.Message(p, "Page must be either \"all\" or an integer.");
} else { } else {
OutputPage(p, items, formatter, cmd, type, page, lines); OutputPage(p, items, formatter, cmd, type, page, lines);