From bf443be0d33206d92b7624699c7d1201e6dc27c5 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Mon, 18 Feb 2013 15:49:30 +0100 Subject: [PATCH] Add the ability to read arbitrary objects. Perhaps NbtBase shouldn't have implemented getValue() after all - it would have been better to have a shared base interface with getName() and getType(), and only let the primitive elements implement getValue(). Too late to change it now though. --- .../comphenix/protocol/wrappers/nbt/NbtCompound.java | 10 +++++++++- .../protocol/wrappers/nbt/WrappedCompound.java | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 245a1c42..226d7b61 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 @@ -262,7 +262,8 @@ public interface NbtCompound extends NbtBase>>, Iterable< /** * Associates a given Java primitive value, list, map or NbtBase with a certain key. *

- * If the value is NULL, the corresponding key is removed. + * If the value is NULL, the corresponding key is removed. Any Map or List will be converted + * to a corresponding NbtCompound or NbtList. * * @param key - the name of the new entry, * @param value - the value of the new entry, or NULL to remove the current value. @@ -270,6 +271,13 @@ public interface NbtCompound extends NbtBase>>, Iterable< */ public abstract NbtCompound putObject(String key, Object value); + /** + * Retrieve the primitive object, NbtList or NbtCompound associated with the given key. + * @param key - the key of the object to find. + * @return The object with this key, or NULL if we couldn't find anything. + */ + public abstract Object getObject(String key); + /** * Retrieve the compound (map) value of an entry identified by a given key. * @param key - the key of the entry. 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 222d8340..ae277973 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 @@ -274,6 +274,16 @@ class WrappedCompound implements NbtWrapper>>, Iterable base = getValue(key); + + if (base != null && base.getType() != NbtType.TAG_LIST && base.getType() != NbtType.TAG_COMPOUND) + return base.getValue(); + else + return base; + } + /** * Retrieve the byte value of an entry identified by a given key. * @param key - the key of the entry.