Skip to content

feature(nbt): CompoundBinaryTag contains methods #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main/4
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions nbt/src/main/java/net/kyori/adventure/nbt/CompoundBinaryTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ public interface CompoundBinaryTag extends BinaryTag, CompoundTagSetter<Compound
return BinaryTagTypes.COMPOUND;
}

/**
* Returns whether the compound contains a specific key.
*
* @param key the key to check for
* @return whether the compound contains the key
* @since 4.24.0
*/
boolean containsKey(final @NotNull String key);

/**
* Returns whether the compound contains a tag of a specific type under a key.
*
* @param key the key to check for
* @param type the type to check for
* @return whether there is a tag of <code>type</code> under <code>key</code>
* @since 4.24.0
*/
boolean contains(final @NotNull String key, final @NotNull BinaryTagType<?> type);

/**
* Gets a set of all keys.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ final class CompoundBinaryTagImpl extends AbstractBinaryTag implements CompoundB
this.hashCode = tags.hashCode();
}

@Override
public boolean containsKey(final @NotNull String key) {
return this.tags.containsKey(key);
}

@Override
public boolean contains(final @NotNull String key, final @NotNull BinaryTagType<?> type) {
final @Nullable BinaryTag tag = this.tags.get(key);
return tag != null && type.test(tag.type());
Expand Down