From c87c0a92990956ab401554ff9ff2c61e7c9c6be9 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 19 Jan 2014 00:27:57 +0100 Subject: [PATCH] Add support for legacy /packet commands. --- .../com/comphenix/protocol/CommandPacket.java | 4 +++ .../comphenix/protocol/PacketTypeParser.java | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandPacket.java b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandPacket.java index 2492d608..da7e8ba1 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/CommandPacket.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/CommandPacket.java @@ -188,6 +188,10 @@ class CommandPacket extends CommandBase { Set types = typeParser.parseTypes(arguments, PacketTypeParser.DEFAULT_MAX_RANGE); Boolean detailed = parseBoolean(arguments, "detailed"); + // Notify user + if (typeParser.getLastProtocol() == null) { + sender.sendMessage(ChatColor.YELLOW + "Warning: Missing protocol (PLAY, etc) - assuming legacy IDs."); + } if (arguments.size() > 0) { throw new IllegalArgumentException("Insufficient arguments."); } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java index 81a30de9..7432a0fa 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java @@ -16,13 +16,14 @@ import com.google.common.collect.Sets; class PacketTypeParser { public final static Range DEFAULT_MAX_RANGE = Ranges.closed(0, 255); + private Sender side = null; + private Protocol protocol = null; + public Set parseTypes(Deque arguments, Range defaultRange) { - Sender side = null; - Protocol protocol = null; Set result = Sets.newHashSet(); // Find these first - while (protocol == null || side == null) { + while (side == null) { String arg = arguments.poll(); // Attempt to parse a side or protocol first @@ -39,7 +40,7 @@ class PacketTypeParser { continue; } } - throw new IllegalArgumentException("No side and protocol specified."); + throw new IllegalArgumentException("Specify connection side (CLIENT or SERVER)."); } // Then we move on to parsing IDs (named packet types soon to come) @@ -68,6 +69,22 @@ class PacketTypeParser { return result; } + /** + * Retrieve the last parsed protocol. + * @return Last protocol. + */ + public Protocol getLastProtocol() { + return protocol; + } + + /** + * Retrieve the last sender. + * @return Last sender. + */ + public Sender getLastSide() { + return side; + } + /** * Parse a connection sides from a string. * @param text - the possible connection side.