-
- All Implemented Interfaces:
-
kotlin.collections.Map
,kotlin.collections.MutableMap
public final class NbtCompound extends NbtTag implements Map<String, NbtTag>
A tag which contains a MutableMap structure associating Strings to NbtTags.
It's the main heart of NBT files and usually contains complex structures.
The returned tags by this class will be linked, so modifications to it will also affect the compound value.
All get functions which are not prefixed with
Nullable
andget
will throw a ClassCastException if the tag is mapped to a different class then the method used. For example if a given compound have an example=NbtInt(2) and you try to read it using NbtCompound.getShort, an exception will be thrown.All get functions which are not prefixed with
Nullable
andget
will throw NoSuchElementException if no value is mapped to the given name. This will change in the future.All get list functions which returns lists of specific types will throw IllegalStateException if the list content does not match the requested type.
-
-
Constructor Summary
Constructors Constructor Description NbtCompound(Map<String, NbtTag> value)
Creates a new compound containing the same mappings as the given Map. NbtCompound()
Creates an empty compound. NbtCompound(Pair<String, NbtTag> tags)
Creates a compound which maps the Pair.first value to the Pair.second tag initially. NbtCompound(Iterable<Pair<String, NbtTag>> tags)
Creates a compound which maps the Pair.first value to the Pair.second tag initially. NbtCompound(String value)
-
Method Summary
Modifier and Type Method Description String
getStringValue()
Returns a string representation of the tag's value. Set<Entry.Map<String, NbtTag>>
getEntries()
Set<String>
getKeys()
Integer
getSize()
Collection<NbtTag>
getValues()
final Unit
set(String key, NbtTag value)
Directly maps a NbtTag to a key. final Unit
set(String key, Boolean value)
Maps a NbtByte 1
if the value istrue
and0
otherwise.final Unit
set(String key, Byte value)
Maps a NbtByte with the given value. final Unit
set(String key, Short value)
Maps a NbtShort with the given value. final Unit
set(String key, Integer value)
Maps a NbtInt with the given value. final Unit
set(String key, Long value)
Maps a NbtLong with the given value. final Unit
set(String key, Float value)
Maps a NbtFloat with the given value. final Unit
set(String key, Double value)
Maps a NbtDouble with the given value. final Unit
set(String key, ByteArray value)
Maps a NbtByteArray with the given value. final Unit
set(String key, String value)
Maps a NbtDouble with the given value. final Unit
set(String key, IntArray value)
Maps a NbtByteArray with the given value. final Unit
set(String key, LongArray value)
Maps a NbtByteArray with the given value. final Boolean
getNullableBooleanByte(String key)
Returns true
if getByte returns1
,false
otherwise.final Boolean
getBooleanByte(String key)
Returns true
if getByte returns1
,false
otherwise.final NbtTag
require(String key)
Returns the value corresponding to the given key, or throw an exception if such a key is not present in the compound. final Byte
getByte(String key)
Returns the unwrapped byte value. final Short
getShort(String key)
Returns the unwrapped short value. final Integer
getInt(String key)
Returns the unwrapped int value. final Long
getLong(String key)
Returns the unwrapped long value. final Float
getFloat(String key)
Returns the unwrapped float value. final Double
getDouble(String key)
Returns the unwrapped double value. final ByteArray
getByteArray(String key)
Returns the unwrapped byte array value. final String
getString(String key)
Returns the unwrapped string value. final IntArray
getIntArray(String key)
Returns the unwrapped int array value. final LongArray
getLongArray(String key)
Returns the unwrapped long array value. final NbtCompound
getCompound(String key)
Returns the NbtCompound mapped to that key. final NbtList<?>
getList(String key)
Returns the NbtList mapped to that key. final NbtList<NbtByte>
getByteList(String key)
Returns the NbtList of bytes mapped to that key. final NbtList<NbtShort>
getShortList(String key)
Returns the NbtList of shorts mapped to that key. final NbtList<NbtInt>
getIntList(String key)
Returns the NbtList of integers mapped to that key. final NbtList<NbtLong>
getLongList(String key)
Returns the NbtList of longs mapped to that key. final NbtList<NbtFloat>
getFloatList(String key)
Returns the NbtList of floats mapped to that key. final NbtList<NbtDouble>
getDoubleList(String key)
Returns the NbtList of doubles mapped to that key. final NbtList<NbtByteArray>
getByteArrayList(String key)
Returns the NbtList of byte arrays mapped to that key. final NbtList<NbtString>
getStringList(String key)
Returns the NbtList of strings mapped to that key. final NbtList<NbtIntArray>
getIntArrayList(String key)
Returns the NbtList of int arrays mapped to that key. final NbtList<NbtLongArray>
getLongArrayList(String key)
Returns the NbtList of long arrays mapped to that key. final NbtList<NbtCompound>
getCompoundList(String key)
Returns the NbtList of compounds mapped to that key. final NbtList<NbtList<?>>
getListOfList(String key)
Returns the NbtList of lists mapped to that key. final Byte
getNullableByte(String key)
Returns the unwrapped byte value or null if no value is mapped, or it is mapped to another type tag. final Short
getNullableShort(String key)
Returns the unwrapped short value or null if no value is mapped, or it is mapped to another type tag. final Integer
getNullableInt(String key)
Returns the unwrapped int value or null if no value is mapped, or it is mapped to another type tag. final Long
getNullableLong(String key)
Returns the unwrapped long value or null if no value is mapped, or it is mapped to another type tag. final Float
getNullableFloat(String key)
Returns the unwrapped float value or null if no value is mapped, or it is mapped to another type tag. final Double
getNullableDouble(String key)
Returns the unwrapped double value or null if no value is mapped, or it is mapped to another type tag. final ByteArray
getNullableByteArray(String key)
Returns the unwrapped byte array value. final String
getNullableString(String key)
Returns the unwrapped string value or null if no value is mapped, or it is mapped to another type tag. final IntArray
getNullableIntArray(String key)
Returns the unwrapped int array value. final LongArray
getNullableLongArray(String key)
Returns the unwrapped long array value. final NbtCompound
getNullableCompound(String key)
Returns the NbtCompound mapped to that key. final NbtList<?>
getNullableList(String key)
Returns the NbtList mapped to that key. final NbtList<NbtByte>
getNullableByteList(String key)
Returns the NbtList of bytes mapped to that key. final NbtList<NbtShort>
getNullableShortList(String key)
Returns the NbtList of shorts mapped to that key. final NbtList<NbtInt>
getNullableIntList(String key)
Returns the NbtList of integers mapped to that key. final NbtList<NbtLong>
getNullableLongList(String key)
Returns the NbtList of longs mapped to that key. final NbtList<NbtFloat>
getNullableFloatList(String key)
Returns the NbtList of floats mapped to that key. final NbtList<NbtDouble>
getNullableDoubleList(String key)
Returns the NbtList of doubles mapped to that key. final NbtList<NbtByteArray>
getNullableByteArrayList(String key)
Returns the NbtList of byte arrays mapped to that key. final NbtList<NbtString>
getNullableStringList(String key)
Returns the NbtList of strings mapped to that key. final NbtList<NbtIntArray>
getNullableIntArrayList(String key)
Returns the NbtList of int arrays mapped to that key. final NbtList<NbtLongArray>
getNullableLongArrayList(String key)
Returns the NbtList of long arrays mapped to that key. final NbtList<NbtCompound>
getNullableCompoundList(String key)
Returns the NbtList of compounds mapped to that key. final NbtList<NbtList<?>>
getNullableListOfList(String key)
Returns the NbtList of lists mapped to that key. final Unit
copyFrom(NbtCompound other, String tagKey, NbtTag default)
Checks if the other compound have a given tag, if it has been placed it in this compound. final Unit
copyTo(NbtCompound other, String tagKey, NbtTag default)
Checks if the compound have a given tag, if it has been placed it in the other compound. NbtCompound
deepCopy()
Returns a new NbtCompound with all nested values copied deeply. Boolean
equals(Object other)
Integer
hashCode()
-
Methods inherited from class br.com.gamemods.nbtmanipulator.NbtCompound
clear, compute, computeIfAbsent, computeIfPresent, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, toString
-
Methods inherited from class kotlin.collections.MutableMap
containsKey, containsValue, forEach, get, getOrDefault, isEmpty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
NbtCompound
NbtCompound(Map<String, NbtTag> value)
Creates a new compound containing the same mappings as the given Map.
-
NbtCompound
NbtCompound()
Creates an empty compound.
-
NbtCompound
NbtCompound(Pair<String, NbtTag> tags)
Creates a compound which maps the Pair.first value to the Pair.second tag initially.
-
NbtCompound
NbtCompound(Iterable<Pair<String, NbtTag>> tags)
Creates a compound which maps the Pair.first value to the Pair.second tag initially.
-
NbtCompound
NbtCompound(String value)
-
-
Method Detail
-
getStringValue
String getStringValue()
Returns a string representation of the tag's value.
The NbtList and the array types will have an output similar to a normal List and NbtCompound to a normal Map.
The class names of the NbtList's and NbtCompound's children will expose.
The returned string is compatible with string constructors of the same type.
Be aware that this may be a slow operation on big lists, arrays or compounds.
-
getEntries
Set<Entry.Map<String, NbtTag>> getEntries()
-
getValues
Collection<NbtTag> getValues()
-
set
final Unit set(String key, ByteArray value)
Maps a NbtByteArray with the given value. The array instance will be linked so any modification will also change the tag value.
-
set
final Unit set(String key, IntArray value)
Maps a NbtByteArray with the given value. The array instance will be linked so any modification will also change the tag value.
-
set
final Unit set(String key, LongArray value)
Maps a NbtByteArray with the given value. The array instance will be linked so any modification will also change the tag value.
-
getNullableBooleanByte
final Boolean getNullableBooleanByte(String key)
Returns
true
if getByte returns1
,false
otherwise. Will also returnfalse
if the value is not mapped.
-
getBooleanByte
final Boolean getBooleanByte(String key)
Returns
true
if getByte returns1
,false
otherwise.
-
require
final NbtTag require(String key)
Returns the value corresponding to the given key, or throw an exception if such a key is not present in the compound.
-
getByteArray
final ByteArray getByteArray(String key)
Returns the unwrapped byte array value. The array will be linked and any modification will also change wrapper and the mapped value.
-
getIntArray
final IntArray getIntArray(String key)
Returns the unwrapped int array value. The array will be linked and any modification will also change wrapper and the mapped value.
-
getLongArray
final LongArray getLongArray(String key)
Returns the unwrapped long array value. The array will be linked and any modification will also change wrapper and the mapped value.
-
getCompound
final NbtCompound getCompound(String key)
Returns the NbtCompound mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getList
final NbtList<?> getList(String key)
Returns the NbtList mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getByteList
final NbtList<NbtByte> getByteList(String key)
Returns the NbtList of bytes mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getShortList
final NbtList<NbtShort> getShortList(String key)
Returns the NbtList of shorts mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getIntList
final NbtList<NbtInt> getIntList(String key)
Returns the NbtList of integers mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getLongList
final NbtList<NbtLong> getLongList(String key)
Returns the NbtList of longs mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getFloatList
final NbtList<NbtFloat> getFloatList(String key)
Returns the NbtList of floats mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getDoubleList
final NbtList<NbtDouble> getDoubleList(String key)
Returns the NbtList of doubles mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getByteArrayList
final NbtList<NbtByteArray> getByteArrayList(String key)
Returns the NbtList of byte arrays mapped to that key. The tag and it's value will be linked and any modification will also change the mapped value.
-
getStringList
final NbtList<NbtString> getStringList(String key)
Returns the NbtList of strings mapped to that key. The tag will be linked and any modification will also change the mapped value.
-
getIntArrayList
final NbtList<NbtIntArray> getIntArrayList(String key)
Returns the NbtList of int arrays mapped to that key. The tag and it's value will be linked and any modification will also change the mapped value.
-
getLongArrayList
final NbtList<NbtLongArray> getLongArrayList(String key)
Returns the NbtList of long arrays mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
-
getCompoundList
final NbtList<NbtCompound> getCompoundList(String key)
Returns the NbtList of compounds mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
-
getListOfList
final NbtList<NbtList<?>> getListOfList(String key)
Returns the NbtList of lists mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
-
getNullableByte
final Byte getNullableByte(String key)
Returns the unwrapped byte value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableShort
final Short getNullableShort(String key)
Returns the unwrapped short value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableInt
final Integer getNullableInt(String key)
Returns the unwrapped int value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableLong
final Long getNullableLong(String key)
Returns the unwrapped long value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableFloat
final Float getNullableFloat(String key)
Returns the unwrapped float value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableDouble
final Double getNullableDouble(String key)
Returns the unwrapped double value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableByteArray
final ByteArray getNullableByteArray(String key)
Returns the unwrapped byte array value. The array will be linked and any modification will also change wrapper and the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableString
final String getNullableString(String key)
Returns the unwrapped string value or null if no value is mapped, or it is mapped to another type tag.
-
getNullableIntArray
final IntArray getNullableIntArray(String key)
Returns the unwrapped int array value. The array will be linked and any modification will also change wrapper and the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableLongArray
final LongArray getNullableLongArray(String key)
Returns the unwrapped long array value. The array will be linked and any modification will also change wrapper and the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableCompound
final NbtCompound getNullableCompound(String key)
Returns the NbtCompound mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableList
final NbtList<?> getNullableList(String key)
Returns the NbtList mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableByteList
final NbtList<NbtByte> getNullableByteList(String key)
Returns the NbtList of bytes mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableShortList
final NbtList<NbtShort> getNullableShortList(String key)
Returns the NbtList of shorts mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableIntList
final NbtList<NbtInt> getNullableIntList(String key)
Returns the NbtList of integers mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableLongList
final NbtList<NbtLong> getNullableLongList(String key)
Returns the NbtList of longs mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableFloatList
final NbtList<NbtFloat> getNullableFloatList(String key)
Returns the NbtList of floats mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableDoubleList
final NbtList<NbtDouble> getNullableDoubleList(String key)
Returns the NbtList of doubles mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableByteArrayList
final NbtList<NbtByteArray> getNullableByteArrayList(String key)
Returns the NbtList of byte arrays mapped to that key. The tag and it's value will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableStringList
final NbtList<NbtString> getNullableStringList(String key)
Returns the NbtList of strings mapped to that key. The tag will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableIntArrayList
final NbtList<NbtIntArray> getNullableIntArrayList(String key)
Returns the NbtList of int arrays mapped to that key. The tag and it's value will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableLongArrayList
final NbtList<NbtLongArray> getNullableLongArrayList(String key)
Returns the NbtList of long arrays mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableCompoundList
final NbtList<NbtCompound> getNullableCompoundList(String key)
Returns the NbtList of compounds mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
getNullableListOfList
final NbtList<NbtList<?>> getNullableListOfList(String key)
Returns the NbtList of lists mapped to that key. The tag and it's values will be linked and any modification will also change the mapped value.
Will return null if no value is mapped, or it is mapped to another type tag.
-
copyFrom
final Unit copyFrom(NbtCompound other, String tagKey, NbtTag default)
Checks if the other compound have a given tag, if it has been placed it in this compound.
The tag will be linked, so any change in the tag will also affect both compounds.
- Parameters:
other
- The compound that will be checkedtagKey
- The name of the tag that will be mappeddefault
- If the other compound doesn't have the tag then this parameter will be used.
-
copyTo
final Unit copyTo(NbtCompound other, String tagKey, NbtTag default)
Checks if the compound have a given tag, if it has been placed it in the other compound.
The tag will be linked, so any change in the tag will also affect both compounds.
- Parameters:
other
- The compound that will be modifiedtagKey
- The name of the tag that will be mappeddefault
- If the compound doesn't have the tag then this parameter will be used.
-
deepCopy
NbtCompound deepCopy()
Returns a new NbtCompound with all nested values copied deeply.
-
-
-
-