From cf7ac90bd0a74d430a8d7f8bd801c98b2fc051bf Mon Sep 17 00:00:00 2001 From: Boy Date: Mon, 29 Jul 2024 17:23:49 +0200 Subject: [PATCH] fix: climbable being removed in initial packet due to caching emptyClimbableTagMap --- gradle.properties | 2 +- .../staminaclimb/StaminaClimbPlugin.kt | 14 +++----------- .../mineinabyss/staminaclimb/StaminaCommands.kt | 4 ---- .../com/mineinabyss/staminaclimb/nms/Tags.kt | 16 ++++++---------- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/gradle.properties b/gradle.properties index 693aadd..632820b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss version=0.23 -idofrontVersion=0.24.15 +idofrontVersion=0.24.16 diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt index 8a82798..43db6e3 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt @@ -1,29 +1,21 @@ package com.mineinabyss.staminaclimb +import com.github.shynixn.mccoroutine.bukkit.launch import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.modules.geary import com.mineinabyss.idofront.di.DI -import com.mineinabyss.idofront.nms.interceptClientbound import com.mineinabyss.idofront.plugin.listeners +import com.mineinabyss.idofront.time.ticks import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour.stopClimbing import com.mineinabyss.staminaclimb.modules.StaminaClimbModule import com.mineinabyss.staminaclimb.modules.StaminaPaperModule -import com.mineinabyss.staminaclimb.modules.stamina import com.mineinabyss.staminaclimb.nms.Tags -import com.mineinabyss.staminaclimb.nms.Tags.networkPayload -import com.mineinabyss.staminaclimb.nms.Tags.tags import com.mineinabyss.staminaclimb.stamina.StaminaBar import com.mineinabyss.staminaclimb.stamina.StaminaBar.registerBar import com.mineinabyss.staminaclimb.stamina.StaminaTask -import it.unimi.dsi.fastutil.ints.IntList -import net.minecraft.core.registries.Registries -import net.minecraft.network.protocol.Packet -import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket -import net.minecraft.resources.ResourceLocation -import net.minecraft.tags.BlockTags +import kotlinx.coroutines.delay import org.bukkit.Bukkit -import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin /** A reference to the StaminaClimb plugin */ diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt index 8595294..1dcffc9 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt @@ -6,13 +6,9 @@ import com.mineinabyss.idofront.messaging.info import com.mineinabyss.idofront.messaging.success import com.mineinabyss.staminaclimb.modules.stamina import com.mineinabyss.staminaclimb.nms.Tags -import net.minecraft.core.Registry -import net.minecraft.core.registries.BuiltInRegistries -import net.minecraft.tags.BlockTags import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter -import kotlin.jvm.optionals.getOrNull class StaminaCommands : IdofrontCommandExecutor(), TabCompleter { override val commands = commands(stamina.plugin) { diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt index ae0cec9..4ffc7e8 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt @@ -1,6 +1,8 @@ package com.mineinabyss.staminaclimb.nms import com.mineinabyss.idofront.nms.interceptClientbound +import com.mineinabyss.idofront.nms.networkPayload +import com.mineinabyss.idofront.nms.tags import com.mineinabyss.staminaclimb.modules.stamina import it.unimi.dsi.fastutil.ints.IntList import net.minecraft.core.registries.Registries @@ -28,18 +30,17 @@ object Tags { stamina.initialTags.putAll(packet.tags) packet.tags.entries.map { registryEntry -> - if (registryEntry.key == Registries.BLOCK) { + registryEntry.key to if (registryEntry.key == Registries.BLOCK) { val tags = registryEntry.value.tags().map { tag -> tag.key to when (tag.key) { BlockTags.CLIMBABLE.location, BlockTags.FALL_DAMAGE_RESETTING.location -> IntList.of() else -> tag.value } }.toMap() - registryEntry.setValue(tags.networkPayload()) - } - registryEntry + tags.networkPayload() + } else registryEntry.value }.forEach { - stamina.disabledClimbingTags[it.key] = it.value + stamina.disabledClimbingTags[it.first] = it.second } return@interceptClientbound packet @@ -59,9 +60,4 @@ object Tags { (player as CraftPlayer).handle.connection.send(ClientboundUpdateTagsPacket(stamina.disabledClimbingTags)) } - private val tagsField = NetworkPayload::class.java.getDeclaredField("tags").also { it.isAccessible = true } - private val payloadConstructor = NetworkPayload::class.java.declaredConstructors.first().also { it.isAccessible = true } - fun NetworkPayload.tags() = (tagsField.get(this) as Map).toMutableMap() - fun Map.networkPayload() = payloadConstructor.newInstance(this) as NetworkPayload - }