Class CompoundTag

java.lang.Object
net.glowstone.util.nbt.Tag<Map<String,Tag>>
net.glowstone.util.nbt.CompoundTag
All Implemented Interfaces:
DynamicallyTypedMap<String>, DynamicallyTypedMapWithDoubles<String>, DynamicallyTypedMapWithFloats<String>

public class CompoundTag extends Tag<Map<String,Tag>> implements DynamicallyTypedMapWithDoubles<String>
The TAG_Compound tag.
  • Constructor Details

    • CompoundTag

      public CompoundTag()
      Creates a new, empty CompoundTag.
    • CompoundTag

      public CompoundTag(Map<String,Tag> value)
  • Method Details

    • valueToString

      protected void valueToString(StringBuilder builder)
      Overrides:
      valueToString in class Tag<Map<String,Tag>>
    • isEmpty

      public boolean isEmpty()
    • containsKey

      public boolean containsKey(@NonNls @NonNls String key)
      Check if the compound contains the given key.
      Parameters:
      key - The key.
      Returns:
      True if the key is in the map.
    • remove

      public void remove(@NonNls @NonNls String key)
    • matches

      public boolean matches(CompoundTag other)
      Checks to see if this tag is a strict, deep submap of the given CompoundTag.
      Parameters:
      other - The CompoundTag that should contain our values.
    • mergeInto

      public void mergeInto(CompoundTag other, boolean overwrite)
      Merges the contents of this compound into the supplied compound.
      Parameters:
      other - the other compound to merge into.
      overwrite - whether keys already set in the other compound should be overwritten.
    • getNumber

      public Number getNumber(String key)
      Returns the value of a numeric subtag.
      Parameters:
      key - the key to look up
      Returns:
      the numeric tag value
    • getByte

      public byte getByte(@NonNls @NonNls String key)
      Returns the value of a byte subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getShort

      public short getShort(@NonNls @NonNls String key)
      Returns the value of a short subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getInt

      public int getInt(@NonNls @NonNls String key)
      Returns the value of an int subtag.
      Specified by:
      getInt in interface DynamicallyTypedMap<String>
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getBoolean

      public boolean getBoolean(@NonNls @NonNls String key)
      Description copied from interface: DynamicallyTypedMap
      Retrieves an entry as a boolean.
      Specified by:
      getBoolean in interface DynamicallyTypedMap<String>
      Parameters:
      key - the key to look up
      Returns:
      the value as a boolean
    • getBoolean

      public boolean getBoolean(@NonNls @NonNls String key, boolean defaultValue)
      Returns the boolean value of a byte subtag if present, or a default otherwise.
      Parameters:
      key - the key to look up
      defaultValue - the value to return if the subtag is missing
      Returns:
      the tag value as a boolean, or defaultValue if it's not a byte
    • getLong

      public long getLong(@NonNls @NonNls String key)
      Returns the value of a long subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getFloat

      public float getFloat(@NonNls @NonNls String key)
      Returns the value of a float subtag.
      Specified by:
      getFloat in interface DynamicallyTypedMapWithFloats<String>
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getDouble

      public double getDouble(@NonNls @NonNls String key)
      Returns the value of a double subtag.
      Specified by:
      getDouble in interface DynamicallyTypedMapWithDoubles<String>
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getByteArray

      public byte[] getByteArray(@NonNls @NonNls String key)
      Returns the value of a byte[] subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getString

      public String getString(@NonNls @NonNls String key)
      Returns the value of a String subtag.
      Specified by:
      getString in interface DynamicallyTypedMap<String>
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getIntArray

      public int[] getIntArray(@NonNls @NonNls String key)
      Returns the value of an int[] subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getLongArray

      public long[] getLongArray(@NonNls @NonNls String key)
      Returns the value of an long[] subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • getList

      public <V> List<V> getList(@NonNls @NonNls String key, TagType type)
      Returns the value of a List subtag.
      Type Parameters:
      V - the list element type
      Parameters:
      key - the key to look up
      type - the list element tag type
      Returns:
      the tag value
    • getCompound

      public CompoundTag getCompound(@NonNls @NonNls String key)
      Returns the value of a compound subtag.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • tryGetCompound

      public Optional<CompoundTag> tryGetCompound(@NonNls @NonNls String key)
      Returns the value of a compound subtag, if it exists. Multiple strings can be passed in to retrieve a sub-subtag (e.g. tryGetCompound("foo", "bar") returns a compound subtag called "bar" of a compound subtag called "foo", or null if either of those tags doesn't exist or isn't compound.
      Parameters:
      key - the key to look up
      Returns:
      the tag value, or an empty optional if the tag doesn't exist or isn't compound
    • readCompound

      public boolean readCompound(@NonNls @NonNls String key, Consumer<? super CompoundTag> consumer)
      Applies the given function to a compound subtag if it is present. Multiple strings can be passed in to operate on a sub-subtag, as with tryGetCompound(String).
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readFloat

      public boolean readFloat(@NonNls @NonNls String key, FloatConsumer consumer)
      Applies the given function to a float subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readDouble

      public boolean readDouble(@NonNls @NonNls String key, DoubleConsumer consumer)
      Applies the given function to a double subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readInt

      public boolean readInt(@NonNls @NonNls String key, IntConsumer consumer)
      Applies the given function to an integer subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readByteArray

      public boolean readByteArray(@NonNls @NonNls String key, Consumer<? super byte[]> consumer)
      Applies the given function to a byte array subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readIntArray

      public boolean readIntArray(@NonNls @NonNls String key, Consumer<? super int[]> consumer)
      Applies the given function to an integer array subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readLongArray

      public boolean readLongArray(@NonNls @NonNls String key, Consumer<? super long[]> consumer)
    • readLong

      public boolean readLong(@NonNls @NonNls String key, LongConsumer consumer)
      Applies the given function to a long subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • tryGetLong

      public Optional<Long> tryGetLong(@NonNls @NonNls String key)
      Returns the value of a long subtag if it is present.
      Parameters:
      key - the key to look up
      Returns:
      an Optional with the value of that tag if it's present and is a long; an empty Optional otherwise
    • readShort

      public boolean readShort(@NonNls @NonNls String key, ShortConsumer consumer)
      Applies the given function to an integer subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readItem

      public boolean readItem(@NonNls @NonNls String key, Consumer<? super org.bukkit.inventory.ItemStack> consumer)
      Applies the given function to a compound subtag if it is present, first converting it to an item using NbtSerialization.readItem(CompoundTag).
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readBoolean

      public boolean readBoolean(@NonNls @NonNls String key, Consumer<? super Boolean> consumer)
      Applies the given function to a byte subtag if it is present, converting it to boolean first.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readByte

      public boolean readByte(@NonNls @NonNls String key, Consumer<? super Byte> consumer)
      Applies the given function to a byte subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readBooleanNegated

      public boolean readBooleanNegated(@NonNls @NonNls String key, Consumer<? super Boolean> consumer)
      Applies the given function to a byte subtag if it is present, converting it to boolean and negating it first.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readList

      public <T> boolean readList(@NonNls @NonNls String key, TagType type, Consumer<? super List<T>> consumer)
      Applies the given function to a list subtag if it is present, converting it to a list of values first.
      Type Parameters:
      T - the type to convert the list entries to
      Parameters:
      key - the key to look up
      type - the type that the list entries must be
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readCompoundList

      public boolean readCompoundList(@NonNls @NonNls String key, Consumer<? super List<CompoundTag>> consumer)
      Applies the given function to a list subtag if it is present and its contents are compound tags. Processes the list as a single object; to process each tag separately, instead use iterateCompoundList(String, Consumer).
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • iterateCompoundList

      public boolean iterateCompoundList(@NonNls @NonNls String key, Consumer<? super CompoundTag> consumer)
      Applies the given function to each compound tag in a compound-list subtag, if that subtag exists.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was iterated over (even if it was empty); false otherwise
    • readStringList

      public boolean readStringList(@NonNls @NonNls String key, Consumer<? super List<String>> consumer)
      Applies the given function to a list subtag if it is present and its contents are string tags.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readFloatList

      public boolean readFloatList(@NonNls @NonNls String key, Consumer<? super List<Float>> consumer)
      Applies the given function to a list subtag if it is present and its contents are float tags.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readDoubleList

      public boolean readDoubleList(@NonNls @NonNls String key, Consumer<? super List<Double>> consumer)
      Applies the given function to a list subtag if it is present and its contents are double tags.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • readString

      public boolean readString(@NonNls @NonNls String key, Consumer<? super String> consumer)
      Applies the given function to a string subtag if it is present.
      Parameters:
      key - the key to look up
      consumer - the function to apply
      Returns:
      true if the tag exists and was passed to the consumer; false otherwise
    • tryGetMaterial

      public Optional<org.bukkit.Material> tryGetMaterial(@NonNls @NonNls String key)
      Reads a material from a string ID or numeric ID, depending on the tag type. Returns null if the tag isn't present, its type is neither string nor any integral type, or its value isn't a valid material ID.
      Parameters:
      key - the key to look up
      Returns:
      the Material denoted by that key, if present and readable; an empty Optional otherwise
    • tryGetBlockData

      public Optional<org.bukkit.block.data.BlockData> tryGetBlockData(@NonNls @NonNls String key)
    • tryGetString

      public Optional<String> tryGetString(@NonNls @NonNls String key)
      Returns the value of a string subtag if it is present.
      Parameters:
      key - the key to look up
      Returns:
      an Optional with the value of that tag if it's present and is a string; an empty optional otherwise
    • tryGetInt

      public Optional<Integer> tryGetInt(@NonNls @NonNls String key)
      Returns the value of an int subtag if it is present.
      Parameters:
      key - the key to look up
      Returns:
      an Optional with the value of that tag if it's present and is an int; an empty optional otherwise
    • readUniqueId

      @Deprecated public boolean readUniqueId(@NonNls @NonNls String keyMost, @NonNls @NonNls String keyLeast, Consumer<? super UUID> consumer)
      Deprecated.
      use readUniqueId(String, Consumer) for modern int-array UUID representation.
      Applies the given function to a UUID extracted from the given pair of long subtags, if they both exist.
      Uses Most/Least representation.
      Parameters:
      keyMost - the key to look up the high word of the UUID
      keyLeast - the key to look up the low word of the UUID
      consumer - the function to apply
      Returns:
      true if the tags exist and were passed to the consumer; false otherwise
    • readUniqueId

      public boolean readUniqueId(@NonNls @NonNls String key, Consumer<? super UUID> consumer)
    • tryGetUniqueId

      @Deprecated public Optional<UUID> tryGetUniqueId(@NonNls @NonNls String keyMost, @NonNls @NonNls String keyLeast)
      Deprecated.
      use tryGetUniqueId(String) for modern int-array UUID representation.
      Returns a UUID extracted from the given pair of long subtags, if they both exist.
      Parameters:
      keyMost - the key to look up the high word of the UUID
      keyLeast - the key to look up the low word of the UUID
      Returns:
      the UUID, or an empty Optional if either tag is missing or not long type
    • tryGetUniqueId

      public Optional<UUID> tryGetUniqueId(@NonNls @NonNls String key)
    • getCompoundList

      public List<CompoundTag> getCompoundList(@NonNls @NonNls String key)
      Returns the value of a list subtag with CompoundTag elements.
      Parameters:
      key - the key to look up
      Returns:
      the tag value
    • isNumeric

      public boolean isNumeric(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of a numeric type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is numeric; false otherwise
    • isByte

      public boolean isByte(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of byte type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a byte; false otherwise
    • isShort

      public boolean isShort(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of short type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a short; false otherwise
    • isInt

      public boolean isInt(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of int type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is an int; false otherwise
    • isLong

      public boolean isLong(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of long type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a long; false otherwise
    • isFloat

      public boolean isFloat(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of float type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a float; false otherwise
    • isDouble

      public boolean isDouble(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of double type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a double; false otherwise
    • isByteArray

      public boolean isByteArray(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of byte[] type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a byte[]; false otherwise
    • isString

      public boolean isString(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of String type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a String; false otherwise
    • isIntArray

      public boolean isIntArray(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of int[] type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is an int[]; false otherwise
    • isLongArray

      public boolean isLongArray(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of long[] type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is an long[]; false otherwise
    • isList

      public boolean isList(@NonNls @NonNls String key, TagType type)
      Test whether the subtag with the given key is of List type.
      Parameters:
      key - the key to look up
      type - the TagType of the list's elements
      Returns:
      true if the subtag exists and is a List; false otherwise
    • isCompound

      public boolean isCompound(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of CompoundTag type.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a CompoundTag; false otherwise
    • isCompoundList

      public boolean isCompoundList(@NonNls @NonNls String key)
      Test whether the subtag with the given key is of List type with elements of type CompoundTag.
      Parameters:
      key - the key to look up
      Returns:
      true if the subtag exists and is a List with elements of type CompoundTag; false otherwise
    • putBool

      public void putBool(@NonNls @NonNls String key, boolean value)
    • putByte

      public void putByte(@NonNls @NonNls String key, int value)
    • putShort

      public void putShort(@NonNls @NonNls String key, int value)
    • putInt

      public void putInt(@NonNls @NonNls String key, int value)
    • putLong

      public void putLong(@NonNls @NonNls String key, long value)
    • putFloat

      public void putFloat(@NonNls @NonNls String key, double value)
    • putDouble

      public void putDouble(@NonNls @NonNls String key, double value)
    • putByteArray

      public void putByteArray(@NonNls @NonNls String key, byte... value)
    • putString

      public void putString(@NonNls @NonNls String key, @NonNls @NonNls String value)
    • putIntArray

      public void putIntArray(@NonNls @NonNls String key, int... value)
    • putLongArray

      public void putLongArray(@NonNls @NonNls String key, long... value)
    • putList

      public <V> void putList(@NonNls @NonNls String key, TagType type, List<V> value, Function<? super V,? extends Tag> tagCreator)
      Adds or replaces a list subtag, converting the list entries to tags.
      Type Parameters:
      V - the list elements' Java type
      Parameters:
      key - the key to write to
      type - the list elements' tag type
      value - the list contents, as objects to convert to tags
      tagCreator - a function that will convert each V to an element tag
    • putCompound

      public void putCompound(@NonNls @NonNls String key, CompoundTag tag)
    • putCompoundList

      public void putCompoundList(@NonNls @NonNls String key, List<CompoundTag> list)
      Adds or replaces a list subtag with a list of compound tags.
      Parameters:
      key - the key to write to
      list - the list contents as compound tags
    • putStringList

      public void putStringList(@NonNls @NonNls String key, List<String> list)
      Adds or replaces a list subtag with a list of strings.
      Parameters:
      key - the key to write to
      list - the list contents as strings, to convert to string tags
    • putFloatList

      public void putFloatList(@NonNls @NonNls String key, List<Float> list)
      Adds or replaces a list subtag with a list of floats.
      Parameters:
      key - the key to write to
      list - the list contents as floats, to convert to float tags
    • putDoubleList

      public void putDoubleList(@NonNls @NonNls String key, List<Double> list)
      Adds or replaces a list subtag with a list of doubles.
      Parameters:
      key - the key to write to
      list - the list contents as doubles, to convert to double tags
    • putLongList

      public void putLongList(@NonNls @NonNls String key, List<Long> list)
      Adds or replaces a list subtag with a list of longs.
      Parameters:
      key - the key to write to
      list - the list contents as longs, to convert to long tags
    • putUniqueId

      public void putUniqueId(@NonNls @NonNls String key, UUID uuid)
    • getValue

      public Map<String,Tag> getValue()
      The value.
      Specified by:
      getValue in class Tag<Map<String,Tag>>
      Returns:
      The value of this tag.