Package xyz.gmitch215.socketmc.util
Class NBTTag
java.lang.Object
xyz.gmitch215.socketmc.util.NBTTag
- All Implemented Interfaces:
Serializable
Represents a NBT tag.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
createSection
(@NotNull String key) Creates a section in the tag.Converts a NBT string to aNBTTag
.Gets an object from the tag.Gets an object from the tag.boolean
getBoolean
(@NotNull String key) Gets a boolean from the tag.boolean
getBoolean
(@NotNull String key, boolean def) Gets a boolean from the tag.byte
Gets a byte from the tag.byte
Gets a byte from the tag.@org.jetbrains.annotations.NotNull byte[]
getByteArray
(@NotNull String key) Gets a byte array from the tag.@org.jetbrains.annotations.NotNull byte[]
getByteArray
(@NotNull String key, byte[] def) Gets a byte array from the tag.double
Gets a double from the tag.double
Gets a double from the tag.float
Gets a float from the tag.float
Gets a float from the tag.int
Gets an integer from the tag.int
Gets an integer from the tag.long
Gets a long from the tag.long
Gets a long from the tag.<T> T
Gets an object from the tag.<T> T
Gets an object from the tag.getSection
(@NotNull String key) Gets a section from the tag.short
Gets a short from the tag.short
Gets a short from the tag.Gets a string from the tag.Gets a string from the tag.getTag()
Gets an immutable copy of the full tag.void
Removes an object from the tag.void
Sets an object in the tag.toTag()
Converts the tag to a NBT string.
-
Constructor Details
-
NBTTag
public NBTTag()Constructs a new, empty NBTTag. -
NBTTag
Constructs a new NBTTag.- Parameters:
tag
- The tag.
-
-
Method Details
-
getTag
Gets an immutable copy of the full tag.- Returns:
- The tag.
-
get
Gets an object from the tag. If the object does not exist, null is returned.
This supports dot notation, for example, "key.subkey.subsubkey".
- Parameters:
key
- The key to get.- Returns:
- The object, or null if it does not exist.
-
set
Sets an object in the tag.- Parameters:
key
- The key to set.value
- The value to set. If null, will remove the key.
-
remove
Removes an object from the tag.- Parameters:
key
- The key to remove.
-
get
Gets an object from the tag. If the object does not exist, the default value is returned.
This supports dot notation, for example, "key.subkey.subsubkey".
- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The object, or the default value if it does not exist.
-
getObject
Gets an object from the tag. If the object does not exist, null is returned.- Type Parameters:
T
- The type of the object.- Parameters:
key
- The key to get.clazz
- The class of the object to cast to.- Returns:
- The object, or null if it does not exist.
-
getObject
@NotNull public <T> T getObject(@NotNull @NotNull String key, @NotNull @NotNull Class<T> clazz, T def) Gets an object from the tag. If the object does not exist, the default value is returned.- Type Parameters:
T
- The type of the object.- Parameters:
key
- The key to get.clazz
- The class of the object to cast to.def
- The default value.- Returns:
- The object, or the default value if it does not exist.
-
getSection
Gets a section from the tag. If the object does not exist, an empty map is returned.- Parameters:
key
- The key to get.- Returns:
- The section, or an empty map if it does not exist.
-
createSection
Creates a section in the tag. If it exists, it will be overwritten.- Parameters:
key
- The key to create.
-
getString
Gets a string from the tag. If the object does not exist, an empty string is returned.- Parameters:
key
- The key to get.- Returns:
- The string, or an empty string if it does not exist.
-
getString
@NotNull public @NotNull String getString(@NotNull @NotNull String key, @NotNull @NotNull String def) Gets a string from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The string, or the default value if it does not exist.
-
getBoolean
Gets a boolean from the tag. If the object does not exist, false is returned.- Parameters:
key
- The key to get.- Returns:
- The boolean, or false if it does not exist.
-
getBoolean
Gets a boolean from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The boolean, or the default value if it does not exist.
-
getByte
Gets a byte from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The byte, or 0 if it does not exist.
-
getByte
Gets a byte from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The byte, or the default value if it does not exist.
-
getShort
Gets a short from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The short, or 0 if it does not exist.
-
getShort
Gets a short from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The short, or the default value if it does not exist.
-
getInt
Gets an integer from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The integer, or 0 if it does not exist.
-
getInt
Gets an integer from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The integer, or the default value if it does not exist.
-
getLong
Gets a long from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The long, or 0 if it does not exist.
-
getLong
Gets a long from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The long, or the default value if it does not exist.
-
getFloat
Gets a float from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The float, or 0 if it does not exist.
-
getFloat
Gets a float from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The float, or the default value if it does not exist.
-
getDouble
Gets a double from the tag. If the object does not exist, 0 is returned.- Parameters:
key
- The key to get.- Returns:
- The double, or 0 if it does not exist.
-
getDouble
Gets a double from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The double, or the default value if it does not exist.
-
getByteArray
@NotNull public @org.jetbrains.annotations.NotNull byte[] getByteArray(@NotNull @NotNull String key) Gets a byte array from the tag. If the object does not exist, an empty byte array is returned.- Parameters:
key
- The key to get.- Returns:
- The byte array, or an empty byte array if it does not exist.
-
getByteArray
@NotNull public @org.jetbrains.annotations.NotNull byte[] getByteArray(@NotNull @NotNull String key, byte[] def) Gets a byte array from the tag. If the object does not exist, the default value is returned.- Parameters:
key
- The key to get.def
- The default value.- Returns:
- The byte array, or the default value if it does not exist.
-
toTag
Converts the tag to a NBT string.- Returns:
- The tag as a string.
-
fromTag
Converts a NBT string to aNBTTag
.- Parameters:
string
- The string to convert.- Returns:
- The converted tag.
-