From 4b273c968934809c47e15609d0f6d159e8f12be1 Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 8 Dec 2023 19:33:03 +0100 Subject: [PATCH] feat: bump to 1.20.4 --- gradle/libs.versions.toml | 30 +++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../commands/children/ChildManager.kt | 2 +- .../idofront/nms/aliases/Conversions.kt | 8 ++--- .../idofront/nms/nbt/OfflinePDC.kt | 2 +- .../idofront/nms/nbt/WrappedPDC.kt | 16 +++++++--- .../serialization/PotionDataSerializer.kt | 31 ------------------- .../PotionEffectTypeSerializer.kt | 9 ++++-- .../serialization/PotionTypeSerializer.kt | 26 ++++++++++++++++ .../serialization/SerializableEnchantment.kt | 11 +++---- .../serialization/SerializableItemStack.kt | 15 +++++---- .../recipes/PotionMixRecipeIngredients.kt | 4 +-- 12 files changed, 79 insertions(+), 77 deletions(-) delete mode 100644 idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionDataSerializer.kt create mode 100644 idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionTypeSerializer.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ad22e0f..ccedd9e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,36 +1,36 @@ [versions] -minecraft = "1.20.2-R0.1-SNAPSHOT" -kotlin = "1.9.10" +minecraft = "1.20.4-R0.1-SNAPSHOT" +kotlin = "1.9.20" jvm = "17" -anvilgui = "1.9.0-SNAPSHOT" +anvilgui = "1.9.2-SNAPSHOT" coroutines = "1.7.3" -compose = "1.5.2" -exposed = "0.44.0" +compose = "1.5.11" +exposed = "0.46.0" fastutil = "8.2.2" -fawe = "2.8.0" +fawe = "2.8.4" junit = "5.10.0" -kaml = "0.55.0" +kaml = "0.57.0" kmongo = "4.8.0" #Deprecated due to MongoDB including Kotlin -kotest = "5.7.2" +kotest = "5.8.0" kt-statistics = "1.2.1" ktor = "2.3.6" logback = "1.4.11" -mccoroutine = "2.13.0" -mockbukkit = "3.24.1" +mccoroutine = "2.14.0" +mockbukkit = "3.65.0" mockk = "1.13.8" -modelengine = "R4.0.2" +modelengine = "R4.0.3" protocollib = "5.1.0" reflections = "0.10.2" -serialization = "1.6.0" +serialization = "1.6.2" sqlite-jdbc = "3.43.0.0" vault = "1.7" worldguard = "7.1.0-SNAPSHOT" -creative = "1.3.0" +creative = "1.6.0" mythic-dist = "5.2.6" mythiccrucible = "1.6.0" -oraxen = "1.164.0" +oraxen = "1.167.0" itemsadder = "3.5.0b" @@ -38,7 +38,7 @@ itemsadder = "3.5.0b" dokka = "1.9.0" shadowjar = "8.1.1" dependencyversions = "0.48.0" -userdev = "1.5.8" +userdev = "1.5.11" [libraries] minecraft-papermc = { module = "io.papermc.paper:paper-api", version.ref = "minecraft" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..a595206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/children/ChildManager.kt b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/children/ChildManager.kt index 413442a..cdb1c3e 100644 --- a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/children/ChildManager.kt +++ b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/children/ChildManager.kt @@ -17,7 +17,7 @@ class ChildManager : ChildRunning { with(command) { //if there are extra arguments and sub-commands exist, we first try to match them to any sub-commands - if (argumentsWereSent && subcommand.names.contains(firstArgument)) { + if (argumentsWereSent && firstArgument in subcommand.names) { applySharedTo(subcommand) subcommand.runWith(init) this.executedCommand = true diff --git a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/aliases/Conversions.kt b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/aliases/Conversions.kt index 16d200e..ce37f4e 100644 --- a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/aliases/Conversions.kt +++ b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/aliases/Conversions.kt @@ -5,10 +5,10 @@ package com.mineinabyss.idofront.nms.aliases import net.minecraft.server.level.ServerLevel import net.minecraft.world.entity.player.Inventory import net.minecraft.world.level.Level -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld -import org.bukkit.craftbukkit.v1_20_R2.entity.* -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventoryPlayer -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_20_R3.CraftWorld +import org.bukkit.craftbukkit.v1_20_R3.entity.* +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryPlayer +import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack import org.bukkit.entity.* import org.bukkit.inventory.ItemStack import org.bukkit.inventory.PlayerInventory diff --git a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/OfflinePDC.kt b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/OfflinePDC.kt index c4c1136..c464e4c 100644 --- a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/OfflinePDC.kt +++ b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/OfflinePDC.kt @@ -4,7 +4,7 @@ import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.NbtIo import org.bukkit.Bukkit import org.bukkit.OfflinePlayer -import org.bukkit.craftbukkit.v1_20_R2.CraftServer +import org.bukkit.craftbukkit.v1_20_R3.CraftServer import java.io.File import java.nio.file.Files import java.util.* diff --git a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/WrappedPDC.kt b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/WrappedPDC.kt index 58fcd65..a8a72ac 100644 --- a/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/WrappedPDC.kt +++ b/idofront-nms/src/main/kotlin/com/mineinabyss/idofront/nms/nbt/WrappedPDC.kt @@ -4,8 +4,8 @@ import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.NbtIo import net.minecraft.nbt.Tag import org.bukkit.NamespacedKey -import org.bukkit.craftbukkit.v1_20_R2.persistence.CraftPersistentDataAdapterContext -import org.bukkit.craftbukkit.v1_20_R2.persistence.CraftPersistentDataTypeRegistry +import org.bukkit.craftbukkit.v1_20_R3.persistence.CraftPersistentDataAdapterContext +import org.bukkit.craftbukkit.v1_20_R3.persistence.CraftPersistentDataTypeRegistry import org.bukkit.persistence.PersistentDataAdapterContext import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataType @@ -26,7 +26,7 @@ class WrappedPDC( override fun set(key: NamespacedKey, type: PersistentDataType, value: Z) { compoundTag.put( key.toString(), - DATA_TYPE_REGISTRY.wrap(type.primitiveType, type.toPrimitive(value, adapterContext)) + DATA_TYPE_REGISTRY.wrap(type, type.toPrimitive(value, adapterContext)) ) } @@ -38,7 +38,7 @@ class WrappedPDC( override fun get(key: NamespacedKey, type: PersistentDataType): Z? { val value: Tag = compoundTag.get(key.toString()) ?: return null - return type.fromPrimitive(DATA_TYPE_REGISTRY.extract(type.primitiveType, value), adapterContext) + return type.fromPrimitive(DATA_TYPE_REGISTRY.extract(type, value), adapterContext) } override fun getOrDefault( @@ -56,6 +56,14 @@ class WrappedPDC( override fun isEmpty(): Boolean = compoundTag.isEmpty + override fun copyTo(other: PersistentDataContainer, replace: Boolean) { + val target = (other as? WrappedPDC)?.compoundTag ?: return + if (replace) target.tags.putAll(compoundTag.tags) + else compoundTag.tags.forEach { (key, value) -> + if (key !in target) target.put(key, value) + } + } + override fun getAdapterContext(): PersistentDataAdapterContext = adapterContext override fun serializeToBytes(): ByteArray { diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionDataSerializer.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionDataSerializer.kt deleted file mode 100644 index 6657b25..0000000 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionDataSerializer.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.mineinabyss.idofront.serialization - -import kotlinx.serialization.KSerializer -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder -import kotlinx.serialization.encoding.Encoder -import org.bukkit.potion.PotionData -import org.bukkit.potion.PotionType - -@Serializable -@SerialName("PotionData") -private class PotionDataSurrogate( - val type: PotionType, - val extended: Boolean, - val upgraded: Boolean, -) - -object PotionDataSerializer : KSerializer { - override val descriptor: SerialDescriptor = PotionDataSurrogate.serializer().descriptor - - override fun serialize(encoder: Encoder, value: PotionData) { - encoder.encodeSerializableValue(PotionDataSurrogate.serializer(), PotionDataSurrogate(value.type, value.isExtended, value.isUpgraded)) - } - - override fun deserialize(decoder: Decoder): PotionData { - val surrogate = decoder.decodeSerializableValue(PotionDataSurrogate.serializer()) - return PotionData(surrogate.type, surrogate.extended, surrogate.upgraded) - } -} diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionEffectTypeSerializer.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionEffectTypeSerializer.kt index a0b4b5e..c51367f 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionEffectTypeSerializer.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionEffectTypeSerializer.kt @@ -1,31 +1,34 @@ package com.mineinabyss.idofront.serialization +import com.mineinabyss.idofront.util.toMCKey import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import org.bukkit.Registry import org.bukkit.potion.PotionEffectType @JvmInline @Serializable @SerialName("PotionEffectType") private value class PotionEffectTypeSurrogate(val type: String) { + init { - require(type.isNotBlank() && PotionEffectType.getByName(type) != null) { "PotionEffectType must be valid" } + require(type.isNotBlank() && Registry.POTION_EFFECT_TYPE.get(type.toMCKey()) != null) { "PotionEffectType must be valid" } } } object PotionEffectTypeSerializer : KSerializer { override val descriptor: SerialDescriptor = PotionEffectTypeSurrogate.serializer().descriptor override fun serialize(encoder: Encoder, value: PotionEffectType) { - val surrogate = PotionEffectTypeSurrogate(value.name) + val surrogate = PotionEffectTypeSurrogate(value.key.asString()) encoder.encodeSerializableValue(PotionEffectTypeSurrogate.serializer(), surrogate) } override fun deserialize(decoder: Decoder): PotionEffectType { val surrogate = decoder.decodeSerializableValue(PotionEffectTypeSurrogate.serializer()) - return PotionEffectType.getByName(surrogate.type)!! + return Registry.POTION_EFFECT_TYPE.get(surrogate.type.toMCKey())!! } } diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionTypeSerializer.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionTypeSerializer.kt new file mode 100644 index 0000000..3c62a1a --- /dev/null +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/PotionTypeSerializer.kt @@ -0,0 +1,26 @@ +package com.mineinabyss.idofront.serialization + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import org.bukkit.potion.PotionType + +@Serializable +@SerialName("PotionType") +private class PotionTypeSurrogate(val type: PotionType) + +object PotionTypeSerializer : KSerializer { + override val descriptor: SerialDescriptor = PotionTypeSurrogate.serializer().descriptor + + override fun serialize(encoder: Encoder, value: PotionType) { + encoder.encodeSerializableValue(PotionTypeSurrogate.serializer(), PotionTypeSurrogate(value)) + } + + override fun deserialize(decoder: Decoder): PotionType { + val surrogate = decoder.decodeSerializableValue(PotionTypeSurrogate.serializer()) + return surrogate.type + } +} diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableEnchantment.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableEnchantment.kt index 5731dd2..5fd76d7 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableEnchantment.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableEnchantment.kt @@ -1,5 +1,6 @@ package com.mineinabyss.idofront.serialization +import com.mineinabyss.idofront.util.toMCKey import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -7,6 +8,7 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import org.bukkit.NamespacedKey +import org.bukkit.Registry import org.bukkit.enchantments.Enchantment @Serializable @@ -24,8 +26,8 @@ data class SerializableEnchantment( @SerialName("Enchantment") private value class EnchantmentSurrogate(val enchant: String) { init { - require(Enchantment.getByKey(enchant.getCorrectKey()) != null) - { "Enchantment must be valid. Valid ones are ${Enchantment.values().map { it.key }}" } + require(Registry.ENCHANTMENT.get(enchant.toMCKey()) != null) + { "Enchantment must be valid. Valid ones are ${Registry.ENCHANTMENT.map { it.key }}" } } } @@ -38,9 +40,6 @@ object EnchantmentSerializer : KSerializer { override fun deserialize(decoder: Decoder): Enchantment { val surrogate = decoder.decodeSerializableValue(EnchantmentSurrogate.serializer()) - return Enchantment.getByKey(surrogate.enchant.getCorrectKey())!! + return Registry.ENCHANTMENT.get(surrogate.enchant.toMCKey())!! } } - -private fun String.getCorrectKey() = - if (":" in this) NamespacedKey.fromString(this) else NamespacedKey.minecraft(this) diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableItemStack.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableItemStack.kt index 245dc82..7dd779e 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableItemStack.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/SerializableItemStack.kt @@ -25,7 +25,7 @@ import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.KnowledgeBookMeta import org.bukkit.inventory.meta.LeatherArmorMeta import org.bukkit.inventory.meta.PotionMeta -import org.bukkit.potion.PotionData +import org.bukkit.potion.PotionType import java.util.* typealias SerializableItemStack = @Serializable(with = SerializableItemStackSerializer::class) BaseSerializableItemStack @@ -52,7 +52,7 @@ data class BaseSerializableItemStack( @EncodeDefault(NEVER) val enchantments: List? = null, @EncodeDefault(NEVER) val itemFlags: List? = null, @EncodeDefault(NEVER) val attributeModifiers: List? = null, - @EncodeDefault(NEVER) val potionData: @Serializable(with = PotionDataSerializer::class) PotionData? = null, + @EncodeDefault(NEVER) val potionType: @Serializable(with = PotionTypeSerializer::class) PotionType? = null, @EncodeDefault(NEVER) val knowledgeBookRecipes: List? = null, @EncodeDefault(NEVER) val color: @Serializable(with = ColorSerializer::class) Color? = null, @EncodeDefault(NEVER) val tag: String? = null, @@ -109,8 +109,7 @@ data class BaseSerializableItemStack( // Support for our prefab system in geary. prefab?.takeIf { Properties.PREFAB !in ignoreProperties }?.let { - encodePrefab?.invoke(applyTo, it) - ?: logWarn("Tried to use prefab tag when reading item, but no prefab provider was registered") + encodePrefab.invoke(applyTo, it) } // Modify item @@ -133,8 +132,8 @@ data class BaseSerializableItemStack( if (itemFlags?.isNotEmpty() == true && Properties.ITEM_FLAGS !in ignoreProperties) meta.addItemFlags(*itemFlags.toTypedArray()) if (color != null && Properties.COLOR !in ignoreProperties) (meta as? PotionMeta)?.setColor(color) ?: (meta as? LeatherArmorMeta)?.setColor(color) - if (potionData != null && Properties.POTION_DATA !in ignoreProperties) (meta as? PotionMeta)?.basePotionData = - potionData + if (potionType != null && Properties.POTION_TYPE !in ignoreProperties) (meta as? PotionMeta)?.basePotionType = + potionType if (enchantments != null && Properties.ENCHANTMENTS !in ignoreProperties) { enchantments.forEach { meta.addEnchant(it.enchant, it.level, true) } } @@ -166,7 +165,7 @@ data class BaseSerializableItemStack( ENCHANTMENTS, ITEM_FLAGS, ATTRIBUTE_MODIFIERS, - POTION_DATA, + POTION_TYPE, KNOWLEDGE_BOOK_RECIPES, COLOR, } @@ -203,7 +202,7 @@ fun ItemStack.toSerializable(): SerializableItemStack = with(itemMeta) { ?: emptyList()).takeIf { it.isNotEmpty() }, itemFlags = (this?.itemFlags?.toList() ?: listOf()).takeIf { it.isNotEmpty() }, attributeModifiers = attributeList.takeIf { it.isNotEmpty() }, - potionData = (this as? PotionMeta)?.basePotionData, + potionType = (this as? PotionMeta)?.basePotionType, color = (this as? PotionMeta)?.color ?: (this as? LeatherArmorMeta)?.color ) //TODO perhaps this should encode prefab too? } diff --git a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/PotionMixRecipeIngredients.kt b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/PotionMixRecipeIngredients.kt index 5e99eb2..464fd57 100644 --- a/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/PotionMixRecipeIngredients.kt +++ b/idofront-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/recipes/PotionMixRecipeIngredients.kt @@ -11,15 +11,13 @@ import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack import org.bukkit.inventory.RecipeChoice import org.bukkit.inventory.meta.PotionMeta -import org.bukkit.potion.PotionData import org.bukkit.potion.PotionType @Serializable @SerialName("potionmix") class PotionMixRecipeIngredients( private val input: SerializableItemStack = - ItemStack(Material.POTION).editItemMeta { basePotionData = PotionData(PotionType.WATER) } - .toSerializable(), + ItemStack(Material.POTION).editItemMeta { basePotionType = PotionType.WATER }.toSerializable(), private val ingredient: SerializableItemStack, ) { fun toPotionMix(key: NamespacedKey, result: ItemStack): PotionMix {