Delete unused features
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
||||
|
||||
package net.axay.kspigot.data
|
||||
|
||||
import net.axay.kspigot.annotations.NMS_General
|
||||
import net.minecraft.nbt.MojangsonParser
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
@NMS_General
|
||||
class NBTData {
|
||||
val nbtTagCompound: NBTTagCompound
|
||||
|
||||
constructor(nbtTagCompound: NBTTagCompound?) {
|
||||
this.nbtTagCompound = nbtTagCompound ?: NBTTagCompound()
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.nbtTagCompound = NBTTagCompound()
|
||||
}
|
||||
|
||||
constructor(nbtString: String) : this(MojangsonParser.parse(nbtString))
|
||||
|
||||
fun serialize() = nbtTagCompound.toString()
|
||||
|
||||
/**
|
||||
* This method gets the value
|
||||
* at the given [key]. The returned [dataType]
|
||||
* must be specified.
|
||||
* The returned value is null, if it
|
||||
* was not possible to find any value at
|
||||
* the specified location, or if the type
|
||||
* is not the one which was specified.
|
||||
*/
|
||||
operator fun <T> get(key: String, dataType: NBTDataType<T>): T? {
|
||||
val value = nbtTagCompound.get(key)
|
||||
return if (value != null) {
|
||||
dataType.decodeNMS(value)
|
||||
} else null
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets some [value]
|
||||
* at the position of the given [key].
|
||||
* The [dataType] of the given [value]
|
||||
* must be specified.
|
||||
*/
|
||||
operator fun <T> set(key: String, dataType: NBTDataType<T>, value: T) {
|
||||
dataType.writeToCompound(key, value, nbtTagCompound)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes the
|
||||
* given [key] from the NBTTagCompound.
|
||||
* Its value will be lost.
|
||||
*/
|
||||
fun remove(key: String) = nbtTagCompound.remove(key)
|
||||
|
||||
/** @see remove */
|
||||
operator fun minusAssign(key: String) = remove(key)
|
||||
|
||||
companion object {
|
||||
fun deserialize(nbtString: String) = NBTData(nbtString)
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
package net.axay.kspigot.data
|
||||
|
||||
import net.axay.kspigot.annotations.NMS_General
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@NMS_General
|
||||
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() {
|
||||
CraftItemStack.asNMSCopy(this).let {
|
||||
return if (it.hasTag()) NBTData(it.tag) else NBTData()
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
package net.axay.kspigot.data
|
||||
|
||||
import net.axay.kspigot.annotations.NMS_General
|
||||
import net.minecraft.nbt.*
|
||||
|
||||
@NMS_General
|
||||
interface NBTDataType<T> {
|
||||
fun decodeNMS(nbtBase: NBTBase): T?
|
||||
fun writeToCompound(key: String, data: T, compound: NBTTagCompound)
|
||||
|
||||
companion object {
|
||||
val COMPOUND = nbtDataType<NBTData, NBTTagCompound>(
|
||||
{ NBTData(it) },
|
||||
{ key, data, compound -> compound.set(key, data.nbtTagCompound) }
|
||||
)
|
||||
val BYTE = nbtDataType<Byte, NBTTagByte>(
|
||||
{ it.asByte() },
|
||||
{ key, data, compound -> compound.setByte(key, data) }
|
||||
)
|
||||
val BYTE_ARRAY = nbtDataType<ByteArray, NBTTagByteArray>(
|
||||
{ it.bytes },
|
||||
{ key, data, compound -> compound.setByteArray(key, data) }
|
||||
)
|
||||
val DOUBLE = nbtDataType<Double, NBTTagDouble>(
|
||||
{ it.asDouble() },
|
||||
{ key, data, compound -> compound.setDouble(key, data) }
|
||||
)
|
||||
val FLOAT = nbtDataType<Float, NBTTagFloat>(
|
||||
{ it.asFloat() },
|
||||
{ key, data, compound -> compound.setFloat(key, data) }
|
||||
)
|
||||
val INT = nbtDataType<Int, NBTTagInt>(
|
||||
{ it.asInt() },
|
||||
{ key, data, compound -> compound.setInt(key, data) }
|
||||
)
|
||||
val INT_ARRAY = nbtDataType<IntArray, NBTTagIntArray>(
|
||||
{ it.ints },
|
||||
{ key, data, compound -> compound.setIntArray(key, data) }
|
||||
)
|
||||
val LONG = nbtDataType<Long, NBTTagLong>(
|
||||
{ it.asLong() },
|
||||
{ key, data, compound -> compound.setLong(key, data) }
|
||||
)
|
||||
val LONG_ARRAY = nbtDataType<LongArray, NBTTagLongArray>(
|
||||
{ it.longs },
|
||||
{ key, data, compound -> compound.set(key, NBTTagLongArray(data)) }
|
||||
)
|
||||
val SHORT = nbtDataType<Short, NBTTagShort>(
|
||||
{ it.asShort() },
|
||||
{ key, data, compound -> compound.setShort(key, data) }
|
||||
)
|
||||
val STRING = nbtDataType<String, NBTTagString>(
|
||||
{ it.asString() },
|
||||
{ key, data, compound -> compound.setString(key, data) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @property T the JVM data type
|
||||
* @property E the NBT data type
|
||||
*/
|
||||
private inline fun <T, reified E> nbtDataType(
|
||||
crossinline decodeNMS: (E) -> T,
|
||||
crossinline writeToCompound: (key: String, data: T, compound: NBTTagCompound) -> Unit,
|
||||
): NBTDataType<T> {
|
||||
return object : NBTDataType<T> {
|
||||
override fun decodeNMS(nbtBase: NBTBase) = if (nbtBase is E) decodeNMS.invoke(nbtBase) else null
|
||||
override fun writeToCompound(key: String, data: T, compound: NBTTagCompound) =
|
||||
writeToCompound.invoke(key, data, compound)
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
package net.axay.kspigot.utils
|
||||
|
||||
/**
|
||||
* Loads the value of the given field for this object.
|
||||
*/
|
||||
internal fun <T> Any.reflectField(field: String): T {
|
||||
val reflectedField = this::class.java.getDeclaredField(field)
|
||||
reflectedField.isAccessible = true
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return reflectedField.get(this) as T
|
||||
}
|
Reference in New Issue
Block a user