Skip to content

Commit

Permalink
✨ show health with health bar
Browse files Browse the repository at this point in the history
  • Loading branch information
b8daniel committed Apr 26, 2022
1 parent 037a6aa commit bc67aff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ArenaCommand : ArgumentBuilder<CommandSender, ArenaCommand>() {
world.setGameRule(GameRule.DO_FIRE_TICK, false)
world.setGameRule(GameRule.DO_MOB_SPAWNING, false)
world.setGameRule(GameRule.SPECTATORS_GENERATE_CHUNKS, false)
world.setGameRule(GameRule.NATURAL_REGENERATION, false)

ctx.source.sendMessage(ThemeBuilder.themed(
"*Successfully* created or loaded world '${Paintball.gameConfig.arenaWorldName}'" +
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/de/crightgames/blxckoxymoron/paintball/game/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ object Game {
" Respawn: *${ttRespawn.inWholeSeconds + 1}*"
))

actionBarMessage.append(getHealthFormatted(pl))

pl.spigot().sendMessage(
ChatMessageType.ACTION_BAR, TextComponent(actionBarMessage.toString())
)
Expand Down Expand Up @@ -334,17 +332,6 @@ object Game {
}, 10.seconds.inWholeTicks)
}

private const val healthInfoWidth = 20

private fun getHealthFormatted(p: Player): String {
val healthWidth = ceil(PlayerHitHandler.getHealthPercent(p) * healthInfoWidth.toDouble()).toInt()
return ThemeBuilder.themed(" Leben: " +
"*" + "|".repeat(healthInfoWidth - healthWidth) + "*" +
"|".repeat(healthWidth)
)

}

private fun playerStatistics(p: Player): String {

val statistics = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SnowballHitPlayer : Listener {
}

shooter.playSound(shooter.location, Sound.ENTITY_TURTLE_EGG_HATCH, 100F, 1F)
hitPlayer.playSound(hitPlayer.location, Sound.ENTITY_TURTLE_EGG_BREAK, SoundCategory.MASTER, 100F, .8F)

val hitTeam = hitPlayer.team
if (hitTeam == null) {
Expand All @@ -61,8 +62,6 @@ class SnowballHitPlayer : Listener {

ColorReplace.replaceRadius(hitPlayer.location, shooter, team, 2.0)

hitPlayer.playSound(hitPlayer.location, Sound.ENTITY_TURTLE_EGG_BREAK, SoundCategory.MASTER, 100F, .8F)

// Scores
Scores.killsObj?.getScore(shooter.name)?.plusAssign(1)
Scores.deathsObj?.getScore(hitPlayer.name)?.plusAssign(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import de.crightgames.blxckoxymoron.paintball.Paintball.Companion.inWholeTicks
import de.crightgames.blxckoxymoron.paintball.game.config.ConfigTeam
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
Expand Down Expand Up @@ -70,28 +71,31 @@ class PlayerHitHandler(val player: Player, val team: ConfigTeam, private val ene
private val baseMeta =
(ItemStack(Material.LEATHER_BOOTS).itemMeta as LeatherArmorMeta).also {
it.isUnbreakable = true
it.addItemFlags(ItemFlag.HIDE_DYE)
it.addItemFlags(ItemFlag.HIDE_DYE, ItemFlag.HIDE_ENCHANTS)
it.addEnchant(Enchantment.BINDING_CURSE, 1, true)
}

private fun setVisibleColorLevel(level: Float) {
private fun setVisibleColorLevel(damagePercent: Float) {

player.getAttribute(Attribute.GENERIC_MAX_HEALTH)?.baseValue = Paintball.gameConfig.playerHealth * 2.0
player.health = ((1 - damagePercent) * Paintball.gameConfig.playerHealth * 2.0).coerceAtLeast(1.0)

val ownMeta = baseMeta.clone()
ownMeta.setColor(team.material.chatColor)
val enemyMeta = baseMeta.clone()
enemyMeta.setColor(enemy.material.chatColor)

player.inventory.setItem(EquipmentSlot.FEET, ItemStack(Material.LEATHER_BOOTS)
.also { it.itemMeta = if (level > 0) enemyMeta else ownMeta })
.also { it.itemMeta = if (damagePercent > 0) enemyMeta else ownMeta })

player.inventory.setItem(EquipmentSlot.LEGS, ItemStack(Material.LEATHER_LEGGINGS)
.also { it.itemMeta = if (level > 0.25) enemyMeta else ownMeta })
.also { it.itemMeta = if (damagePercent > 0.25) enemyMeta else ownMeta })

player.inventory.setItem(EquipmentSlot.CHEST, ItemStack(Material.LEATHER_CHESTPLATE)
.also { it.itemMeta = if (level > 0.5) enemyMeta else ownMeta })
.also { it.itemMeta = if (damagePercent > 0.5) enemyMeta else ownMeta })

player.inventory.setItem(EquipmentSlot.HEAD, ItemStack(Material.LEATHER_HELMET)
.also { it.itemMeta = if (level > 0.75) enemyMeta else ownMeta })
.also { it.itemMeta = if (damagePercent > 0.75) enemyMeta else ownMeta })
}

}

0 comments on commit bc67aff

Please sign in to comment.