diff --git a/build.gradle.kts b/build.gradle.kts index 3444207..d153b03 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,6 +14,7 @@ plugins { repositories { maven("https://repo.mineinabyss.com/snapshots") maven("https://jitpack.io") + mavenLocal() } dependencies { diff --git a/gradle.properties b/gradle.properties index 681e3ab..bf7c1d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group=com.mineinabyss -version=0.21 -idofrontVersion=0.20.6 +version=0.22 +idofrontVersion=0.21.5 diff --git a/gradle/staminaLibs.versions.toml b/gradle/staminaLibs.versions.toml index ed2b24b..5d3b395 100644 --- a/gradle/staminaLibs.versions.toml +++ b/gradle/staminaLibs.versions.toml @@ -1,6 +1,6 @@ [versions] -geary = "0.27.0" -bonehurtingjuice = "1.10.0" +geary = "0.29.0" +bonehurtingjuice = "1.10" [libraries] geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "geary" } diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt index 1def307..0468dac 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt @@ -6,6 +6,7 @@ import com.mineinabyss.staminaclimb.component.StaminaModifier import com.mineinabyss.staminaclimb.modules.stamina import com.mineinabyss.staminaclimb.stamina.StaminaBar import org.bukkit.Material +import org.bukkit.Tag import org.bukkit.entity.Player import org.bukkit.inventory.EquipmentSlot import java.util.* @@ -115,3 +116,5 @@ inline fun inCube( var Player.climbEnabled: Boolean get() = StaminaBar.climbEnabled(this) set(enable) = StaminaBar.setClimbEnabled(this, enable) + +val Player.isInClimbable get() = location.block.type in Tag.CLIMBABLE.values diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt index 6f911a3..7b81884 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt @@ -6,6 +6,7 @@ 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.tags.BlockTags import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter @@ -17,6 +18,7 @@ class StaminaCommands : IdofrontCommandExecutor(), TabCompleter { playerAction { player.climbEnabled = !player.climbEnabled if (player.climbEnabled) Tags.enableClimb(player) + else Tags.disableClimb(player) player.info("Stamina and climbing system: ${if (player.climbEnabled) "ON" else "OFF"}!") } } @@ -27,6 +29,16 @@ class StaminaCommands : IdofrontCommandExecutor(), TabCompleter { sender.success("Config has been reloaded!") } } + "tags" { + action { + stamina.emptyClimbableMap.entries.find { it.key == BlockTags.FALL_DAMAGE_RESETTING.location }?.let { + sender.info("Fall damage resetting tag: ${it.value}") + } + stamina.normalClimbableMap.entries.find { it.key == BlockTags.CLIMBABLE.location }?.let { + sender.info("Climbable tag: ${it.value}") + } + } + } } } diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/climbing/ClimbBehaviour.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/climbing/ClimbBehaviour.kt index 2dd39a8..c54f7e9 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/climbing/ClimbBehaviour.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/climbing/ClimbBehaviour.kt @@ -1,21 +1,30 @@ package com.mineinabyss.staminaclimb.climbing +import com.mineinabyss.idofront.messaging.broadcast import com.mineinabyss.staminaclimb.* import com.mineinabyss.staminaclimb.modules.stamina import com.mineinabyss.staminaclimb.stamina.StaminaBar import com.mineinabyss.staminaclimb.stamina.removeProgress +import net.minecraft.world.level.block.LadderBlock import org.bukkit.GameMode import org.bukkit.Material +import org.bukkit.Tag +import org.bukkit.block.BlockFace import org.bukkit.entity.Player import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.block.Action import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.block.BlockPlaceEvent +import org.bukkit.event.entity.EntityDamageEvent import org.bukkit.event.player.PlayerAnimationEvent import org.bukkit.event.player.PlayerInteractEvent +import org.bukkit.event.player.PlayerMoveEvent import org.bukkit.inventory.EquipmentSlot import org.bukkit.util.Vector +import org.cultofclang.bonehurtingjuice.events.BoneHurtDamageEvent +import org.cultofclang.bonehurtingjuice.hurtBones import java.util.* import java.util.concurrent.ConcurrentHashMap @@ -35,17 +44,35 @@ object ClimbBehaviour : Listener { isClimbing.remove(uuid) } + private val climbableMap = mutableMapOf() + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) + fun PlayerMoveEvent.onScaleDownClimbable() { + if (!hasExplicitlyChangedBlock() || !player.isInClimbable) return + + val block = player.location.block + val increase = if (block.type == Material.SCAFFOLDING || !player.uniqueId.canClimb) 1 else 0 + climbableMap.compute(player.uniqueId) { _, v -> (v ?: 0).toFloat() + increase } + if (block.getRelative(BlockFace.DOWN).type in Tag.CLIMBABLE.values) return + player.hurtBones(climbableMap[player.uniqueId] ?: 0f) + climbableMap.remove(player.uniqueId) + } + + @EventHandler + fun EntityDamageEvent.onClimbableDamage() { + broadcast(cause.name + ": " + isCancelled) + } + @EventHandler fun BlockPlaceEvent.onBlockPlace() { val uuid = player.uniqueId if (!player.isSneaking && uuid.isClimbing) isCancelled = true - if (cooldown.containsKey(uuid)) uuid.climbCooldown = conf.walljumpCooldown + if (uuid in cooldown) uuid.climbCooldown = conf.walljumpCooldown } @EventHandler fun BlockBreakEvent.onBlockBreak() { val uuid = player.uniqueId - if (cooldown.containsKey(uuid)) uuid.climbCooldown = conf.walljumpCooldown + if (uuid in cooldown) uuid.climbCooldown = conf.walljumpCooldown } @EventHandler @@ -54,7 +81,7 @@ object ClimbBehaviour : Listener { val velocity = player.velocity //if sneaking, don't climb, but do climb if player is also falling - if (allowClimb(player) && rightClicked() && !isClimbing.containsKey(uuid)) { + if (allowClimb(player) && rightClicked() && uuid !in isClimbing) { val bossBar = StaminaBar.registeredBars[uuid] ?: return //remove stamina progress based on how long the player's already fallen bossBar.removeProgress(player.fallDistance / 15f) @@ -85,7 +112,7 @@ object ClimbBehaviour : Listener { val uuid = player.uniqueId //when isClimbing is false, it means player can still do the jump, once it's actually removed from the hashmap, that's when we can't climb //don't even ask ok - if (allowClimb(player) && isClimbing.containsKey(uuid)) { + if (allowClimb(player) && uuid in isClimbing) { //set a cooldown for player not to be able to wall jump right away uuid.climbCooldown = conf.walljumpCooldown val bossBar = StaminaBar.registeredBars[uuid] ?: return diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt index a32d89b..e6fc713 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt @@ -6,10 +6,11 @@ import it.unimi.dsi.fastutil.ints.IntList import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.core.registries.Registries import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket +import net.minecraft.network.protocol.game.ServerboundEntityTagQuery import net.minecraft.resources.ResourceLocation import net.minecraft.tags.BlockTags import net.minecraft.tags.TagNetworkSerialization.NetworkPayload -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer import org.bukkit.entity.Player object Tags { @@ -23,18 +24,27 @@ object Tags { fun enableClimb(player: Player) { if (player !in disabledPlayers) return disabledPlayers.remove(player) - val packet = - ClientboundUpdateTagsPacket(mapOf(Registries.BLOCK to createPayload(stamina.normalClimbableMap))) - (player as CraftPlayer).handle.connection.send(packet) + (player as CraftPlayer).handle.connection.send(updateTagPacket(true)) } fun disableClimb(player: Player) { if (player in disabledPlayers) return disabledPlayers.add(player) - val packet = - ClientboundUpdateTagsPacket(mapOf(Registries.BLOCK to createPayload(stamina.emptyClimbableMap))) - (player as CraftPlayer).handle.connection.send(packet) + (player as CraftPlayer).handle.connection.send(updateTagPacket(false)) + } + + private fun updateTagPacket(enable: Boolean): ClientboundUpdateTagsPacket { + return ClientboundUpdateTagsPacket( + mapOf( + Registries.BLOCK to createPayload( + when (enable) { + true -> stamina.normalClimbableMap + false -> stamina.emptyClimbableMap + } + ) + ) + ) } fun emptyFallDamageResetTag(player: Player): Map { @@ -60,9 +70,10 @@ object Tags { return BuiltInRegistries.BLOCK.tags.map { pair -> pair.first.location to IntArrayList(pair.second.size()).apply { // If the tag is CLIMBABLE, don't add any blocks to the list - if (pair.first.location == BlockTags.CLIMBABLE.location) return@apply - if (pair.first.location == BlockTags.FALL_DAMAGE_RESETTING.location) return@apply - pair.second.forEach { add(BuiltInRegistries.BLOCK.getId(it.value())) } + when (pair.first.location) { + BlockTags.CLIMBABLE.location, BlockTags.FALL_DAMAGE_RESETTING.location -> return@apply + else -> pair.second.forEach { add(BuiltInRegistries.BLOCK.getId(it.value())) } + } } }.toList().toMap() } diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaBar.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaBar.kt index 7b8e04f..f523045 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaBar.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaBar.kt @@ -16,7 +16,7 @@ import org.bukkit.Bukkit import org.bukkit.GameMode.ADVENTURE import org.bukkit.GameMode.SURVIVAL import org.bukkit.Location -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer +import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener diff --git a/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaTask.kt b/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaTask.kt index 07a0bc7..8c449d4 100644 --- a/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaTask.kt +++ b/src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaTask.kt @@ -31,7 +31,6 @@ class StaminaTask : BukkitRunnable() { StaminaBar.forEachBar { player, uuid, bar -> val progress = bar.progress() - val onClimbable: Boolean = Tag.CLIMBABLE.isTagged(player.location.block.type) if (player.gameMode == GameMode.CREATIVE || player.gameMode == GameMode.SPECTATOR) { StaminaBar.unregisterBar(uuid) @@ -45,7 +44,7 @@ class StaminaTask : BukkitRunnable() { bar.addProgress( if (player.location.apply { y -= 0.0625 }.block.isSolid) conf.staminaRegen - else if (!onClimbable) conf.staminaRegenInAir else 0f + else if (!player.isInClimbable) conf.staminaRegenInAir else 0f ) if (progress <= conf.barRed) { //Changing bar colors and effects on player depending on its progress @@ -62,7 +61,7 @@ class StaminaTask : BukkitRunnable() { ) } else if (progress < 1 && !uuid.canClimb) { bar.color(BossBar.Color.RED) //Keep Stamina Bar red even in yellow zone while it's regenerating - } else if ((uuid.isClimbing || onClimbable) && progress <= conf.barBlink2) { + } else if ((uuid.isClimbing || player.isInClimbable) && progress <= conf.barBlink2) { val deltaTime = System.currentTimeMillis() - lastTime lastTime = System.currentTimeMillis() if (timeSinceLastColorFlip < conf.barBlinkSpeed2) @@ -71,7 +70,7 @@ class StaminaTask : BukkitRunnable() { flipColor(bar) timeSinceLastColorFlip = 0 } - } else if ((uuid.isClimbing || onClimbable) && progress <= conf.barBlink1) { + } else if ((uuid.isClimbing || player.isInClimbable) && progress <= conf.barBlink1) { val deltaTime = System.currentTimeMillis() - lastTime lastTime = System.currentTimeMillis() if (timeSinceLastColorFlip < conf.barBlinkSpeed1)