diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java index 4fda61b8..87f9ffe4 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtBase.java @@ -64,6 +64,9 @@ public interface NbtBase { * Is either a primitive {@link java.lang.Number wrapper}, {@link java.lang.String String}, * {@link java.util.List List} or a {@link java.util.Map Map}. *

+ * Users are encouraged to cast an NBT compound to {@link NbtCompound} and use its put and get-methods + * instead of accessing its content from getValue(). + *

* All operations that modify collections directly, such as {@link java.util.List#add(Object) List.add(Object)} or * {@link java.util.Map#clear() Map.clear()}, are considered optional. This also include members in {@link java.util.Iterator Iterator} and * {@link java.util.ListIterator ListIterator}. Operations that are not implemented throw a diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtCompound.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtCompound.java index 5465ae29..cc4deeb3 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtCompound.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/NbtCompound.java @@ -16,6 +16,10 @@ import java.util.Set; * @author Kristian */ public interface NbtCompound extends NbtBase>>, Iterable> { + @Override + @Deprecated() + public Map> getValue(); + /** * Determine if an entry with the given key exists or not. * @param key - the key to lookup. @@ -304,6 +308,13 @@ public interface NbtCompound extends NbtBase>>, Iterable< */ public abstract NbtCompound put(String key, Collection> list); + /** + * Remove the NBT element that is associated with the given key. + * @param key - the key of the element to remove. + * @return The removed element, or NULL if no such element was found. + */ + public abstract NbtBase remove(String key); + /** * Retrieve an iterator view of the NBT tags stored in this compound. * @return The tags stored in this compound. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/WrappedCompound.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/WrappedCompound.java index 8d3f6fa8..217c555d 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/WrappedCompound.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/nbt/WrappedCompound.java @@ -215,6 +215,9 @@ class WrappedCompound implements NbtWrapper>>, Iterable NbtCompound put(NbtBase entry) { + if (entry == null) + throw new IllegalArgumentException("Entry cannot be NULL."); + getValue().put(entry.getName(), entry); return this; } @@ -565,6 +568,9 @@ class WrappedCompound implements NbtWrapper>>, Iterable entry) { + if (entry == null) + throw new IllegalArgumentException("Entry cannot be NULL."); + // Don't modify the original NBT NbtBase clone = entry.deepClone(); @@ -583,6 +589,11 @@ class WrappedCompound implements NbtWrapper>>, Iterable NbtBase remove(String key) { + return getValue().remove(key); + } + @Override public void write(DataOutput destination) { NbtBinarySerializer.DEFAULT.serialize(container, destination);