mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Improve /warp list / /waypoint list. (Thanks xnotx123)
This commit is contained in:
parent
f41f756127
commit
33236afc4e
@ -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);
|
||||
|
@ -190,15 +190,12 @@ namespace MCGalaxy.Eco {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary> Whether an award with that name exists. </summary>
|
||||
public static string FindExact(string name) {
|
||||
foreach (Award award in AwardsList)
|
||||
if (award.Name.CaselessEq(name)) return award.Name;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary> Gets the description of the award matching the given name,
|
||||
/// or an empty string if no matching award was found. </summary>
|
||||
|
||||
public static string GetDescription(string name) {
|
||||
foreach (Award award in AwardsList)
|
||||
if (award.Name.CaselessEq(name)) return award.Description;
|
||||
|
@ -27,8 +27,6 @@ namespace MCGalaxy.Network {
|
||||
int count = 0;
|
||||
public Level level;
|
||||
public Player player;
|
||||
|
||||
/// <summary> Constructs a bulk sender. </summary>
|
||||
public BufferedBlockSender() { }
|
||||
|
||||
/// <summary> Constructs a bulk sender that will send block changes to all players on that level. </summary>
|
||||
|
@ -20,40 +20,32 @@ using System;
|
||||
namespace MCGalaxy {
|
||||
/// <summary> Utility methods for reading/writing big endian integers, and fixed length strings. </summary>
|
||||
public static class NetUtils {
|
||||
|
||||
/// <summary> Number of bytes a string occupies in a packet.</summary>
|
||||
public const int StringSize = 64;
|
||||
|
||||
/// <summary> Reads a 16 bit signed integer, big endian form. </summary>
|
||||
|
||||
public static short ReadI16(byte[] array, int offset) {
|
||||
return (short)(array[offset] << 8 | array[offset + 1]);
|
||||
}
|
||||
|
||||
/// <summary> Reads a 16 bit unsigned integer, big endian form. </summary>
|
||||
|
||||
public static ushort ReadU16(byte[] array, int offset) {
|
||||
return (ushort)(array[offset] << 8 | array[offset + 1]);
|
||||
}
|
||||
|
||||
/// <summary> Reads a 32 bit signed integer, big endian form. </summary>
|
||||
public static int ReadI32(byte[] array, int offset) {
|
||||
return array[offset] << 24 | array[offset + 1] << 16
|
||||
| array[offset + 2] << 8 | array[offset + 3];
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Writes a 16 bit signed integer, big endian form. </summary>
|
||||
public static void WriteI16(short value, byte[] array, int index) {
|
||||
array[index++] = (byte)(value >> 8);
|
||||
array[index++] = (byte)(value);
|
||||
}
|
||||
|
||||
/// <summary> Writes a 16 bit unsigned integer, big endian form. </summary>
|
||||
public static void WriteU16(ushort value, byte[] array, int index) {
|
||||
array[index++] = (byte)(value >> 8);
|
||||
array[index++] = (byte)(value);
|
||||
}
|
||||
|
||||
/// <summary> Writes a 32 bit signed integer, big endian form. </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary> Writes three (X, Y, Z) either 16 or 32 bit signed integers, big endian form. </summary>
|
||||
/// <returns> Number of bytes written. </returns>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary> Reads a string of unicode characters. (input is 64 bytes). </summary>
|
||||
/// <remarks> String length may be less than 64, as string is trimmed of trailing spaces and nuls. </remarks>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary> Writes a string of unicode characters. (output is 64 bytes). </summary>
|
||||
/// <remarks> Unicode characters that are unable to be mapped into code page 437 are converted to '?'. </remarks>
|
||||
/// <remarks> If 'hasCP437' is false, characters that cannot be mapped to ASCII are converted to '?'. </remarks>
|
||||
|
||||
public static void Write(string str, byte[] array, int offset, bool hasCP437) {
|
||||
if (hasCP437) WriteCP437(str, array, offset);
|
||||
else WriteAscii(str, array, offset);
|
||||
|
Loading…
x
Reference in New Issue
Block a user