Improved NBTData api
This commit is contained in:
@@ -13,6 +13,10 @@ class NBTData {
|
||||
this.nbtTagCompound = nbtTagCompound ?: NBTTagCompound()
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.nbtTagCompound = NBTTagCompound()
|
||||
}
|
||||
|
||||
constructor(nbtString: String) : this(MojangsonParser.parse(nbtString))
|
||||
|
||||
fun serialize() = nbtTagCompound.toString()
|
||||
|
@@ -8,11 +8,19 @@ import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@NMS_General
|
||||
val Entity.nbtData: NBTData get() {
|
||||
val nbtTagCompound = NBTTagCompound()
|
||||
(this as CraftEntity).handle.load(nbtTagCompound)
|
||||
return NBTData(nbtTagCompound)
|
||||
}
|
||||
var Entity.nbtData: NBTData
|
||||
get() {
|
||||
val nbtTagCompound = NBTTagCompound()
|
||||
(this as CraftEntity).handle.load(nbtTagCompound)
|
||||
return NBTData(nbtTagCompound)
|
||||
}
|
||||
set(value) {
|
||||
(this as CraftEntity).handle.save(value.nbtTagCompound)
|
||||
}
|
||||
|
||||
@NMS_General
|
||||
val ItemStack.nbtData: NBTData get() = NBTData(CraftItemStack.asNMSCopy(this).tag)
|
||||
val ItemStack.nbtData: NBTData get() {
|
||||
CraftItemStack.asNMSCopy(this).let {
|
||||
return if (it.hasTag()) NBTData(it.tag) else NBTData()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user