Archiviert
13
0

Add support for legacy /packet commands.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2014-01-19 00:27:57 +01:00
Ursprung d70e9d28d4
Commit c87c0a9299
2 geänderte Dateien mit 25 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -188,6 +188,10 @@ class CommandPacket extends CommandBase {
Set<PacketType> types = typeParser.parseTypes(arguments, PacketTypeParser.DEFAULT_MAX_RANGE); Set<PacketType> types = typeParser.parseTypes(arguments, PacketTypeParser.DEFAULT_MAX_RANGE);
Boolean detailed = parseBoolean(arguments, "detailed"); 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) { if (arguments.size() > 0) {
throw new IllegalArgumentException("Insufficient arguments."); throw new IllegalArgumentException("Insufficient arguments.");
} }

Datei anzeigen

@ -16,13 +16,14 @@ import com.google.common.collect.Sets;
class PacketTypeParser { class PacketTypeParser {
public final static Range<Integer> DEFAULT_MAX_RANGE = Ranges.closed(0, 255); public final static Range<Integer> DEFAULT_MAX_RANGE = Ranges.closed(0, 255);
private Sender side = null;
private Protocol protocol = null;
public Set<PacketType> parseTypes(Deque<String> arguments, Range<Integer> defaultRange) { public Set<PacketType> parseTypes(Deque<String> arguments, Range<Integer> defaultRange) {
Sender side = null;
Protocol protocol = null;
Set<PacketType> result = Sets.newHashSet(); Set<PacketType> result = Sets.newHashSet();
// Find these first // Find these first
while (protocol == null || side == null) { while (side == null) {
String arg = arguments.poll(); String arg = arguments.poll();
// Attempt to parse a side or protocol first // Attempt to parse a side or protocol first
@ -39,7 +40,7 @@ class PacketTypeParser {
continue; 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) // Then we move on to parsing IDs (named packet types soon to come)
@ -68,6 +69,22 @@ class PacketTypeParser {
return result; 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. * Parse a connection sides from a string.
* @param text - the possible connection side. * @param text - the possible connection side.