Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added readField methods to packet and added a method for reading all …

…the fields at once
  • Loading branch information...
commit a9513607de291c2062b8d4a0d781643f1dc42193 1 parent c0cf559
@Raphfrk authored
View
28 src/main/java/com/raphfrk/craftproxylib/fields/Field.java
@@ -251,7 +251,7 @@ public int getFixedLength() {
*
* @param packet the Packet
* @param the field index
- * @return the value of the
+ * @return the value of the field
*/
public static Object read(Packet packet, int i) throws IOException {
int id = packet.getId();
@@ -276,6 +276,32 @@ public static Object read(Packet packet, int i) throws IOException {
}
/**
+ * Reads the packet fields from a Packet.
+ *
+ * @param packet the Packet
+ * @return an array containing the values of the fields
+ */
+ public static Object[] readAll(Packet packet) throws IOException {
+ int id = packet.getId();
+ if (id < 0) {
+ return null;
+ }
+
+ packet.reset();
+ packet.setInputStream(null);
+
+ Field[] fields = expandedFieldMap[id];
+
+ Object[] values = new Object[fields.length];
+
+ for (int i = 0; i < fields.length; i++) {
+ values[i] = fields[i].read(packet);
+ }
+
+ return values;
+ }
+
+ /**
* Creates a String based on an array of Fields
*
* @param fields the field array
View
21 src/main/java/com/raphfrk/craftproxylib/packet/Packet.java
@@ -252,4 +252,25 @@ public void writeField(Field field, Object value) throws IOException {
}
}
}
+
+ /**
+ * Reads a Field from the Packet
+ *
+ * @param i the field index
+ * @return the value of the field
+ * @throws IOException
+ */
+ public Object readField(int i) throws IOException {
+ return Field.read(this, i);
+ }
+
+ /**
+ * Reads all the Fields from the Packet
+ *
+ * @return an array containing the values of the field
+ * @throws IOException
+ */
+ public Object readFields() throws IOException {
+ return Field.readAll(this);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.