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