Archiviert
13
0

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.
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-02-18 15:49:30 +01:00
Ursprung 61ae40b936
Commit bf443be0d3
2 geänderte Dateien mit 19 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -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.

Datei anzeigen

@ -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.