Now /ccols list uses pagintation too

This commit is contained in:
UnknownShadow200 2017-02-26 20:01:08 +11:00
parent cc773a82fe
commit 5de6a59c3d
5 changed files with 24 additions and 27 deletions

View File

@ -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

View File

@ -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<CustomColor> validCols = new List<CustomColor>(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) {

View File

@ -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;

View File

@ -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);

View File

@ -20,9 +20,11 @@ using System.Collections.Generic;
namespace MCGalaxy {
/// <summary> Outputs a large range of values across a number of 'pages'. </summary>
/// <summary> Outputs a large range of values across a number of 'pages'. (Pagination) </summary>
public static class MultiPageOutput {
/// <summary> Outputs a large range of values across a number of 'pages'. (Pagination) </summary>
/// <param name="lines">true if each item is printed on a separate line, false if combined. </param>
public static void Output<T>(Player p, IList<T> items, Func<T, string> formatter,
string cmd, string type, string modifier, bool lines) {
int page = 0, total = items.Count;