mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
Now /commands uses multi-page output.
This commit is contained in:
parent
5a2aac4573
commit
037b4396ae
@ -43,10 +43,6 @@ namespace MCGalaxy.Commands {
|
||||
p.ignoreIRC = !p.ignoreIRC;
|
||||
Player.Message(p, "{0} ignoring IRC chat", p.ignoreIRC ? "&cNow " : "&aNo longer ");
|
||||
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") {
|
||||
p.ignoreTitles = !p.ignoreTitles;
|
||||
Player.Message(p, "{0} show before names in chat",
|
||||
@ -63,7 +59,6 @@ namespace MCGalaxy.Commands {
|
||||
if (names != "") Player.Message(p, names);
|
||||
if (p.ignoreAll) Player.Message(p, "&cIgnoring all 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.ignoreNicks) Player.Message(p, "&cCustom player nicks do not show in chat.");
|
||||
return;
|
||||
@ -109,7 +104,6 @@ namespace MCGalaxy.Commands {
|
||||
Player.Message(p, "%T/ignore [name]");
|
||||
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 \"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 \"titles\", player titles before names are ignored.");
|
||||
Player.Message(p, "%H If name is \"nicks\", custom player nicks do not show in chat.");
|
||||
|
@ -35,32 +35,42 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
internal static bool DoCommand(Player p, string message) {
|
||||
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()) {
|
||||
case "build":
|
||||
case "building":
|
||||
PrintHelpForGroup(p, sort, "build", "Building"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "build", "Building"); break;
|
||||
case "chat":
|
||||
PrintHelpForGroup(p, sort, "chat", "Chat"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "chat", "Chat"); break;
|
||||
case "eco":
|
||||
case "economy":
|
||||
PrintHelpForGroup(p, sort, "eco", "Economy"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "eco", "Economy"); break;
|
||||
case "mod":
|
||||
case "moderation":
|
||||
PrintHelpForGroup(p, sort, "mod", "Moderation"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "mod", "Moderation"); break;
|
||||
case "info":
|
||||
case "information":
|
||||
PrintHelpForGroup(p, sort, "info", "Information"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "info", "Information"); break;
|
||||
case "game":
|
||||
case "games":
|
||||
PrintHelpForGroup(p, sort, "game", "Game"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "game", "Game"); break;
|
||||
case "other":
|
||||
case "others":
|
||||
PrintHelpForGroup(p, sort, "other", "Other"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "other", "Other"); break;
|
||||
case "maps":
|
||||
case "world":
|
||||
PrintHelpForGroup(p, sort, "world", "World"); break;
|
||||
PrintHelpForGroup(p, sort, modifier, "world", "World"); break;
|
||||
case "short":
|
||||
case "shortcut":
|
||||
case "shortcuts":
|
||||
@ -70,44 +80,33 @@ namespace MCGalaxy.Commands {
|
||||
case "command":
|
||||
case "":
|
||||
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 "commandall":
|
||||
case "all":
|
||||
PrintAllCommands(p, sort); break;
|
||||
PrintAllCommands(p, sort, modifier); break;
|
||||
default:
|
||||
Group grp = Group.Find(args[0]);
|
||||
if (grp == null) return false;
|
||||
PrintRankCommands(p, sort, grp, false); break;
|
||||
PrintRankCommands(p, sort, modifier, grp, false); break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PrintShortcuts(Player p, string sort) {
|
||||
bool list1 = sort == null || sort != "2";
|
||||
List<string> shortcuts = new List<string>();
|
||||
foreach (Command c in Command.all.commands) {
|
||||
if (p != null && !p.group.CanExecute(c) || c.shortcut == "") continue;
|
||||
shortcuts.Add(c.shortcut + " %S[" + c.name + "]");
|
||||
static void PrintShortcuts(Player p, string modifier) {
|
||||
List<Command> shortcuts = new List<Command>();
|
||||
foreach (Command cmd in Command.all.commands) {
|
||||
if (cmd.shortcut == "") continue;
|
||||
if (p != null && !p.group.CanExecute(cmd)) continue;
|
||||
shortcuts.Add(cmd);
|
||||
}
|
||||
|
||||
int top = list1 ? shortcuts.Count / 2 : shortcuts.Count;
|
||||
StringBuilder cmds = new StringBuilder();
|
||||
for (int i = list1 ? 0 : shortcuts.Count / 2; i < top; i++)
|
||||
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 ");
|
||||
}
|
||||
MultiPageOutput.Output(p, shortcuts,
|
||||
(cmd, i) => "&b" + cmd.shortcut + " %S[" + cmd.name + "]",
|
||||
"cmds shortcuts", "shortcuts", modifier, false);
|
||||
}
|
||||
|
||||
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>();
|
||||
foreach (Command c in Command.all.commands) {
|
||||
string disabled = Command.GetDisabledReason(c.Enabled);
|
||||
@ -115,34 +114,42 @@ namespace MCGalaxy.Commands {
|
||||
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)
|
||||
Player.Message(p, "Available commands:");
|
||||
else
|
||||
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/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>();
|
||||
foreach (Command c in Command.all.commands) {
|
||||
if (c.name == null) continue;
|
||||
cmds.Add(c);
|
||||
}
|
||||
|
||||
StringBuilder list = FormatCommands(cmds, sort);
|
||||
SortCommands(cmds, sort);
|
||||
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/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) {
|
||||
List<Command> cmds = new List<Command>();
|
||||
foreach (Command c in Command.all.commands) {
|
||||
@ -153,33 +160,33 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder list = FormatCommands(cmds, sort);
|
||||
if (list.Length == 0) {
|
||||
Player.Message(p, "You cannot use any of the " + category + " commands.");
|
||||
} else {
|
||||
Player.Message(p, category + " commands you may use:");
|
||||
Player.Message(p, list.ToString(2, list.Length - 2) + ".");
|
||||
if (cmds.Count == 0) {
|
||||
Player.Message(p, "You cannot use any of the " + category + " commands."); return;
|
||||
}
|
||||
SortCommands(cmds, sort);
|
||||
Player.Message(p, category + " commands you may use:");
|
||||
|
||||
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) {
|
||||
if (sort != null && (sort == "name" || sort == "names")) {
|
||||
static void SortCommands(List<Command> cmds, string sort) {
|
||||
if (sort == "name" || sort == "names") {
|
||||
cmds.Sort((a, b) => a.name
|
||||
.CompareTo(b.name));
|
||||
}
|
||||
if (sort != null && (sort == "rank" || sort == "ranks")) {
|
||||
if (sort == "rank" || sort == "ranks") {
|
||||
cmds.Sort((a, b) => GrpCommands.MinPerm(a)
|
||||
.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) {
|
||||
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, " %H\"shortcuts\" category outputs all command shortcuts.");
|
||||
Player.Message(p, " %H\"all\" category outputs all commands.");
|
||||
|
@ -525,7 +525,6 @@ namespace MCGalaxy {
|
||||
try {
|
||||
using (StreamWriter w = new StreamWriter(path)) {
|
||||
if (ignoreAll) w.WriteLine("&all");
|
||||
if (ignoreGlobal) w.WriteLine("&global");
|
||||
if (ignoreIRC) w.WriteLine("&irc");
|
||||
if (ignoreTitles) w.WriteLine("&titles");
|
||||
if (ignoreNicks) w.WriteLine("&nicks");
|
||||
@ -546,8 +545,8 @@ namespace MCGalaxy {
|
||||
try {
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
foreach (string line in lines) {
|
||||
if (line == "&global") ignoreGlobal = true;
|
||||
else if (line == "&all") ignoreAll = true;
|
||||
if (line == "&global") continue; // deprecated /ignore global
|
||||
if (line == "&all") ignoreAll = true;
|
||||
else if (line == "&irc") ignoreIRC = true;
|
||||
else if (line == "&titles") ignoreTitles = true;
|
||||
else if (line == "&nicks") ignoreNicks = true;
|
||||
@ -558,8 +557,7 @@ namespace MCGalaxy {
|
||||
Server.s.Log("Failed to load ignore list for: " + name);
|
||||
}
|
||||
|
||||
if (ignoreAll || ignoreGlobal || ignoreIRC
|
||||
|| ignoreTitles || ignoreNicks || listignored.Count > 0)
|
||||
if (ignoreAll || ignoreIRC || ignoreTitles || ignoreNicks || listignored.Count > 0)
|
||||
SendMessage("&cType &a/ignore list &cto see who you are still ignoring");
|
||||
}
|
||||
|
||||
|
@ -24,18 +24,18 @@ namespace MCGalaxy {
|
||||
public static class MultiPageOutput {
|
||||
|
||||
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 perPage = lines ? 10 : 30;
|
||||
|
||||
if (input == "") {
|
||||
if (modifier == "") {
|
||||
OutputPage(p, items, formatter, cmd, type, 1, lines);
|
||||
if (total <= perPage) return;
|
||||
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);
|
||||
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.");
|
||||
} else {
|
||||
OutputPage(p, items, formatter, cmd, type, page, lines);
|
||||
|
Loading…
x
Reference in New Issue
Block a user