From 5de6a59c3dcb1c5b017a79586e5f259df72b3021 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 26 Feb 2017 20:01:08 +1100 Subject: [PATCH] Now /ccols list uses pagintation too --- MCGalaxy/Blocks/Block.cs | 2 ++ MCGalaxy/Commands/CPE/CmdCustomColors.cs | 35 +++++++++------------ MCGalaxy/Commands/Information/CmdHelp.cs | 2 +- MCGalaxy/Commands/building/CmdPlace.cs | 8 ++--- MCGalaxy/util/Formatting/MultiPageOutput.cs | 4 ++- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/MCGalaxy/Blocks/Block.cs b/MCGalaxy/Blocks/Block.cs index 07eee6706..dd358a7f7 100644 --- a/MCGalaxy/Blocks/Block.cs +++ b/MCGalaxy/Blocks/Block.cs @@ -21,6 +21,8 @@ using MCGalaxy.Blocks; namespace MCGalaxy { public sealed partial class Block { + public static bool IsPhysicsId(byte block) { return block >= CpeCount && block != custom_block; } + public static bool Walkthrough(byte block) { return block == air || block == shrub || block == Block.snow || block == fire || block == rope diff --git a/MCGalaxy/Commands/CPE/CmdCustomColors.cs b/MCGalaxy/Commands/CPE/CmdCustomColors.cs index 8513553e8..025467dc0 100644 --- a/MCGalaxy/Commands/CPE/CmdCustomColors.cs +++ b/MCGalaxy/Commands/CPE/CmdCustomColors.cs @@ -16,6 +16,7 @@ permissions and limitations under the Licenses. */ using System; +using System.Collections.Generic; using System.Drawing; namespace MCGalaxy.Commands.CPE { @@ -40,7 +41,8 @@ namespace MCGalaxy.Commands.CPE { case "delete": RemoveHandler(p, args); break; case "list": - ListHandler(p, args, false); break; + string modifer = args.Length > 1 ? args[1] : ""; + ListHandler(p, "ccols list", modifer); break; case "edit": case "modify": EditHandler(p, args); break; @@ -96,28 +98,19 @@ namespace MCGalaxy.Commands.CPE { Player.Message(p, "Successfully removed a custom color."); } - internal static void ListHandler(Player p, string[] args, bool all) { - int offset = 0, index = 0, count = 0; - if (args != null && args.Length > 1) int.TryParse(args[1], out offset); - CustomColor[] cols = Colors.ExtColors; - - for (int i = 0; i < cols.Length; i++) { - CustomColor col = cols[i]; + internal static void ListHandler(Player p, string cmd, string modifier) { + List validCols = new List(Colors.ExtColors.Length); + foreach (CustomColor col in Colors.ExtColors) { if (col.Undefined) continue; - - if (index >= offset) { - count++; - const string format = "{4}{0} &{1}({2}){4} - %{1}, falls back to &{3}%{3}."; - Player.SendMessage(p, String.Format(format, col.Name, col.Code, col.Hex(), col.Fallback, Server.DefaultColor), false); - - if (count >= 8 && !all) { - const string helpFormat = "To see the next set of custom colors, type %T/ccols list {0}"; - Player.Message(p, helpFormat, offset + 8); - return; - } - } - index++; + validCols.Add(col); } + MultiPageOutput.Output(p, validCols, FormatColor, cmd, "colors", modifier, true); + } + + // Not very elegant, because we don't want the % to be escaped like everywhere else + static string FormatColor(CustomColor col) { + const string format = "{0} &{1}({2})%S - %&S{1}, falls back to &{3}%&{3}{3}"; + return String.Format(format, col.Name, col.Code, col.Hex(), col.Fallback); } void EditHandler(Player p, string[] args) { diff --git a/MCGalaxy/Commands/Information/CmdHelp.cs b/MCGalaxy/Commands/Information/CmdHelp.cs index 2bd01c2fe..01e266826 100644 --- a/MCGalaxy/Commands/Information/CmdHelp.cs +++ b/MCGalaxy/Commands/Information/CmdHelp.cs @@ -55,7 +55,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "4 - &4Maroon %S| 5 - &5Purple %S| 6 - &6Gold %S| 7 - &7Silver"); Player.Message(p, "8 - &8Gray %S| 9 - &9Blue %S| a - &aLime %S| b - &bAqua"); Player.Message(p, "c - &cRed %S| d - &dPink %S| e - &eYellow %S| f - &fWhite"); - CmdCustomColors.ListHandler(p, null, true); + CmdCustomColors.ListHandler(p, "help colors", "all"); break; default: if (CmdCommands.DoCommand(p, message)) break; diff --git a/MCGalaxy/Commands/building/CmdPlace.cs b/MCGalaxy/Commands/building/CmdPlace.cs index c7ec062a5..00d576539 100644 --- a/MCGalaxy/Commands/building/CmdPlace.cs +++ b/MCGalaxy/Commands/building/CmdPlace.cs @@ -36,10 +36,10 @@ namespace MCGalaxy.Commands.Building { string[] parts = message.Split(' '); switch (parts.Length) { case 1: - if (message == "") break; - - if (!CommandParser.GetBlock(p, parts[0], out block, out ext)) return; - break; + if (message == "") break; + + if (!CommandParser.GetBlock(p, parts[0], out block, out ext)) return; + break; case 3: x = (ushort)(ushort.Parse(parts[0]) * 32); y = (ushort)(ushort.Parse(parts[1]) * 32); diff --git a/MCGalaxy/util/Formatting/MultiPageOutput.cs b/MCGalaxy/util/Formatting/MultiPageOutput.cs index 1684a6ad3..7ba175d5f 100644 --- a/MCGalaxy/util/Formatting/MultiPageOutput.cs +++ b/MCGalaxy/util/Formatting/MultiPageOutput.cs @@ -20,9 +20,11 @@ using System.Collections.Generic; namespace MCGalaxy { - /// Outputs a large range of values across a number of 'pages'. + /// Outputs a large range of values across a number of 'pages'. (Pagination) public static class MultiPageOutput { + /// Outputs a large range of values across a number of 'pages'. (Pagination) + /// true if each item is printed on a separate line, false if combined. public static void Output(Player p, IList items, Func formatter, string cmd, string type, string modifier, bool lines) { int page = 0, total = items.Count;