Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ allprojects {
maven("https://repo.codemc.io/repository/maven-releases/") {
name = "CodeMC"
}
maven("https://repo.extendedclip.com/releases/") {
name = "PlaceholderAPI"
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions rebar/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import net.minecrell.pluginyml.paper.PaperPluginDescription
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode

plugins {
Expand Down Expand Up @@ -41,6 +42,7 @@ dependencies {

paperLibraryApi("xyz.xenondevs.invui:invui:2.0.0-beta.5")
paperLibraryApi("xyz.xenondevs.invui:invui-kotlin:2.0.0-beta.5")
compileOnly("me.clip:placeholderapi:2.12.2")
implementation("com.github.Tofaa2.EntityLib:spigot:2.4.11")
implementation("com.github.retrooper:packetevents-spigot:2.11.2")
implementation("info.debatty:java-string-similarity:2.0.0")
Expand Down Expand Up @@ -163,6 +165,13 @@ paper {
authors = listOf("Rebar team")
apiVersion = minecraftVersion
load = BukkitPluginDescription.PluginLoadOrder.STARTUP

serverDependencies {
register("PlaceholderAPI") {
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
required = false
}
}
}

tasks.withType<Jar> {
Expand Down
4 changes: 4 additions & 0 deletions rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import io.github.pylonmc.rebar.resourcepack.armor.ArmorTextureEngine
import io.github.pylonmc.rebar.util.delayTicks
import io.github.pylonmc.rebar.util.mergeGlobalConfig
import io.github.pylonmc.rebar.waila.Waila
import io.github.pylonmc.rebar.waila.WailaPlaceholders
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
import io.papermc.paper.ServerBuildInfo
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
Expand Down Expand Up @@ -258,6 +259,9 @@ object Rebar : JavaPlugin(), RebarAddon {

if (RebarConfig.WailaConfig.ENABLED) {
pm.registerEvents(Waila, this)
if (pm.getPlugin("PlaceholderAPI") != null) {
WailaPlaceholders.register()
}
}

if (RebarConfig.ArmorTextureConfig.ENABLED) {
Expand Down
46 changes: 35 additions & 11 deletions rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import net.kyori.adventure.bossbar.BossBar
import net.kyori.adventure.text.Component
import org.apache.commons.lang3.StringUtils.overlay
Comment thread
JustAHuman-xD marked this conversation as resolved.
Outdated
import org.bukkit.attribute.Attribute
import org.bukkit.block.Block
import org.bukkit.entity.Entity
Expand Down Expand Up @@ -58,23 +59,32 @@ class Waila private constructor(private val player: Player, playerConfig: Player
RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay
)

var lastText: Component? = null
private set
var lastColor: BossBar.Color? = null
private set
var lastOverlay: BossBar.Overlay? = null
private set
var lastProgress: Float? = null
private set

private var wasVisible = false;

private fun send(display: WailaDisplay) {
val color = if (display.color in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_COLORS) {
display.color
} else {
RebarConfig.WailaConfig.DEFAULT_DISPLAY.color
}
val overlay = if (display.overlay in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS) {
display.overlay
} else {
RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay
}

when (config.type) {
Type.BOSSBAR -> {
player.hideBossBar(bossBar)
val color = if (display.color in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_COLORS) {
display.color
} else {
RebarConfig.WailaConfig.DEFAULT_DISPLAY.color
}
val overlay = if (display.overlay in RebarConfig.WailaConfig.ALLOWED_BOSS_BAR_OVERLAYS) {
display.overlay
} else {
RebarConfig.WailaConfig.DEFAULT_DISPLAY.overlay
}

bossBar.name(display.text)
bossBar.color(color)
bossBar.overlay(overlay)
Expand All @@ -83,6 +93,11 @@ class Waila private constructor(private val player: Player, playerConfig: Player
}
Type.ACTIONBAR -> player.sendActionBar(display.text)
}

lastText = display.text
lastColor = color
lastOverlay = overlay
lastProgress = display.progress
wasVisible = true
}

Expand All @@ -95,6 +110,10 @@ class Waila private constructor(private val player: Player, playerConfig: Player
Type.BOSSBAR -> player.hideBossBar(bossBar)
Type.ACTIONBAR -> player.sendActionBar(Component.empty())
}
lastText = null
lastColor = null
lastOverlay = null
wasVisible = false
wasVisible = false
Comment thread
JustAHuman-xD marked this conversation as resolved.
Outdated
}

Expand Down Expand Up @@ -195,6 +214,11 @@ class Waila private constructor(private val player: Player, playerConfig: Player
private val blockOverrides = mutableMapOf<BlockPosition, (Player) -> WailaDisplay?>()
private val entityOverrides = mutableMapOf<UUID, (Player) -> WailaDisplay?>()

@JvmStatic
fun getWaila(player: Player): Waila? {
return wailas[player.uniqueId]
}

/**
* Forcibly adds a WAILA display for the given player.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.pylonmc.rebar.waila

import io.github.pylonmc.rebar.i18n.customMiniMessage
import io.github.pylonmc.rebar.util.plainText
import me.clip.placeholderapi.expansion.PlaceholderExpansion
import net.kyori.adventure.bossbar.BossBar
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player

object WailaPlaceholders : PlaceholderExpansion() {
@JvmField
val placeholders: List<String> = listOf("text", "plain_text", "color", "overlay", "progress")

override fun onRequest(player: OfflinePlayer?, params: String): String? {
if (player == null || player !is Player) return null
val waila = Waila.getWaila(player) ?: return null
return when(params) {
"text" -> waila.lastText?.let { customMiniMessage.serialize(it) } ?: ""
"plain_text" -> waila.lastText?.plainText ?: ""
"color" -> waila.lastColor?.let { BossBar.Color.NAMES.key(it) } ?: ""
"overlay" -> waila.lastOverlay?.let { BossBar.Overlay.NAMES.key(it) } ?: ""
else -> null
}
}

override fun getPlaceholders(): List<String?> = placeholders

override fun getIdentifier(): String = "rebarwaila"

override fun getAuthor(): String = "Rebar"

override fun getVersion(): String = "1.0.0"
}
Loading