4.2.0: More helpers, deprecate primitive setValue methods

In anticipation of value classes existing before I die of age, the primitive wrappers (and only those) will become immutable in the future.
This commit is contained in:
Nassim Jahnke 2024-02-10 20:43:36 +01:00
parent ea616b1e44
commit eec9aca691
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
9 changed files with 36 additions and 1 deletions

View File

@ -5,7 +5,7 @@
<groupId>com.viaversion</groupId>
<artifactId>nbt</artifactId>
<version>4.1.0</version>
<version>4.2.0</version>
<packaging>jar</packaging>
<name>ViaNBT</name>

View File

@ -51,7 +51,9 @@ public class ByteTag extends NumberTag {
* 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;
}

View File

@ -130,6 +130,8 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
/**
* Gets the 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 get.
* @param tagName Name of the tag.
@ -160,8 +162,25 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
return tag instanceof NumberTag ? (NumberTag) tag : null;
}
public @Nullable ByteArrayTag getByteArrayTag(String tagName) {
final Tag tag = this.value.get(tagName);
return tag instanceof ByteArrayTag ? (ByteArrayTag) tag : null;
}
public @Nullable IntArrayTag getIntArrayTag(String tagName) {
final Tag tag = this.value.get(tagName);
return tag instanceof IntArrayTag ? (IntArrayTag) tag : null;
}
public @Nullable LongArrayTag getLongArrayTag(String tagName) {
final Tag tag = this.value.get(tagName);
return tag instanceof LongArrayTag ? (LongArrayTag) tag : null;
}
/**
* Puts the tag into this compound 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.
@ -211,6 +230,8 @@ public class CompoundTag extends Tag implements Iterable<Entry<String, Tag>> {
/**
* Removes a tag from this compound 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.

View File

@ -51,7 +51,9 @@ public class DoubleTag extends NumberTag {
* 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;
}

View File

@ -51,7 +51,9 @@ public class FloatTag extends NumberTag {
* 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;
}

View File

@ -51,7 +51,9 @@ public class IntTag extends NumberTag {
* 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;
}

View File

@ -51,7 +51,9 @@ public class LongTag extends NumberTag {
* 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;
}

View File

@ -51,7 +51,9 @@ public class ShortTag extends NumberTag {
* 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;
}

View File

@ -28,6 +28,8 @@ public abstract class Tag {
/**
* 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