From 921fa31b29096ad9c8dcdcd71778509b3cb3c9b7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 9 Mar 2024 12:47:22 +0100 Subject: [PATCH] Add getUnchecked method to CompoundTag --- pom.xml | 2 +- .../opennbt/tag/builtin/CompoundTag.java | 36 ++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 1ed68cc..71f7d05 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.viaversion nbt - 4.4.1 + 4.4.2 jar ViaNBT diff --git a/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java b/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java index fceaaf8..35f441f 100644 --- a/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java +++ b/src/main/java/com/github/steveice10/opennbt/tag/builtin/CompoundTag.java @@ -129,19 +129,33 @@ public final class CompoundTag extends Tag implements Iterable * This will have its generic removed and instead return a raw tag in the future. * - * @param Type of tag to get. - * @param tagName Name of the tag. - * @return The tag. + * @param type of the tag + * @param tagName key of the tag + * @return tag if present, else null + * @see #getUnchecked(String) */ @Nullable public T get(String tagName) { return (T) this.value.get(tagName); } + /** + * Returns a tag by name if present. + * + * @param type of the tag + * @param tagName key of the tag + * @return tag if present, else null + */ + @Nullable + public 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 Type of tag to remove. * @param tagName Name of the tag to remove. * @return The removed tag. + * @see #removeUnchecked(String) */ @Nullable public T remove(String tagName) { return (T) this.value.remove(tagName); } + /** + * Removes a tag from this compound tag. + * + * @param Type of tag to remove. + * @param tagName Name of the tag to remove. + * @return The removed tag. + */ + @Nullable + public T removeUnchecked(String tagName) { + //noinspection unchecked + return (T) this.value.remove(tagName); + } + /** * Gets a set of keys in this compound tag. *