feat: placeholder API 仮対応
This commit is contained in:
parent
f3ea947310
commit
dd3a066a47
|
|
@ -1,3 +1,5 @@
|
|||
import net.minecrell.pluginyml.paper.PaperPluginDescription
|
||||
|
||||
group = "net.hareworks"
|
||||
version = "1.0"
|
||||
|
||||
|
|
@ -9,9 +11,11 @@ plugins {
|
|||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
implementation("net.hareworks:kommand-lib:1.1")
|
||||
|
|
@ -31,6 +35,12 @@ paper {
|
|||
apiVersion = "1.21"
|
||||
description = "Invisible display entity controller library."
|
||||
authors = listOf("Hareworks")
|
||||
serverDependencies {
|
||||
register("PlaceholderAPI") {
|
||||
required = false
|
||||
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks {
|
||||
withType<Jar> {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class DisplayManager(
|
|||
ensureIdAvailable(normalized)
|
||||
val safeLocation = location.clone()
|
||||
val controller = service.createTextDisplay(safeLocation, INTERACTION_DEFAULT)
|
||||
val component = parseMiniMessage(initialContent.ifBlank { "<gray>${normalized}" })
|
||||
val component = parseMiniMessage(initialContent.ifBlank { "<gray>${normalized}" }, creator)
|
||||
controller.applyEntityUpdate { textDisplay ->
|
||||
textDisplay.text(component)
|
||||
}
|
||||
|
|
@ -98,9 +98,9 @@ class DisplayManager(
|
|||
|
||||
fun findDisplay(id: String): ManagedDisplay<*>? = displays[normalizeId(id)]
|
||||
|
||||
fun updateText(id: String, content: String): Component {
|
||||
fun updateText(id: String, content: String, playerContext: Player? = null): Component {
|
||||
val display = requireText(id)
|
||||
val component = parseMiniMessage(content)
|
||||
val component = parseMiniMessage(content, playerContext)
|
||||
display.controller.applyEntityUpdate { it.text(component) }
|
||||
display.rawContent = content
|
||||
display.component = component
|
||||
|
|
@ -253,11 +253,18 @@ class DisplayManager(
|
|||
}
|
||||
}
|
||||
|
||||
private fun parseMiniMessage(raw: String): Component =
|
||||
runCatching { miniMessage.deserialize(if (raw.isBlank()) "<gray>empty" else raw) }
|
||||
private fun parseMiniMessage(raw: String, playerContext: Player? = null): Component {
|
||||
val rawOrEmpty = if (raw.isBlank()) "<gray>empty" else raw
|
||||
val withPlaceholders = if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(playerContext, rawOrEmpty)
|
||||
} else {
|
||||
rawOrEmpty
|
||||
}
|
||||
return runCatching { miniMessage.deserialize(withPlaceholders) }
|
||||
.getOrElse { ex ->
|
||||
throw DisplayOperationException("MiniMessage parse error: ${ex.message ?: ex.javaClass.simpleName}")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val INTERACTION_DEFAULT = InteractionOptions.enabled(width = 0.8, height = 0.8)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user