Skip to content

Commit

Permalink
fix: climb being disabled not increasing fall-distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 24, 2024
1 parent d18c12a commit e9411fd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ 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
val Player.isInClimbableBlock get() = location.block.type in Tag.CLIMBABLE.values
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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
Expand All @@ -23,7 +22,6 @@ 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
Expand All @@ -47,21 +45,16 @@ object ClimbBehaviour : Listener {
private val climbableMap = mutableMapOf<UUID, Float>()
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
fun PlayerMoveEvent.onScaleDownClimbable() {
if (!hasExplicitlyChangedBlock() || !player.isInClimbable) return
if (!hasExplicitlyChangedBlock() || !player.isInClimbableBlock) return

val block = player.location.block
val increase = if (block.type == Material.SCAFFOLDING || !player.uniqueId.canClimb) 1 else 0
val increase = if (block.type == Material.SCAFFOLDING || !player.climbEnabled || !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
Expand Down
83 changes: 44 additions & 39 deletions src/main/kotlin/com/mineinabyss/staminaclimb/stamina/StaminaTask.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.mineinabyss.staminaclimb.stamina

import com.mineinabyss.geary.papermc.tracking.items.inventory.toGeary
import com.mineinabyss.idofront.entities.toPlayer
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.idofront.time.inWholeTicks
import com.mineinabyss.staminaclimb.*
import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour
import com.mineinabyss.staminaclimb.modules.stamina
import net.kyori.adventure.bossbar.BossBar
import org.bukkit.Bukkit
import org.bukkit.GameMode
import org.bukkit.Tag
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
import org.bukkit.scheduler.BukkitRunnable
Expand Down Expand Up @@ -42,52 +41,58 @@ class StaminaTask : BukkitRunnable() {
//regenerate stamina for BossBar
if (!uuid.isClimbing)
bar.addProgress(
if (player.location.apply { y -= 0.0625 }.block.isSolid)
conf.staminaRegen
else if (!player.isInClimbable) conf.staminaRegenInAir else 0f
when {
player.location.clone().apply { y -= 0.0625 }.block.isSolid -> conf.staminaRegen
!player.isInClimbableBlock -> conf.staminaRegenInAir
else -> 0f
}
)

if (progress <= conf.barRed) { //Changing bar colors and effects on player depending on its progress
bar.color(BossBar.Color.RED)
bar.name(redBar)
if (uuid.isClimbing) player.stopClimbing()
when {
progress <= conf.barRed -> { //Changing bar colors and effects on player depending on its progress
bar.color(BossBar.Color.RED)
bar.name(redBar)
if (uuid.isClimbing) player.stopClimbing()

uuid.canClimb = false //If player reaches red zone, they can't climb until they get back in green zone
player.addPotionEffect(
PotionEffect(PotionEffectType.SLOW, 110, 2, false, false)
)
player.addPotionEffect(
PotionEffect(PotionEffectType.WEAKNESS, 110, 2, false, false)
)
} 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 || player.isInClimbable) && progress <= conf.barBlink2) {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed2)
timeSinceLastColorFlip += deltaTime
else {
flipColor(bar)
timeSinceLastColorFlip = 0
uuid.canClimb =
false //If player reaches red zone, they can't climb until they get back in green zone
player.addPotionEffect(PotionEffect(PotionEffectType.SLOW, 110, 2, false, false))
player.addPotionEffect(PotionEffect(PotionEffectType.WEAKNESS, 110, 2, false, false))
}
} else if ((uuid.isClimbing || player.isInClimbable) && progress <= conf.barBlink1) {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed1)
timeSinceLastColorFlip += deltaTime
else {
flipColor(bar)
timeSinceLastColorFlip = 0

progress < 1 && !uuid.canClimb -> bar.color(BossBar.Color.RED) //Keep Stamina Bar red even in yellow zone while it's regenerating
(uuid.isClimbing || player.isInClimbableBlock) && progress <= conf.barBlink2 -> {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed2)
timeSinceLastColorFlip += deltaTime
else {
flipColor(bar)
timeSinceLastColorFlip = 0
}
}

(uuid.isClimbing || player.isInClimbableBlock) && progress <= conf.barBlink1 -> {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed1)
timeSinceLastColorFlip += deltaTime
else {
flipColor(bar)
timeSinceLastColorFlip = 0
}
}

else -> {
bar.color(conf.baseBarColor)
bar.name(baseBar)
uuid.canClimb = true
}
} else {
bar.color(conf.baseBarColor)
bar.name(baseBar)
uuid.canClimb = true
}
}

ClimbBehaviour.isClimbing.entries.forEach { (uuid, isClimbing) ->
val player = Bukkit.getPlayer(uuid) ?: ClimbBehaviour.isClimbing.remove(uuid).let { return }
val player = uuid.toPlayer() ?: ClimbBehaviour.isClimbing.remove(uuid).let { return }
//if climbing in creative, stop climbing but keep flight
if (player.gameMode == GameMode.CREATIVE) {
player.stopClimbing()
Expand Down

0 comments on commit e9411fd

Please sign in to comment.