mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-30 22:53:26 +01:00
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.
This commit is contained in:
parent
61ae40b936
commit
bf443be0d3
@ -262,7 +262,8 @@ public interface NbtCompound extends NbtBase<Map<String, NbtBase<?>>>, Iterable<
|
||||
/**
|
||||
* Associates a given Java primitive value, list, map or NbtBase<?> with a certain key.
|
||||
* <p>
|
||||
* 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<Map<String, 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.
|
||||
|
@ -274,6 +274,16 @@ class WrappedCompound implements NbtWrapper<Map<String, NbtBase<?>>>, Iterable<N
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObject(String key) {
|
||||
NbtBase<?> 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.
|
||||
|
Loading…
Reference in New Issue
Block a user