Make Tag an interface, move packages

This commit is contained in:
Nassim Jahnke 2023-12-31 15:26:59 +01:00
parent d43da3189e
commit b15b783c2f
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
47 changed files with 348 additions and 416 deletions

View File

@ -1,5 +1,5 @@
Copyright (C) 2013-2017 Steveice10
Copyright (C) 2021-2023 ViaVersion and contributors
Copyright (C) 2021-2024 ViaVersion and contributors
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:

View File

@ -8,11 +8,12 @@ This project is derived from an earlier version of [OpenNBT](https://github.com/
* `SNBT` for string serialization
* Add primitive getter methods to number types
* Don't wrap values given in Tag#setValue / Tag constructors
* Abstract NumberTag class for easier number handling
* NumberTag and NumberArrayTag interfaces for easier number handling
* Don't use reflection when creating tag instances
* Directly use value in copy(), also replacing clone()
* Implement tag specific equals() methods
* Update to Java 8
* A bunch of other small improvements and fixes
This project also includes code from [adventure](https://github.com/KyoriPowered/adventure) used for SNBT serialization.
@ -31,7 +32,7 @@ This project also includes code from [adventure](https://github.com/KyoriPowered
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>nbt</artifactId>
<version>4.0.0</version>
<version>5.0.0</version>
</dependency>
```
@ -43,7 +44,7 @@ repositories {
}
dependencies {
implementation("com.viaversion:nbt:4.0.0")
implementation("com.viaversion:nbt:5.0.0")
}
```

13
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>com.viaversion</groupId>
<artifactId>nbt</artifactId>
<version>4.4.5</version>
<version>5.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ViaNBT</name>
@ -48,21 +48,20 @@
<issueManagement>
<system>GitHub</system>
<url>https://github.com/ViaVersion/OpenNBT/issues</url>
<url>https://github.com/ViaVersion/ViaNBT/issues</url>
</issueManagement>
<dependencies>
<!-- Expected to be bundled -->
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.2</version>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<version>24.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -73,7 +72,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version>
<version>3.6.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
@ -91,7 +90,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>

View File

@ -1,67 +0,0 @@
package com.github.steveice10.opennbt.tag.builtin;
import com.github.steveice10.opennbt.stringified.SNBT;
import java.io.DataOutput;
import java.io.IOException;
/**
* Represents an NBT tag.
* <p>
* Tags should also have setter methods specific to their value types.
*/
public abstract class Tag {
/**
* Returns the value of this tag.
*
* @return value of this tag
*/
public abstract Object getValue();
/**
* Returns the raw string representation of the value of this tag.
* For SNBT, use {@link SNBT#serialize(Tag)}.
*
* @return raw string representation of the value of this tag
*/
public abstract String asRawString();
/**
* Returns the unchecked value of this tag.
* <p>
* <b>The generic of this method might be removed in a later version</b>
*
* @param <T> expected type
* @return unchecked value of this tag
*/
public <T> T value() {
return (T) getValue();
}
/**
* Writes this tag to an output stream.
*
* @param out data output to write to
* @throws IOException if an I/O error occurs
*/
public abstract void write(DataOutput out) throws IOException;
/**
* Returns the NBT tag id of this tag type, used in I/O.
*
* @return ID of the tag this class represents
*/
public abstract int getTagId();
/**
* Returns a copy of this tag.
*
* @return a copy of this tag
*/
public abstract Tag copy();
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,4 +1,4 @@
package com.github.steveice10.opennbt.conversion;
package com.viaversion.nbt.conversion;
/**
* An exception thrown when an error occurs while converting something.

View File

@ -1,31 +1,31 @@
package com.github.steveice10.opennbt.conversion;
package com.viaversion.nbt.conversion;
import com.github.steveice10.opennbt.conversion.converter.ByteArrayTagConverter;
import com.github.steveice10.opennbt.conversion.converter.ByteTagConverter;
import com.github.steveice10.opennbt.conversion.converter.CompoundTagConverter;
import com.github.steveice10.opennbt.conversion.converter.DoubleTagConverter;
import com.github.steveice10.opennbt.conversion.converter.FloatTagConverter;
import com.github.steveice10.opennbt.conversion.converter.IntArrayTagConverter;
import com.github.steveice10.opennbt.conversion.converter.IntTagConverter;
import com.github.steveice10.opennbt.conversion.converter.ListTagConverter;
import com.github.steveice10.opennbt.conversion.converter.LongArrayTagConverter;
import com.github.steveice10.opennbt.conversion.converter.LongTagConverter;
import com.github.steveice10.opennbt.conversion.converter.ShortTagConverter;
import com.github.steveice10.opennbt.conversion.converter.StringTagConverter;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.conversion.converter.ByteArrayTagConverter;
import com.viaversion.nbt.conversion.converter.ByteTagConverter;
import com.viaversion.nbt.conversion.converter.CompoundTagConverter;
import com.viaversion.nbt.conversion.converter.DoubleTagConverter;
import com.viaversion.nbt.conversion.converter.FloatTagConverter;
import com.viaversion.nbt.conversion.converter.IntArrayTagConverter;
import com.viaversion.nbt.conversion.converter.IntTagConverter;
import com.viaversion.nbt.conversion.converter.ListTagConverter;
import com.viaversion.nbt.conversion.converter.LongArrayTagConverter;
import com.viaversion.nbt.conversion.converter.LongTagConverter;
import com.viaversion.nbt.conversion.converter.ShortTagConverter;
import com.viaversion.nbt.conversion.converter.StringTagConverter;
import com.viaversion.nbt.io.TagRegistry;
import com.viaversion.nbt.tag.ByteArrayTag;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.DoubleTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.ShortTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.HashMap;

View File

@ -1,6 +1,6 @@
package com.github.steveice10.opennbt.conversion;
package com.viaversion.nbt.conversion;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.tag.Tag;
/**
* A converter that converts between a tag type and a value type. A converted tag will have its value and all children converted to raw types and vice versa.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.ByteArrayTag;
/**
* A converter that converts between ByteArrayTag and byte[].

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.ByteTag;
/**
* A converter that converts between ByteTag and byte.

View File

@ -1,9 +1,9 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.conversion.ConverterRegistry;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.DoubleTag;
/**
* A converter that converts between DoubleTag and double.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.FloatTag;
/**
* A converter that converts between FloatTag and float.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.IntArrayTag;
/**
* A converter that converts between IntArrayTag and int[].

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.IntTag;
/**
* A converter that converts between IntTag and int.

View File

@ -1,9 +1,9 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.ConverterRegistry;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.conversion.ConverterRegistry;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.Tag;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.LongArrayTag;
/**
* A converter that converts between LongArrayTag and long[].

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.LongTag;
/**
* A converter that converts between LongTag and long.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.ShortTag;
/**
* A converter that converts between ShortTag and short.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.conversion.converter;
package com.viaversion.nbt.conversion.converter;
import com.github.steveice10.opennbt.conversion.TagConverter;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.nbt.conversion.TagConverter;
import com.viaversion.nbt.tag.StringTag;
/**
* A converter that converts between StringTag and String.

View File

@ -1,8 +1,7 @@
package com.github.steveice10.opennbt.tag.io;
package com.viaversion.nbt.io;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.tag.io;
package com.viaversion.nbt.io;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.nbt.limiter.TagLimiter;
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
import java.io.DataInput;
import java.io.DataInputStream;

View File

@ -1,19 +1,19 @@
package com.github.steveice10.opennbt.tag;
package com.viaversion.nbt.io;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.nbt.tag.ByteArrayTag;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.DoubleTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.ShortTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.io.DataInput;

View File

@ -1,6 +1,6 @@
package com.github.steveice10.opennbt.tag.io;
package com.viaversion.nbt.io;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.tag.Tag;
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;

View File

@ -1,9 +1,12 @@
package com.github.steveice10.opennbt.tag.limiter;
package com.viaversion.nbt.limiter;
final class NoopTagLimiter implements TagLimiter {
static final TagLimiter INSTANCE = new NoopTagLimiter();
private NoopTagLimiter() {
}
@Override
public void countBytes(int bytes) {
}

View File

@ -1,4 +1,4 @@
package com.github.steveice10.opennbt.tag.limiter;
package com.viaversion.nbt.limiter;
public interface TagLimiter {

View File

@ -1,4 +1,4 @@
package com.github.steveice10.opennbt.tag.limiter;
package com.viaversion.nbt.limiter;
final class TagLimiterImpl implements TagLimiter {

View File

@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
/**
* A character buffer designed to be inspected by a parser.

View File

@ -1,7 +1,7 @@
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.Tag;
/**
* Serialization of stringifies tags.

View File

@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
// Specific Via changes:
// - Remove buffer field

View File

@ -21,22 +21,22 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.tag.ByteArrayTag;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.DoubleTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.nbt.tag.ShortTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import java.util.stream.IntStream;

View File

@ -21,22 +21,22 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.nbt.tag.ByteArrayTag;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.DoubleTag;
import com.viaversion.nbt.tag.FloatTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.LongArrayTag;
import com.viaversion.nbt.tag.LongTag;
import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.nbt.tag.ShortTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
import java.util.Map;
// Specific Via changes:

View File

@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.steveice10.opennbt.stringified;
package com.viaversion.nbt.stringified;
final class Tokens {
// Compounds

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -9,7 +10,7 @@ import java.util.Arrays;
/**
* A tag containing a byte array.
*/
public final class ByteArrayTag extends NumberArrayTag {
public final class ByteArrayTag implements NumberArrayTag {
public static final int ID = 7;
private static final byte[] EMPTY_ARRAY = new byte[0];
private byte[] value;
@ -70,7 +71,7 @@ public final class ByteArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @return The value at the given index.
*/
public byte getValue(int index) {
public byte get(int index) {
return this.value[index];
}
@ -80,7 +81,7 @@ public final class ByteArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @param value Value to set.
*/
public void setValue(int index, byte value) {
public void set(int index, byte value) {
this.value[index] = value;
}
@ -126,4 +127,9 @@ public final class ByteArrayTag extends NumberArrayTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,16 +9,10 @@ import java.io.IOException;
/**
* A tag containing a byte.
*/
public final class ByteTag extends NumberTag {
public final class ByteTag implements NumberTag {
public static final int ID = 1;
private byte value;
/**
* Creates a tag.
*/
public ByteTag() {
this((byte) 0);
}
public static final ByteTag ZERO = new ByteTag((byte) 0);
private final byte value;
/**
* Creates a tag.
@ -56,17 +51,6 @@ public final class ByteTag extends NumberTag {
return Byte.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(byte value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeByte(this.value);
@ -85,11 +69,6 @@ public final class ByteTag extends NumberTag {
return value;
}
@Override
public ByteTag copy() {
return new ByteTag(this.value);
}
@Override
public byte asByte() {
return this.value;
@ -124,4 +103,9 @@ public final class ByteTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,7 +1,8 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.io.TagRegistry;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -16,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
/**
* A compound tag containing other tags.
*/
public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
public final class CompoundTag implements Tag, Iterable<Entry<String, Tag>> {
public static final int ID = 10;
private Map<String, Tag> value;
@ -133,14 +134,13 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
* <p>
* <b>This will have its generic removed and instead return a raw tag in the future.</b>
*
* @param <T> type of the tag
* @param tagName key of the tag
* @return tag if present, else null
* @see #getUnchecked(String)
*/
@Nullable
public <T extends Tag> T get(String tagName) {
return (T) this.value.get(tagName);
public Tag get(String tagName) {
return this.value.get(tagName);
}
/**
@ -323,17 +323,16 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
* <p>
* <b>This will have its generic removed and instead return a raw tag in the future.</b>
*
* @param <T> Type of tag to put.
* @param tagName Name of the tag.
* @param tag Tag to put into this compound tag.
* @return The previous tag associated with its name, or null if there wasn't one.
*/
@Nullable
public <T extends Tag> T put(String tagName, T tag) {
public Tag put(String tagName, Tag tag) {
if (tag == this) {
throw new IllegalArgumentException("Cannot add a tag to itself");
}
return (T) this.value.put(tagName, tag);
return this.value.put(tagName, tag);
}
public void putString(String tagName, String value) {
@ -377,14 +376,13 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
* <p>
* <b>This will have its generic removed and instead return a raw tag in the future.</b>
*
* @param <T> Type of tag to remove.
* @param tagName Name of the tag to remove.
* @return The removed tag.
* @see #removeUnchecked(String)
*/
@Nullable
public <T extends Tag> T remove(String tagName) {
return (T) this.value.remove(tagName);
public Tag remove(String tagName) {
return this.value.remove(tagName);
}
/**
@ -487,4 +485,9 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,16 +9,10 @@ import java.io.IOException;
/**
* A tag containing a double.
*/
public final class DoubleTag extends NumberTag {
public final class DoubleTag implements NumberTag {
public static final int ID = 6;
private double value;
/**
* Creates a tag.
*/
public DoubleTag() {
this(0);
}
public static final DoubleTag ZERO = new DoubleTag(0);
private final double value;
/**
* Creates a tag.
@ -47,17 +42,6 @@ public final class DoubleTag extends NumberTag {
return Double.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(double value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeDouble(this.value);
@ -76,11 +60,6 @@ public final class DoubleTag extends NumberTag {
return Double.hashCode(this.value);
}
@Override
public DoubleTag copy() {
return new DoubleTag(this.value);
}
@Override
public byte asByte() {
return (byte) this.value;
@ -115,4 +94,9 @@ public final class DoubleTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,16 +9,10 @@ import java.io.IOException;
/**
* A tag containing a float.
*/
public final class FloatTag extends NumberTag {
public final class FloatTag implements NumberTag {
public static final int ID = 5;
private float value;
/**
* Creates a tag.
*/
public FloatTag() {
this(0);
}
public static final FloatTag ZERO = new FloatTag(0);
private final float value;
/**
* Creates a tag.
@ -47,17 +42,6 @@ public final class FloatTag extends NumberTag {
return Float.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(float value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeFloat(this.value);
@ -76,11 +60,6 @@ public final class FloatTag extends NumberTag {
return Float.hashCode(this.value);
}
@Override
public FloatTag copy() {
return new FloatTag(this.value);
}
@Override
public byte asByte() {
return (byte) this.value;
@ -115,4 +94,9 @@ public final class FloatTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -9,7 +10,7 @@ import java.util.Arrays;
/**
* A tag containing an integer array.
*/
public final class IntArrayTag extends NumberArrayTag {
public final class IntArrayTag implements NumberArrayTag {
public static final int ID = 11;
private static final int[] EMPTY_ARRAY = new int[0];
private int[] value;
@ -35,7 +36,7 @@ public final class IntArrayTag extends NumberArrayTag {
public static IntArrayTag read(final DataInput in, final TagLimiter tagLimiter) throws IOException {
tagLimiter.countInt();
int[] value = new int[in.readInt()];
final int[] value = new int[in.readInt()];
tagLimiter.countBytes(Integer.BYTES * value.length);
for (int index = 0; index < value.length; index++) {
value[index] = in.readInt();
@ -71,7 +72,7 @@ public final class IntArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @return The value at the given index.
*/
public int getValue(final int index) {
public int get(final int index) {
return this.value[index];
}
@ -81,7 +82,7 @@ public final class IntArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @param value Value to set.
*/
public void setValue(final int index, final int value) {
public void set(final int index, final int value) {
this.value[index] = value;
}
@ -129,4 +130,9 @@ public final class IntArrayTag extends NumberArrayTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,9 +9,9 @@ import java.io.IOException;
/**
* A tag containing an integer.
*/
public final class IntTag extends NumberTag {
public final class IntTag implements NumberTag {
public static final int ID = 3;
private int value;
private final int value;
/**
* Creates a tag.
@ -47,17 +48,6 @@ public final class IntTag extends NumberTag {
return Integer.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(int value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeInt(this.value);
@ -76,11 +66,6 @@ public final class IntTag extends NumberTag {
return this.value;
}
@Override
public IntTag copy() {
return new IntTag(this.value);
}
@Override
public byte asByte() {
return (byte) this.value;
@ -115,4 +100,9 @@ public final class IntTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,7 +1,8 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.TagRegistry;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.io.TagRegistry;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -15,7 +16,7 @@ import org.jetbrains.annotations.Nullable;
/**
* A tag containing a list of tags.
*/
public final class ListTag<T extends Tag> extends Tag implements Iterable<T> {
public final class ListTag<T extends Tag> implements Tag, Iterable<T> {
public static final int ID = 9;
private Class<T> type;
private List<T> value;
@ -259,4 +260,9 @@ public final class ListTag<T extends Tag> extends Tag implements Iterable<T> {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -9,7 +10,7 @@ import java.util.Arrays;
/**
* A tag containing a long array.
*/
public final class LongArrayTag extends NumberArrayTag {
public final class LongArrayTag implements NumberArrayTag {
public static final int ID = 12;
private static final long[] EMPTY_ARRAY = new long[0];
private long[] value;
@ -71,7 +72,7 @@ public final class LongArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @return The value at the given index.
*/
public long getValue(int index) {
public long get(int index) {
return this.value[index];
}
@ -81,7 +82,7 @@ public final class LongArrayTag extends NumberArrayTag {
* @param index Index of the value.
* @param value Value to set.
*/
public void setValue(int index, long value) {
public void set(int index, long value) {
this.value[index] = value;
}
@ -129,4 +130,9 @@ public final class LongArrayTag extends NumberArrayTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,16 +9,10 @@ import java.io.IOException;
/**
* A tag containing a long.
*/
public final class LongTag extends NumberTag {
public final class LongTag implements NumberTag {
public static final int ID = 4;
private long value;
/**
* Creates a tag.
*/
public LongTag() {
this(0);
}
public static final LongTag ZERO = new LongTag(0);
private final long value;
/**
* Creates a tag.
@ -47,17 +42,6 @@ public final class LongTag extends NumberTag {
return Long.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(long value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeLong(this.value);
@ -76,11 +60,6 @@ public final class LongTag extends NumberTag {
return Long.hashCode(this.value);
}
@Override
public LongTag copy() {
return new LongTag(this.value);
}
@Override
public byte asByte() {
return (byte) this.value;
@ -115,4 +94,9 @@ public final class LongTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,18 +1,21 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
public abstract class NumberArrayTag extends Tag {
public interface NumberArrayTag extends Tag {
/**
* Gets the length of this tag's array.
*
* @return array length
*/
public abstract int length();
int length();
/**
* Creates a new list tag from this tag.
*
* @return a new list tag
*/
public abstract ListTag<? extends NumberTag> toListTag();
ListTag<? extends NumberTag> toListTag();
@Override
NumberArrayTag copy();
}

View File

@ -1,9 +1,9 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
/**
* Abstract class representing a number tag, containing methods to return primitive number types.
*/
public abstract class NumberTag extends Tag {
public interface NumberTag extends Tag {
/**
* Gets the number value of this tag.
@ -11,49 +11,49 @@ public abstract class NumberTag extends Tag {
* @return Number value of this tag.
*/
@Override
public abstract Number getValue();
Number getValue();
/**
* Gets the byte value of this tag.
*
* @return Byte value of this tag.
*/
public abstract byte asByte();
byte asByte();
/**
* Gets the short value of this tag.
*
* @return Short value of this tag.
*/
public abstract short asShort();
short asShort();
/**
* Gets the int value of this tag.
*
* @return Int value of this tag.
*/
public abstract int asInt();
int asInt();
/**
* Gets the long value of this tag.
*
* @return Long value of this tag.
*/
public abstract long asLong();
long asLong();
/**
* Gets the float value of this tag.
*
* @return Float value of this tag.
*/
public abstract float asFloat();
float asFloat();
/**
* Gets the double value of this tag.
*
* @return Double value of this tag.
*/
public abstract double asDouble();
double asDouble();
/**
* Gets the boolean value of this tag.
@ -63,7 +63,13 @@ public abstract class NumberTag extends Tag {
*
* @return Boolean value of this tag.
*/
public boolean asBoolean() {
default boolean asBoolean() {
return this.asByte() != 0;
}
@Override
default NumberTag copy() {
// Immutable, so return this
return this;
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,16 +9,10 @@ import java.io.IOException;
/**
* A tag containing a short.
*/
public final class ShortTag extends NumberTag {
public final class ShortTag implements NumberTag {
public static final int ID = 2;
private short value;
/**
* Creates a tag.
*/
public ShortTag() {
this((short) 0);
}
public static final ShortTag ZERO = new ShortTag((short) 0);
private final short value;
/**
* Creates a tag.
@ -47,17 +42,6 @@ public final class ShortTag extends NumberTag {
return Short.toString(this.value);
}
/**
* Sets the value of this tag.
*
* @param value New value of this tag.
* @deprecated number tags will be immutable in the future
*/
@Deprecated
public void setValue(short value) {
this.value = value;
}
@Override
public void write(DataOutput out) throws IOException {
out.writeShort(this.value);
@ -76,11 +60,6 @@ public final class ShortTag extends NumberTag {
return this.value;
}
@Override
public ShortTag copy() {
return new ShortTag(this.value);
}
@Override
public byte asByte() {
return (byte) this.value;
@ -115,4 +94,9 @@ public final class ShortTag extends NumberTag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -1,6 +1,7 @@
package com.github.steveice10.opennbt.tag.builtin;
package com.viaversion.nbt.tag;
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
import com.viaversion.nbt.stringified.SNBT;
import com.viaversion.nbt.limiter.TagLimiter;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@ -8,7 +9,7 @@ import java.io.IOException;
/**
* A tag containing a string.
*/
public final class StringTag extends Tag {
public final class StringTag implements Tag {
public static final int ID = 8;
private String value;
@ -86,4 +87,9 @@ public final class StringTag extends Tag {
public int getTagId() {
return ID;
}
@Override
public String toString() {
return SNBT.serialize(this);
}
}

View File

@ -0,0 +1,45 @@
package com.viaversion.nbt.tag;
import com.viaversion.nbt.stringified.SNBT;
import java.io.DataOutput;
import java.io.IOException;
public interface Tag {
/**
* Returns the value of this tag.
*
* @return value of this tag
*/
Object getValue();
/**
* Returns the raw string representation of the value of this tag.
* For SNBT, use {@link SNBT#serialize(Tag)}.
*
* @return raw string representation of the value of this tag
*/
String asRawString();
/**
* Writes this tag to an output stream.
*
* @param out data output to write to
* @throws IOException if an I/O error occurs
*/
void write(DataOutput out) throws IOException;
/**
* Returns the NBT tag id of this tag type, used in I/O.
*
* @return ID of the tag this class represents
*/
int getTagId();
/**
* Returns a copy of this tag.
*
* @return a copy of this tag
*/
Tag copy();
}