Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Add Region file reading support #13

Closed
wants to merge 21 commits into from
Closed
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
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ buildscript {
}
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.2.8' // Coveralls dependency
classpath 'net.saliman:gradle-cobertura-plugin:2.6.0' // Coveralls dependency
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.10.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
}
Expand Down Expand Up @@ -83,8 +83,8 @@ license {

// Source compiler configuration
configure([compileJava, compileTestJava]) {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:all'
options.compilerArgs << '-Xlint:-path'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>Flow NBT</name>
<groupId>com.flowpowered</groupId>
<artifactId>flow-nbt</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<inceptionYear>2011</inceptionYear>
<url>https://flowpowered.com/nbt</url>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/ByteArrayTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ByteArrayTag extends Tag<byte[]> {
/**
* The value.
*/
private final byte[] value;
private byte[] value;

/**
* Creates the tag.
Expand All @@ -50,6 +50,11 @@ public byte[] getValue() {
return value;
}

@Override
public void setValue(byte[] value) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you make every Tag mutable!? D': cries
I don't care what @kashike says, this is one of my favorite NBT libraries.
Immutable Tags are one reason for that.

If everyone really wants this.... cries some more
Maybe it should be in its own PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you ever tried to change the position of an entity in chunk with the NBT data being immutable?

Maybe it should be in its own PR?

IIRC this was, but I merged it onto my dev branch and I later build the API changes on top of it; sorry.

this.value = value;
}

@Override
public String toString() {
StringBuilder hex = new StringBuilder();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/ByteTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class ByteTag extends Tag<Byte> {
/**
* The value.
*/
private final byte value;
private byte value;

/**
* Creates the tag.<br> Boolean true is stored as 1 and boolean false is stored as 0.
Expand Down Expand Up @@ -58,6 +58,11 @@ public Byte getValue() {
return value;
}

@Override
public void setValue(Byte value) {
this.value = value;
}

public boolean getBooleanValue() {
return value != 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/flowpowered/nbt/CompoundMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public CompoundMap(Iterable<Tag<?>> initial, boolean sort, boolean reverse) {
}
}
if (initial != null) {
for (Tag t : initial) {
for (Tag<?> t : initial) {
put(t);
}
}
Expand Down Expand Up @@ -205,8 +205,8 @@ public boolean equals(Object o) {
Iterator<Tag<?>> iThis = iterator();
Iterator<Tag<?>> iOther = other.iterator();
while (iThis.hasNext() && iOther.hasNext()) {
Tag tThis = iThis.next();
Tag tOther = iOther.next();
Tag<?> tThis = iThis.next();
Tag<?> tOther = iOther.next();
if (!tThis.equals(tOther)) {
return false;
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/flowpowered/nbt/CompoundTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CompoundTag extends Tag<CompoundMap> {
/**
* The value.
*/
private final CompoundMap value;
private CompoundMap value;

/**
* Creates the tag.
Expand All @@ -49,6 +49,11 @@ public CompoundMap getValue() {
return value;
}

@Override
public void setValue(CompoundMap value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand All @@ -59,14 +64,15 @@ public String toString() {

StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n");
for (Tag entry : value.values()) {
for (Tag<?> entry : value.values()) {
bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
bldr.append("}");
return bldr.toString();
}

public CompoundTag clone() {
@Override
public CompoundTag clone() {
CompoundMap map = new CompoundMap(value);
return new CompoundTag(getName(), map);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/DoubleTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class DoubleTag extends Tag<Double> {
/**
* The value.
*/
private final double value;
private double value;

/**
* Creates the tag.
Expand All @@ -48,6 +48,11 @@ public Double getValue() {
return value;
}

@Override
public void setValue(Double value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/flowpowered/nbt/EndTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public Object getValue() {
return null;
}

@Override
public void setValue(Object value) {
throw new UnsupportedOperationException();
}

@Override
public String toString() {
return "TAG_End";
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/FloatTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class FloatTag extends Tag<Float> {
/**
* The value.
*/
private final float value;
private float value;

/**
* Creates the tag.
Expand All @@ -48,6 +48,11 @@ public Float getValue() {
return value;
}

@Override
public void setValue(Float value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/IntArrayTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class IntArrayTag extends Tag<int[]> {
/**
* The value.
*/
private final int[] value;
private int[] value;

/**
* Creates the tag.
Expand All @@ -47,6 +47,11 @@ public int[] getValue() {
return value;
}

@Override
public void setValue(int[] value) {
this.value = value;
}

@Override
public String toString() {
StringBuilder hex = new StringBuilder();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/IntTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class IntTag extends Tag<Integer> {
/**
* The value.
*/
private final int value;
private int value;

/**
* Creates the tag.
Expand All @@ -48,6 +48,11 @@ public Integer getValue() {
return value;
}

@Override
public void setValue(Integer value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/flowpowered/nbt/ListTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> {
/**
* The value.
*/
private final List<T> value;
private List<T> value;

/**
* Creates the tag.
Expand All @@ -50,7 +50,7 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> {
public ListTag(String name, Class<T> type, List<T> value) {
super(TagType.TAG_LIST, name);
this.type = type;
this.value = Collections.unmodifiableList(value);
this.value = value;
}

/**
Expand All @@ -67,6 +67,11 @@ public List<T> getValue() {
return value;
}

@Override
public void setValue(List<T> value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand All @@ -77,14 +82,15 @@ public String toString() {

StringBuilder bldr = new StringBuilder();
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(TagType.getByTagClass(type).getTypeName()).append("\r\n{\r\n");
for (Tag t : value) {
for (Tag<?> t : value) {
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
bldr.append("}");
return bldr.toString();
}

@SuppressWarnings ("unchecked")
@Override
@SuppressWarnings ("unchecked")
public ListTag<T> clone() {
List<T> newList = new ArrayList<T>();

Expand Down
101 changes: 101 additions & 0 deletions src/main/java/com/flowpowered/nbt/LongArrayTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* This file is part of Flow NBT, licensed under the MIT License (MIT).
*
* Copyright (c) 2011 Flow Powered <https://flowpowered.com/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.flowpowered.nbt;

import java.util.Arrays;

public class LongArrayTag extends Tag<long[]> {
/**
* The value.
*/
private long[] value;

/**
* Creates the tag.
*
* @param name The name.
* @param value The value.
*/
public LongArrayTag(String name, long[] value) {
super(TagType.TAG_LONG_ARRAY, name);
this.value = value;
}

@Override
public long[] getValue() {
return value;
}

@Override
public void setValue(long[] value) {
this.value = value;
}

@Override
public String toString() {
StringBuilder hex = new StringBuilder();
for (long s : value) {
String hexDigits = Long.toHexString(s).toUpperCase();
if (hexDigits.length() == 1) {
hex.append("0");
}
hex.append(hexDigits).append(" ");
}

String name = getName();
String append = "";
if (name != null && !name.equals("")) {
append = "(\"" + this.getName() + "\")";
}
return "TAG_Long_Array" + append + ": " + hex.toString();
}

@Override
public LongArrayTag clone() {
long[] clonedArray = cloneArray(value);

return new LongArrayTag(getName(), clonedArray);
}

@Override
public boolean equals(Object other) {
if (!(other instanceof LongArrayTag)) {
return false;
}

LongArrayTag tag = (LongArrayTag) other;
return Arrays.equals(value, tag.value) && getName().equals(tag.getName());
}

private long[] cloneArray(long[] longArray) {
if (longArray == null) {
return null;
} else {
int length = longArray.length;
byte[] newArray = new byte[length];
System.arraycopy(longArray, 0, newArray, 0, length);
return longArray;
}
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/flowpowered/nbt/LongTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class LongTag extends Tag<Long> {
/**
* The value.
*/
private final long value;
private long value;

/**
* Creates the tag.
Expand All @@ -48,6 +48,11 @@ public Long getValue() {
return value;
}

@Override
public void setValue(Long value) {
this.value = value;
}

@Override
public String toString() {
String name = getName();
Expand Down
Loading