From 33236afc4ec1e7bd2c918f2f5443b7953f4e6a1a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 14 Nov 2017 01:28:21 +1100 Subject: [PATCH] Improve /warp list / /waypoint list. (Thanks xnotx123) --- MCGalaxy/Commands/World/CmdWarp.cs | 15 +++++++----- MCGalaxy/Economy/Awards.cs | 5 +--- MCGalaxy/Network/Utils/BufferedBlockSender.cs | 2 -- MCGalaxy/Network/Utils/NetUtils.cs | 23 ++++--------------- 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/MCGalaxy/Commands/World/CmdWarp.cs b/MCGalaxy/Commands/World/CmdWarp.cs index b68c85e16..42a3f9644 100644 --- a/MCGalaxy/Commands/World/CmdWarp.cs +++ b/MCGalaxy/Commands/World/CmdWarp.cs @@ -17,6 +17,7 @@ */ using System; using System.Threading; +using MCGalaxy.Maths; namespace MCGalaxy.Commands.Misc { public class CmdWarp : Command { @@ -37,18 +38,20 @@ namespace MCGalaxy.Commands.Misc { UseCore(p, message, WarpList.Global, "Warp", true); } + static string FormatWarp(Warp warp) { + Vec3S32 pos = warp.Pos.BlockCoords; + return warp.Name + " - (" + pos.X + ", " + pos.Y + ", " + pos.Z + ") on " + warp.Level; + } + protected void UseCore(Player p, string message, WarpList warps, string group, bool checkExtraPerms) { string[] args = message.SplitSpaces(); string cmd = args[0]; if (cmd.Length == 0) { Help(p); return; } - if (args.Length == 1 && cmd.CaselessEq("list")) { - Player.Message(p, "{0}s:", group); - foreach (Warp wr in warps.Items) { - if (LevelInfo.FindExact(wr.Level) != null) - Player.Message(p, wr.Name + " : " + wr.Level); - } + if (cmd.CaselessEq("list")) { + string modifier = args.Length > 1 ? args[1] : ""; + MultiPageOutput.Output(p, warps.Items, FormatWarp, group + " list", group + "s", modifier, true); return; } else if (args.Length == 1) { Warp warp = Matcher.FindWarps(p, warps, cmd); diff --git a/MCGalaxy/Economy/Awards.cs b/MCGalaxy/Economy/Awards.cs index 816c4e079..c4f049d56 100644 --- a/MCGalaxy/Economy/Awards.cs +++ b/MCGalaxy/Economy/Awards.cs @@ -190,15 +190,12 @@ namespace MCGalaxy.Eco { return false; } - /// Whether an award with that name exists. public static string FindExact(string name) { foreach (Award award in AwardsList) if (award.Name.CaselessEq(name)) return award.Name; return null; } - - /// Gets the description of the award matching the given name, - /// or an empty string if no matching award was found. + public static string GetDescription(string name) { foreach (Award award in AwardsList) if (award.Name.CaselessEq(name)) return award.Description; diff --git a/MCGalaxy/Network/Utils/BufferedBlockSender.cs b/MCGalaxy/Network/Utils/BufferedBlockSender.cs index dd1012035..4af069512 100644 --- a/MCGalaxy/Network/Utils/BufferedBlockSender.cs +++ b/MCGalaxy/Network/Utils/BufferedBlockSender.cs @@ -27,8 +27,6 @@ namespace MCGalaxy.Network { int count = 0; public Level level; public Player player; - - /// Constructs a bulk sender. public BufferedBlockSender() { } /// Constructs a bulk sender that will send block changes to all players on that level. diff --git a/MCGalaxy/Network/Utils/NetUtils.cs b/MCGalaxy/Network/Utils/NetUtils.cs index 02afc5c18..39db5a171 100644 --- a/MCGalaxy/Network/Utils/NetUtils.cs +++ b/MCGalaxy/Network/Utils/NetUtils.cs @@ -20,40 +20,32 @@ using System; namespace MCGalaxy { /// Utility methods for reading/writing big endian integers, and fixed length strings. public static class NetUtils { - - /// Number of bytes a string occupies in a packet. public const int StringSize = 64; - - /// Reads a 16 bit signed integer, big endian form. + public static short ReadI16(byte[] array, int offset) { return (short)(array[offset] << 8 | array[offset + 1]); } - - /// Reads a 16 bit unsigned integer, big endian form. + public static ushort ReadU16(byte[] array, int offset) { return (ushort)(array[offset] << 8 | array[offset + 1]); } - /// Reads a 32 bit signed integer, big endian form. public static int ReadI32(byte[] array, int offset) { return array[offset] << 24 | array[offset + 1] << 16 | array[offset + 2] << 8 | array[offset + 3]; } - /// Writes a 16 bit signed integer, big endian form. public static void WriteI16(short value, byte[] array, int index) { array[index++] = (byte)(value >> 8); array[index++] = (byte)(value); } - /// Writes a 16 bit unsigned integer, big endian form. public static void WriteU16(ushort value, byte[] array, int index) { array[index++] = (byte)(value >> 8); array[index++] = (byte)(value); } - /// Writes a 32 bit signed integer, big endian form. public static void WriteI32(int value, byte[] array, int index) { array[index++] = (byte)(value >> 24); array[index++] = (byte)(value >> 16); @@ -61,8 +53,6 @@ namespace MCGalaxy { array[index++] = (byte)(value); } - /// Writes three (X, Y, Z) either 16 or 32 bit signed integers, big endian form. - /// Number of bytes written. internal static int WritePos(Position pos, byte[] arr, int offset, bool extPos) { if (!extPos) { WriteI16((short)pos.X, arr, offset + 0); @@ -75,10 +65,8 @@ namespace MCGalaxy { } return extPos ? 12 : 6; } + - - /// Reads a string of unicode characters. (input is 64 bytes). - /// String length may be less than 64, as string is trimmed of trailing spaces and nuls. public unsafe static string ReadString(byte[] data, int offset) { int length = 0; char* characters = stackalloc char[StringSize]; @@ -90,10 +78,7 @@ namespace MCGalaxy { } return new String(characters, 0, length); } - - /// Writes a string of unicode characters. (output is 64 bytes). - /// Unicode characters that are unable to be mapped into code page 437 are converted to '?'. - /// If 'hasCP437' is false, characters that cannot be mapped to ASCII are converted to '?'. + public static void Write(string str, byte[] array, int offset, bool hasCP437) { if (hasCP437) WriteCP437(str, array, offset); else WriteAscii(str, array, offset);