Add getUnchecked method to CompoundTag

This commit is contained in:
Nassim Jahnke 2024-03-09 12:47:22 +01:00
parent 9be057263f
commit 921fa31b29
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 33 additions and 5 deletions

View File

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

View File

@ -129,19 +129,33 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
}
/**
* Gets the tag.
* Returns a tag by name if present.
* <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.
* @return The tag.
* @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);
}
/**
* Returns a tag by name if present.
*
* @param <T> type of the tag
* @param tagName key of the tag
* @return tag if present, else null
*/
@Nullable
public <T extends Tag> T getUnchecked(String tagName) {
//noinspection unchecked
return (T) this.value.get(tagName);
}
public @Nullable StringTag getStringTag(String tagName) {
final Tag tag = this.value.get(tagName);
return tag instanceof StringTag ? (StringTag) tag : null;
@ -258,12 +272,26 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
* @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);
}
/**
* Removes a tag from this compound tag.
*
* @param <T> Type of tag to remove.
* @param tagName Name of the tag to remove.
* @return The removed tag.
*/
@Nullable
public <T extends Tag> T removeUnchecked(String tagName) {
//noinspection unchecked
return (T) this.value.remove(tagName);
}
/**
* Gets a set of keys in this compound tag.
*