Skip to content

Commit

Permalink
Adds scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed May 5, 2024
1 parent 083c4a3 commit 3b05f7d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import kr.toxicity.healthbar.api.layout.LayoutGroup;
import kr.toxicity.healthbar.api.renderer.HealthBarRenderer;
import kr.toxicity.healthbar.api.trigger.HealthBarTriggerType;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

Expand All @@ -19,6 +20,9 @@ public interface HealthBar extends HealthBarConfiguration {
@Unmodifiable
List<LayoutGroup> groups();

@NotNull
Vector scale();

@NotNull
Set<String> applicableTypes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jetbrains.annotations.NotNull;

public record HealthBarData(
@NotNull HealthBar healthBar,
@NotNull HealthBarTrigger trigger,
@NotNull HealthBarPlayer player,
@NotNull HealthBarEntity entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kr.toxicity.healthbar.manager.ConfigManagerImpl
import kr.toxicity.healthbar.manager.LayoutManagerImpl
import kr.toxicity.healthbar.util.*
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.util.Vector
import java.util.Collections
import java.util.EnumSet
import java.util.UUID
Expand All @@ -36,6 +37,13 @@ class HealthBarImpl(
private val conditions = section.toCondition()
private val isDefault = section.getBoolean("default")
private val applicableTypes = section.getStringList("applicable-types").toSet()
private val scale = section.getConfigurationSection("scale")?.let {
Vector(
it.getDouble("x", 1.0),
it.getDouble("y", 1.0),
it.getDouble("z", 1.0)
)
} ?: Vector(1, 1, 1)

override fun path(): String = path
override fun uuid(): UUID = uuid
Expand All @@ -44,6 +52,7 @@ class HealthBarImpl(
override fun triggers(): Set<HealthBarTriggerType> = triggers
override fun condition(): HealthBarCondition = conditions
override fun isDefault(): Boolean = isDefault
override fun scale(): Vector = Vector(scale.x, scale.y, scale.z)

override fun duration(): Int = duration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class HealthBarUpdaterGroupImpl(

override fun addHealthBar(healthBar: HealthBar, trigger: HealthBarTrigger) {
updaters.computeIfAbsent(healthBar.uuid()) {
HealthBarUpdaterImpl(this, player, healthBar.createRenderer(
HealthBarData(
trigger,
player,
entity
)
))
val data = HealthBarData(
healthBar,
trigger,
player,
entity
)
HealthBarUpdaterImpl(this, data, healthBar.createRenderer(data))
}.updateTick()
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package kr.toxicity.healthbar.healthbar

import kr.toxicity.healthbar.api.healthbar.HealthBarData
import kr.toxicity.healthbar.api.healthbar.HealthBarUpdater
import kr.toxicity.healthbar.api.healthbar.HealthBarUpdaterGroup
import kr.toxicity.healthbar.api.nms.VirtualTextDisplay
import kr.toxicity.healthbar.api.player.HealthBarPlayer
import kr.toxicity.healthbar.api.renderer.HealthBarRenderer
import kr.toxicity.healthbar.util.PLUGIN

class HealthBarUpdaterImpl(
private val parent: HealthBarUpdaterGroupImpl,
player: HealthBarPlayer,
data: HealthBarData,
private val renderer: HealthBarRenderer
): HealthBarUpdater {
private val display = renderer().render().run {
PLUGIN.nms().createTextDisplay(player.player(), location, component.component.build())
PLUGIN.nms().createTextDisplay(data.player.player(), location, component.component.build()).apply {
scale(data.healthBar.scale())
}
}

override fun parent(): HealthBarUpdaterGroup = parent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
default_healthbar:
default: true
applicable-types: []
scale:
x: 0.75
y: 0.75
z: 0.75
triggers:
- damage
- look
Expand Down

0 comments on commit 3b05f7d

Please sign in to comment.