From bde12aab91a554ec081f527f87de0ac9302dab4b Mon Sep 17 00:00:00 2001 From: Jakob K Date: Sun, 12 Dec 2021 03:04:42 +0100 Subject: [PATCH] Delete unused features --- .../kotlin/net/axay/kspigot/data/NBTData.kt | 64 ----------------- .../net/axay/kspigot/data/NBTDataLoader.kt | 27 ------- .../net/axay/kspigot/data/NBTDataType.kt | 72 ------------------- .../kspigot/utils/ReflectionExtensions.kt | 11 --- 4 files changed, 174 deletions(-) delete mode 100644 src/main/kotlin/net/axay/kspigot/data/NBTData.kt delete mode 100644 src/main/kotlin/net/axay/kspigot/data/NBTDataLoader.kt delete mode 100644 src/main/kotlin/net/axay/kspigot/data/NBTDataType.kt delete mode 100644 src/main/kotlin/net/axay/kspigot/utils/ReflectionExtensions.kt diff --git a/src/main/kotlin/net/axay/kspigot/data/NBTData.kt b/src/main/kotlin/net/axay/kspigot/data/NBTData.kt deleted file mode 100644 index e65dae15..00000000 --- a/src/main/kotlin/net/axay/kspigot/data/NBTData.kt +++ /dev/null @@ -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 get(key: String, dataType: NBTDataType): 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 set(key: String, dataType: NBTDataType, 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) - } -} diff --git a/src/main/kotlin/net/axay/kspigot/data/NBTDataLoader.kt b/src/main/kotlin/net/axay/kspigot/data/NBTDataLoader.kt deleted file mode 100644 index ab93dbd7..00000000 --- a/src/main/kotlin/net/axay/kspigot/data/NBTDataLoader.kt +++ /dev/null @@ -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() - } - } diff --git a/src/main/kotlin/net/axay/kspigot/data/NBTDataType.kt b/src/main/kotlin/net/axay/kspigot/data/NBTDataType.kt deleted file mode 100644 index e1bb023b..00000000 --- a/src/main/kotlin/net/axay/kspigot/data/NBTDataType.kt +++ /dev/null @@ -1,72 +0,0 @@ -package net.axay.kspigot.data - -import net.axay.kspigot.annotations.NMS_General -import net.minecraft.nbt.* - -@NMS_General -interface NBTDataType { - fun decodeNMS(nbtBase: NBTBase): T? - fun writeToCompound(key: String, data: T, compound: NBTTagCompound) - - companion object { - val COMPOUND = nbtDataType( - { NBTData(it) }, - { key, data, compound -> compound.set(key, data.nbtTagCompound) } - ) - val BYTE = nbtDataType( - { it.asByte() }, - { key, data, compound -> compound.setByte(key, data) } - ) - val BYTE_ARRAY = nbtDataType( - { it.bytes }, - { key, data, compound -> compound.setByteArray(key, data) } - ) - val DOUBLE = nbtDataType( - { it.asDouble() }, - { key, data, compound -> compound.setDouble(key, data) } - ) - val FLOAT = nbtDataType( - { it.asFloat() }, - { key, data, compound -> compound.setFloat(key, data) } - ) - val INT = nbtDataType( - { it.asInt() }, - { key, data, compound -> compound.setInt(key, data) } - ) - val INT_ARRAY = nbtDataType( - { it.ints }, - { key, data, compound -> compound.setIntArray(key, data) } - ) - val LONG = nbtDataType( - { it.asLong() }, - { key, data, compound -> compound.setLong(key, data) } - ) - val LONG_ARRAY = nbtDataType( - { it.longs }, - { key, data, compound -> compound.set(key, NBTTagLongArray(data)) } - ) - val SHORT = nbtDataType( - { it.asShort() }, - { key, data, compound -> compound.setShort(key, data) } - ) - val STRING = nbtDataType( - { it.asString() }, - { key, data, compound -> compound.setString(key, data) } - ) - } -} - -/** - * @property T the JVM data type - * @property E the NBT data type - */ -private inline fun nbtDataType( - crossinline decodeNMS: (E) -> T, - crossinline writeToCompound: (key: String, data: T, compound: NBTTagCompound) -> Unit, -): NBTDataType { - return object : NBTDataType { - 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) - } -} diff --git a/src/main/kotlin/net/axay/kspigot/utils/ReflectionExtensions.kt b/src/main/kotlin/net/axay/kspigot/utils/ReflectionExtensions.kt deleted file mode 100644 index cfd239be..00000000 --- a/src/main/kotlin/net/axay/kspigot/utils/ReflectionExtensions.kt +++ /dev/null @@ -1,11 +0,0 @@ -package net.axay.kspigot.utils - -/** - * Loads the value of the given field for this object. - */ -internal fun Any.reflectField(field: String): T { - val reflectedField = this::class.java.getDeclaredField(field) - reflectedField.isAccessible = true - @Suppress("UNCHECKED_CAST") - return reflectedField.get(this) as T -}