Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.10</version>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/tv/rewinside/nbtstorage/nbt/NBTTagLongArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package tv.rewinside.nbtstorage.nbt;

import tv.rewinside.nbtstorage.exceptions.NBTLoadException;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;

public class NBTTagLongArray extends NBTBase {

private long[] data;

NBTTagLongArray() {
}

public NBTTagLongArray(long[] data) {
this.data = data;
}

@Override
void write(DataOutput dataOutput) throws IOException {
dataOutput.writeInt(this.data.length);

for (long value : this.data) {
dataOutput.writeLong(value);
}
}

@Override
void load(DataInput dataInput, int i, NBTReadLimiter nbtReadLimiter) throws IOException {
int count = dataInput.readInt();
if (count >= 1 << 24) throw new NBTLoadException("Error while loading LongArray");

nbtReadLimiter.allocate(64 * count);
this.data = new long[count];

for (int index = 0; index < count; index++) {
this.data[index] = dataInput.readLong();
}
}

@Override
public NBTType getType() {
return NBTType.LONG_ARRAY;
}

@Override
public long[] getData() {
return this.data;
}

@Override
public NBTBase clone() {
long[] copyData = new long[this.data.length];

System.arraycopy(this.data, 0, copyData, 0, this.data.length);
return new NBTTagLongArray(copyData);
}

@Override
public boolean equals(Object object) {
return super.equals(object) && Arrays.equals(this.data, ((NBTTagLongArray) object).data);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder("[");

for (long value : this.data) {
builder.append(value).append(",");
}
builder.append("]");

return builder.toString();
}

@Override
public int hashCode() {
return super.hashCode() ^ Arrays.hashCode(this.data);
}
}
3 changes: 2 additions & 1 deletion src/main/java/tv/rewinside/nbtstorage/nbt/NBTType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum NBTType {
STRING(8, NBTTagString.class),
LIST(9, NBTTagList.class),
COMPOUND(10, NBTTagCompound.class),
INT_ARRAY(11, NBTTagIntArray.class);
INT_ARRAY(11, NBTTagIntArray.class),
LONG_ARRAY(12, NBTTagLongArray.class);

private byte byteType;
private Class<? extends NBTBase> clazz;
Expand Down