From a3db32758cb3c56694d869ab567fc587ce0bff6f Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 20 Apr 2016 01:09:39 +0100 Subject: [PATCH] Add new is feature to PacketWrapper :) --- .../myles/ViaVersion/api/PacketWrapper.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 3b7362d72..7f8b4f643 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -56,6 +56,26 @@ public class PacketWrapper { throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Data", packetValues); } + /** + * Check if a type is at an index + * + * @param type The type of the part you wish to get. + * @param index The index of the part (relative to the type) + * @return True if the type is at the index + */ + public boolean is(Type type, int index) { + int currentIndex = 0; + for (Pair packetValue : packetValues) { + if (packetValue.getKey() == type) { // Ref check + if (currentIndex == index) { + return true; + } + currentIndex++; + } + } + return false; + } + /** * Set a currently existing part in the output *