Skip to content

Commit

Permalink
Set seed for randomized boss bar color
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytm committed Oct 26, 2023
1 parent 2e1dde8 commit dbc9ea3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Partial update of chinese translations by [SnowCutieOwO](https://github.com/SnowCutieOwO)
- The default config has been updated to replace some items with custom player heads
- Holograms are now multiline by default
- The color of the indicators in the boss bar no longer change every settings change or plugin config reload

### Fixed
- Default colors for beacon beams are not applied
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.md5lukas.waypoints.pointers

import kotlin.random.Random
import net.kyori.adventure.text.Component
import org.bukkit.Location
import org.bukkit.entity.Player
Expand Down Expand Up @@ -30,5 +31,8 @@ interface Trackable {
val hologramItem: ItemStack?
get() = null

val seed: Long
get() = Random.nextLong()

fun asPredicate(): TrackablePredicate = { it === this }
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class BossBarPointer(

val data =
targetData.computeIfAbsent(trackable) {
TargetData(0f, (it as? StaticTrackable)?.beaconColor?.textColor ?: randomColor())
TargetData(0f, (it as? StaticTrackable)?.beaconColor?.textColor ?: randomColor(it.seed))
}

// Don't calculate the position of the indicator everytime in favour to make the compass update
Expand Down Expand Up @@ -131,5 +131,6 @@ internal class BossBarPointer(
return substring(modOffset, min(length, modOffset + size)) + substring(0, overhang)
}

private fun randomColor() = TextColor.color(HSVLike.hsvLike(Random.nextFloat(), 1f, 1f))
private fun randomColor(seed: Long) =
TextColor.color(HSVLike.hsvLike(Random(seed).nextFloat(), 1f, 1f))
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class PlayerTrackable(private val plugin: WaypointsPlugin, val player: Player) :
}
}

override val seed: Long
get() = player.uniqueId.mostSignificantBits

override fun equals(other: Any?): Boolean {
return player == (other as? PlayerTrackable)?.player
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.md5lukas.waypoints.pointers

import de.md5lukas.waypoints.WaypointsPlugin
import de.md5lukas.waypoints.util.getResolvers
import kotlin.random.Random
import org.bukkit.Location
import org.bukkit.entity.Player

Expand All @@ -11,6 +12,8 @@ class TemporaryWaypointTrackable(
override val beaconColor: BeaconColor? = null,
) : StaticTrackable {

override val seed: Long = Random.nextLong()

override fun getHologramText(player: Player, translatedTarget: Location) =
plugin.apiExtensions.run {
plugin.translations.POINTERS_HOLOGRAM_TEMPORARY.withReplacements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class WaypointTrackable(private val plugin: WaypointsPlugin, val waypoint: Waypo

override val hologramItem = plugin.apiExtensions.run { waypoint.getIconStack() }

override val seed: Long
get() = waypoint.id.mostSignificantBits

override fun equals(other: Any?): Boolean {
return waypoint == (other as? WaypointTrackable)?.waypoint
}
Expand Down

0 comments on commit dbc9ea3

Please sign in to comment.