diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/PlayerWailaConfigPersistentDataType.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/PlayerWailaConfigPersistentDataType.kt index 7fd7cadf4..333a2bab0 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/PlayerWailaConfigPersistentDataType.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/PlayerWailaConfigPersistentDataType.kt @@ -1,7 +1,9 @@ package io.github.pylonmc.rebar.datatypes +import io.github.pylonmc.rebar.config.RebarConfig import io.github.pylonmc.rebar.util.rebarKey import io.github.pylonmc.rebar.waila.PlayerWailaConfig +import net.kyori.adventure.bossbar.BossBar import org.bukkit.persistence.PersistentDataAdapterContext import org.bukkit.persistence.PersistentDataContainer import org.bukkit.persistence.PersistentDataType @@ -10,6 +12,8 @@ object PlayerWailaConfigPersistentDataType : PersistentDataType = PersistentDataContainer::class.java @@ -22,7 +26,9 @@ object PlayerWailaConfigPersistentDataType : PersistentDataType 1) { + addSetting( + CyclePlayerSettingButton( + rebarKey("cycle-waila-boss-bar-color"), + RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_COLORS.toList(), + identifier = { color -> color.name.lowercase() }, + getter = { player -> player.wailaConfig.bossbarColor }, + setter = { player, color -> player.wailaConfig.bossbarColor = color }, + decorator = { player, color -> + ItemStackBuilder.Companion.of(RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM).get( + NamespacedKey.minecraft(color.name.lowercase() + "_wool"))!!) + .addCustomModelDataString("waila_boss_bar_color=${color.name.lowercase()}") + .build() + } + ) + ) + } + if (RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS.size > 1) { + addSetting( + CyclePlayerSettingButton( + rebarKey("cycle-waila-boss-bar-overlay"), + RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS.toList(), + identifier = { overlay -> overlay.name.lowercase() }, + getter = { player -> player.wailaConfig.bossbarOverlay }, + setter = { player, overlay -> player.wailaConfig.bossbarOverlay = overlay }, + decorator = { player, overlay -> + ItemStackBuilder.Companion.of(Material.NOTE_BLOCK) + .addCustomModelDataString("waila_boss_bar_overlay=${overlay.name.lowercase()}") + .build() + } + ) + ) + } } } \ No newline at end of file diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt index 7836a8924..a661bc8de 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt @@ -29,6 +29,7 @@ import org.bukkit.attribute.AttributeModifier import org.bukkit.block.BlockType import org.bukkit.inventory.EquipmentSlotGroup import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.ItemType import org.bukkit.inventory.meta.ItemMeta import org.bukkit.persistence.PersistentDataContainer import org.jetbrains.annotations.ApiStatus @@ -388,6 +389,11 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro return of(ItemStack(material)) } + @JvmStatic + fun of(itemType: ItemType): ItemStackBuilder { + return of(itemType.createItemStack()) + } + /** * Creates a new [ItemStack] for a GUI item, sets its pdc key and adds * a custom model data string for resource packs. diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/PlayerWailaConfig.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/PlayerWailaConfig.kt index d8de4651d..154f5bb9e 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/PlayerWailaConfig.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/PlayerWailaConfig.kt @@ -2,6 +2,7 @@ package io.github.pylonmc.rebar.waila import io.github.pylonmc.rebar.config.RebarConfig import io.github.pylonmc.rebar.waila.Waila.Companion.wailaConfig +import net.kyori.adventure.bossbar.BossBar import org.bukkit.entity.Player class PlayerWailaConfig { @@ -25,11 +26,25 @@ class PlayerWailaConfig { player?.wailaConfig = this } + var bossbarColor: BossBar.Color = RebarConfig.WailaConfig.DEFAULT_DISPLAY.color + set(value) { + field = value + player?.wailaConfig = this + } + + var bossbarOverlay: BossBar.Overlay = RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay + set(value) { + field = value + player?.wailaConfig = this + } + constructor() - constructor(enabled: Boolean, vanillaWailaEnabled: Boolean, type: Waila.Type) { + constructor(enabled: Boolean, vanillaWailaEnabled: Boolean, type: Waila.Type, bossbarColor: BossBar.Color, bossbarOverlay: BossBar.Overlay) { this.enabled = enabled this.vanillaWailaEnabled = vanillaWailaEnabled this.type = type + this.bossbarColor = bossbarColor + this.bossbarOverlay = bossbarOverlay } } \ No newline at end of file diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt index 182137c92..74001320c 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt @@ -54,21 +54,21 @@ class Waila private constructor(private val player: Player, playerConfig: Player private val bossBar = BossBar.bossBar( Component.empty(), RebarConfig.WailaConfig.DEFAULT_DISPLAY.progress, - RebarConfig.WailaConfig.DEFAULT_DISPLAY.color, - RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay + playerConfig.bossbarColor, + playerConfig.bossbarOverlay ) private fun send(display: WailaDisplay) { when (config.type) { Type.BOSSBAR -> { player.hideBossBar(bossBar) - val color = if (display.color in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_COLORS) { - display.color + val color = if (config.bossbarColor in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_COLORS) { + config.bossbarColor } else { RebarConfig.WailaConfig.DEFAULT_DISPLAY.color } - val overlay = if (display.overlay in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS) { - display.overlay + val overlay = if (config.bossbarOverlay in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS) { + config.bossbarOverlay } else { RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay } diff --git a/rebar/src/main/resources/lang/en.yml b/rebar/src/main/resources/lang/en.yml index 04562b120..708e51193 100644 --- a/rebar/src/main/resources/lang/en.yml +++ b/rebar/src/main/resources/lang/en.yml @@ -201,6 +201,56 @@ guide: Whether your WAILA is displayed as an actionbar or bossbar Bossbar - at the top of your screen Actionbar - at the bottom of your screen + cycle-waila-boss-bar-color: + pink: + name: "Boss bar color: Pink (Click to cycle)" + lore: |- + The color of your boss bar WAILA + blue: + name: "Boss bar color: Blue (Click to cycle)" + lore: |- + The color of your boss bar WAILA + red: + name: "Boss bar color: Red (Click to cycle)" + lore: |- + The color of your boss bar WAILA + green: + name: "Boss bar color: Green (Click to cycle)" + lore: |- + The color of your boss bar WAILA + yellow: + name: "Boss bar color: Yellow (Click to cycle)" + lore: |- + The color of your boss bar WAILA + purple: + name: "Boss bar color: Purple (Click to cycle)" + lore: |- + The color of your boss bar WAILA + white: + name: "Boss bar color: White (Click to cycle)" + lore: |- + The color of your boss bar WAILA + cycle-waila-boss-bar-overlay: + progress: + name: "Boss bar overlay: Progress (Click to cycle)" + lore: |- + The overlay of your boss bar WAILA + notched_6: + name: "Boss bar overlay: Notched 6 (Click to cycle)" + lore: |- + The overlay of your boss bar WAILA + notched_10: + name: "Boss bar overlay: Notched 10 (Click to cycle)" + lore: |- + The overlay of your boss bar WAILA + notched_12: + name: "Boss bar overlay: Notched 12 (Click to cycle)" + lore: |- + The overlay of your boss bar WAILA + notched_20: + name: "Boss bar overlay: Notched 20 (Click to cycle)" + lore: |- + The overlay of your boss bar WAILA toggle-block-culling: enabled: name: "Block culling: Enabled (Click to toggle)"