diff --git a/pom.xml b/pom.xml
index e4607e3..20404b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.viaversion
nbt
- 3.4.0
+ 3.5.0
jar
ViaNBT
diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java
index f119bf0..0752575 100644
--- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java
+++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/ByteArrayTag.java
@@ -9,7 +9,7 @@ import java.util.Arrays;
/**
* A tag containing a byte array.
*/
-public class ByteArrayTag extends Tag {
+public class ByteArrayTag extends NumberArrayTag {
public static final int ID = 7;
private static final byte[] EMPTY_ARRAY = new byte[0];
private byte[] value;
@@ -73,15 +73,20 @@ public class ByteArrayTag extends Tag {
this.value[index] = value;
}
- /**
- * Gets the length of this tag's array.
- *
- * @return This tag's array length.
- */
+ @Override
public int length() {
return this.value.length;
}
+ @Override
+ public ListTag toListTag() {
+ final ListTag list = new ListTag(ByteTag.class);
+ for (final byte b : this.value) {
+ list.add(new ByteTag(b));
+ }
+ return list;
+ }
+
@Override
public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
tagLimiter.countInt();
diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java
index bfdcb51..5a1d21b 100644
--- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java
+++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/IntArrayTag.java
@@ -9,7 +9,7 @@ import java.util.Arrays;
/**
* A tag containing an integer array.
*/
-public class IntArrayTag extends Tag {
+public class IntArrayTag extends NumberArrayTag {
public static final int ID = 11;
private static final int[] EMPTY_ARRAY = new int[0];
private int[] value;
@@ -26,7 +26,7 @@ public class IntArrayTag extends Tag {
*
* @param value The value of the tag.
*/
- public IntArrayTag(int[] value) {
+ public IntArrayTag(final int[] value) {
if (value == null) {
throw new NullPointerException("value cannot be null");
}
@@ -48,7 +48,7 @@ public class IntArrayTag extends Tag {
*
* @param value New value of this tag.
*/
- public void setValue(int[] value) {
+ public void setValue(final int[] value) {
if (value == null) {
throw new NullPointerException("value cannot be null");
}
@@ -61,7 +61,7 @@ public class IntArrayTag extends Tag {
* @param index Index of the value.
* @return The value at the given index.
*/
- public int getValue(int index) {
+ public int getValue(final int index) {
return this.value[index];
}
@@ -71,21 +71,26 @@ public class IntArrayTag extends Tag {
* @param index Index of the value.
* @param value Value to set.
*/
- public void setValue(int index, int value) {
+ public void setValue(final int index, final int value) {
this.value[index] = value;
}
- /**
- * Gets the length of this tag's array.
- *
- * @return This tag's array length.
- */
+ @Override
public int length() {
return this.value.length;
}
@Override
- public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
+ public ListTag toListTag() {
+ final ListTag list = new ListTag();
+ for (final int i : this.value) {
+ list.add(new IntTag(i));
+ }
+ return list;
+ }
+
+ @Override
+ public void read(final DataInput in, final TagLimiter tagLimiter, final int nestingLevel) throws IOException {
tagLimiter.countInt();
this.value = new int[in.readInt()];
tagLimiter.countBytes(4 * this.value.length);
@@ -95,9 +100,9 @@ public class IntArrayTag extends Tag {
}
@Override
- public void write(DataOutput out) throws IOException {
+ public void write(final DataOutput out) throws IOException {
out.writeInt(this.value.length);
- for (int i : this.value) {
+ for (final int i : this.value) {
out.writeInt(i);
}
}
@@ -106,7 +111,7 @@ public class IntArrayTag extends Tag {
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- IntArrayTag that = (IntArrayTag) o;
+ final IntArrayTag that = (IntArrayTag) o;
return Arrays.equals(this.value, that.value);
}
diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongArrayTag.java
index e211d2f..3e8e53f 100644
--- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongArrayTag.java
+++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongArrayTag.java
@@ -9,7 +9,7 @@ import java.util.Arrays;
/**
* A tag containing a long array.
*/
-public class LongArrayTag extends Tag {
+public class LongArrayTag extends NumberArrayTag {
public static final int ID = 12;
private static final long[] EMPTY_ARRAY = new long[0];
private long[] value;
@@ -75,15 +75,20 @@ public class LongArrayTag extends Tag {
this.value[index] = value;
}
- /**
- * Gets the length of this tag's array.
- *
- * @return This tag's array length.
- */
+ @Override
public int length() {
return this.value.length;
}
+ @Override
+ public ListTag toListTag() {
+ final ListTag list = new ListTag(LongTag.class);
+ for (final long l : this.value) {
+ list.add(new LongTag(l));
+ }
+ return list;
+ }
+
@Override
public void read(DataInput in, TagLimiter tagLimiter, int nestingLevel) throws IOException {
tagLimiter.countInt();
diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/NumberArrayTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/NumberArrayTag.java
new file mode 100644
index 0000000..dd27e46
--- /dev/null
+++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/NumberArrayTag.java
@@ -0,0 +1,18 @@
+package com.github.steveice10.opennbt.tag.builtin;
+
+public abstract class NumberArrayTag extends Tag {
+
+ /**
+ * Gets the length of this tag's array.
+ *
+ * @return array length
+ */
+ public abstract int length();
+
+ /**
+ * Creates a new list tag from this tag.
+ *
+ * @return a new list tag
+ */
+ public abstract ListTag toListTag();
+}