Skip to content
Open
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[versions]
kotlin = "2.1.0"
shadow = "9.0.0-beta4"
simplecloud-controller = "0.0.30-dev.16f91aa"
paper = "1.21.4-R0.1-SNAPSHOT"

simplecloud-controller = "0.0.30-dev.16f91aa"
simplecloud-plugin-api = "0.0.1-dev.e7b12c9"

cloud-core = "2.0.0"
cloud-commands = "2.0.0-beta.10"
cloud-confirmation-processors = "1.0.0-rc.1"
Expand All @@ -27,6 +29,7 @@ cloud-paper = { module = "org.incendo:cloud-paper", version.ref = "cloud-command
cloud-processors-confirmation = { module = "org.incendo:cloud-processors-confirmation", version.ref = "cloud-confirmation-processors" }

simplecloud-controller-api = { module = "app.simplecloud.controller:controller-api", version.ref = "simplecloud-controller" }
simplecloud-plugin-api = { module = "app.simplecloud.plugin:plugin-shared", version.ref = "simplecloud-plugin-api" }

coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" }
coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutine" }
Expand All @@ -39,6 +42,7 @@ cloud-core = ["cloud-core", "cloud-kotlin-coroutines", "cloud-kotlin-extensions"
cloud-paper = ["cloud-paper", "cloud-minecraft-extras", "cloud-processors-confirmation"]
coroutine = ["coroutines-core", "coroutines-android"]
adventure = ["adventure", "adventure-text-minimessage"]
simplecloud = ["simplecloud-controller-api", "simplecloud-plugin-api"]

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.simplecloud.plugin.sign.paper

import app.simplecloud.plugin.sign.paper.dispatcher.PaperPlatformDispatcher
import app.simplecloud.plugin.sign.shared.command.SignStateManager
import app.simplecloud.plugin.sign.shared.config.location.SignLocation
import app.simplecloud.plugin.sign.shared.config.location.SignLocationConfig
import kotlinx.coroutines.withContext
import net.kyori.adventure.text.Component
import org.bukkit.Location
Expand Down Expand Up @@ -32,7 +32,7 @@ class PaperSignStateManager(
}
}

override suspend fun updateSign(location: SignLocation, lines: List<Component>) {
override suspend fun updateSign(location: SignLocationConfig, lines: List<Component>) {
withContext(dispatcher.getDispatcher()) {
val mappedLocation = bootstrap.signManager.map(location)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package app.simplecloud.plugin.sign.paper

import app.simplecloud.controller.api.ControllerApi
import app.simplecloud.plugin.sign.paper.dispatcher.PaperPlatformDispatcher
import app.simplecloud.plugin.sign.paper.rule.PaperRuleRegistry
import app.simplecloud.plugin.sign.paper.rule.PlayerRuleContext
import app.simplecloud.plugin.sign.paper.sender.PaperCommandSender
import app.simplecloud.plugin.sign.paper.sender.PaperCommandSenderMapper
import app.simplecloud.plugin.sign.paper.service.PaperSignService
import app.simplecloud.plugin.sign.shared.CloudSign
import app.simplecloud.plugin.sign.shared.SignManager
import app.simplecloud.plugin.sign.shared.command.SignCommand
import app.simplecloud.plugin.sign.shared.config.layout.FrameConfig
import app.simplecloud.plugin.sign.shared.rule.impl.RuleContext
import io.papermc.paper.plugin.bootstrap.BootstrapContext
import io.papermc.paper.plugin.bootstrap.PluginBootstrap
import io.papermc.paper.plugin.bootstrap.PluginProviderContext
Expand All @@ -35,6 +32,8 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
private val controllerApi = ControllerApi.createCoroutineApi()
private val miniMessage = MiniMessage.miniMessage()

private var isEnabled = false

lateinit var signManager: SignManager<Location>
private set
lateinit var commandManager: PaperCommandManager.Bootstrapped<PaperCommandSender>
Expand All @@ -48,6 +47,8 @@ class PaperSignsPluginBootstrap : PluginBootstrap {

override fun bootstrap(context: BootstrapContext) {
try {
isEnabled = true

initializeSignManager(context)
initializeCommandManager(context)
registerCommands()
Expand All @@ -59,12 +60,12 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
}
}


private fun initializeSignManager(context: BootstrapContext) {
signManager = SignManager(
controllerApi,
context.dataDirectory,
PaperSignService(this),
PaperRuleRegistry()
) { cloudSign, frameConfig ->
updateSign(cloudSign, frameConfig)
}
Expand All @@ -89,7 +90,9 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
}

override fun createPlugin(context: PluginProviderContext): JavaPlugin = plugin

fun disable() {
isEnabled = false
runBlocking {
try {
signCommand?.cleanup()
Expand All @@ -102,34 +105,28 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
}

private fun updateSign(cloudSign: CloudSign<Location>, frameConfig: FrameConfig) {
if (!isEnabled || !plugin.isEnabled) {
logger.debug("Skipping sign update - plugin is disabled")
return
}

val location = cloudSign.location
plugin.server.scheduler.runTask(plugin, Runnable {
try {
val sign = location.block.state as? Sign ?: return@Runnable

val onlinePlayers = plugin.server.onlinePlayers

onlinePlayers.forEach { player ->
val playerRuleContext = PlayerRuleContext(
server = cloudSign.server,
serverState = cloudSign.server?.state,
player
)

updateSignLines(sign, frameConfig, cloudSign, playerRuleContext)
}

updateSignLines(sign, frameConfig, cloudSign)
} catch (e: Exception) {
logger.error("Failed to update sign at location: $location", e)
}
})
}

private fun updateSignLines(sign: Sign, frameConfig: FrameConfig, cloudSign: CloudSign<*>, context: RuleContext) {
private fun updateSignLines(sign: Sign, frameConfig: FrameConfig, cloudSign: CloudSign<*>) {
clearSignLines(sign)

frameConfig.lines.forEachIndexed { index, line ->
val resolvedLine = miniMessage.deserialize(line, *getPlaceholders(cloudSign, context).toTypedArray())
val resolvedLine = miniMessage.deserialize(line, *getPlaceholders(cloudSign).toTypedArray())
sign.getSide(Side.FRONT).line(index, resolvedLine)
sign.getSide(Side.BACK).line(index, resolvedLine)
}
Expand All @@ -143,7 +140,7 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
sign.getSide(Side.BACK).lines().replaceAll { emptyComponent }
}

private fun getPlaceholders(cloudSign: CloudSign<*>, context: RuleContext): List<TagResolver.Single> = buildList {
private fun getPlaceholders(cloudSign: CloudSign<*>): List<TagResolver.Single> = buildList {
with(cloudSign.server) {
add(Placeholder.parsed("group", this?.group ?: "unknown"))
add(Placeholder.parsed("numerical-id", this?.numericalId?.toString() ?: "0"))
Expand All @@ -157,10 +154,5 @@ class PaperSignsPluginBootstrap : PluginBootstrap {
add(Placeholder.parsed("player-count", this?.playerCount?.toString() ?: "0"))
add(Placeholder.parsed("state", this?.state?.toString() ?: "unknown"))
}

if (context is PlayerRuleContext) {
add(Placeholder.parsed("player_name", context.player.name))
add(Placeholder.parsed("player_sender", context.player.server.name))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.simplecloud.plugin.sign.paper.listener

import app.simplecloud.plugin.sign.paper.PaperSignsPlugin
import app.simplecloud.plugin.sign.paper.rule.PlayerRuleContext
import app.simplecloud.plugin.sign.shared.rule.context.impl.ServerRuleContext
import org.bukkit.block.Sign
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
Expand All @@ -22,14 +22,10 @@ data class SignListener(private val plugin: PaperSignsPlugin) : Listener {
plugin.bootstrap.signManager.getCloudSign(sign.location)?.let { cloudSign ->
event.isCancelled = true

val playerRuleContext = PlayerRuleContext(
server = cloudSign.server,
serverState = cloudSign.server?.state,
event.player
)
val serverRuleContext = ServerRuleContext(server = cloudSign.server)

cloudSign.server?.let { server ->
val serverName = plugin.bootstrap.signManager.getLayout(playerRuleContext).constructName(server)
val serverName = plugin.bootstrap.signManager.getLayout(serverRuleContext).constructName(server)
plugin.sendPlayerToServer(event.player, serverName)
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.simplecloud.plugin.sign.paper.sender

import app.simplecloud.plugin.sign.paper.PaperSignsPlugin
import app.simplecloud.plugin.sign.shared.config.location.SignLocation
import app.simplecloud.plugin.sign.shared.config.location.SignLocationConfig
import app.simplecloud.plugin.sign.shared.sender.SignCommandSender
import app.simplecloud.plugin.sign.shared.utils.SignCommandMessages
import io.papermc.paper.command.brigadier.CommandSourceStack
Expand All @@ -20,7 +20,7 @@ class PaperCommandSender(
override fun sendMessage(component: Component) =
sourceStack.sender.sendMessage(component)

override suspend fun getTargetBlock(maxDistance: Int): SignLocation? {
override suspend fun getTargetBlock(maxDistance: Int): SignLocationConfig? {
val player = sourceStack.sender as? Player ?: return null

return withContext(PaperSignsPlugin.instance.bootstrap.platformDispatcher.getDispatcher()) {
Expand All @@ -32,7 +32,7 @@ class PaperCommandSender(
return@withContext null
}

SignLocation(
SignLocationConfig(
world = targetBlock.world.name,
x = targetBlock.x.toDouble(),
y = targetBlock.y.toDouble(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import app.simplecloud.controller.api.ControllerApi
import app.simplecloud.plugin.sign.paper.PaperSignsPluginBootstrap
import app.simplecloud.plugin.sign.shared.CloudSign
import app.simplecloud.plugin.sign.shared.LocationMapper
import app.simplecloud.plugin.sign.shared.config.location.SignLocation
import app.simplecloud.plugin.sign.shared.config.location.SignLocationConfig
import app.simplecloud.plugin.sign.shared.config.rule.RuleConfig
import app.simplecloud.plugin.sign.shared.service.SignService
import org.bukkit.Location

Expand All @@ -17,13 +18,13 @@ class PaperSignService(private val bootstrap: PaperSignsPluginBootstrap) : SignS
override fun getCloudSign(location: Location): CloudSign<Location>? =
bootstrap.signManager.getCloudSign(location)

override fun getAllLocations(): List<SignLocation> =
override fun getAllLocations(): List<SignLocationConfig> =
bootstrap.signManager.getAllLocations()

override fun getAllGroupsRegistered(): List<String> =
bootstrap.signManager.getAllGroupsRegistered()

override fun getLocationsByGroup(group: String): List<SignLocation>? =
override fun getLocationsByGroup(group: String): List<SignLocationConfig>? =
bootstrap.signManager.getLocationsByGroup(group)

override fun register(group: String, location: Location) =
Expand All @@ -35,16 +36,22 @@ class PaperSignService(private val bootstrap: PaperSignsPluginBootstrap) : SignS
override fun exists(group: String): Boolean =
bootstrap.signManager.exists(group)

override fun map(location: SignLocation): Location =
override fun getAllRules(): List<RuleConfig> =
bootstrap.signManager.getAllRules()

override fun getRule(ruleName: String): RuleConfig? =
bootstrap.signManager.getRule(ruleName)

override fun map(location: SignLocationConfig): Location =
Location(
bootstrap.plugin.server.getWorld(location.world),
location.x,
location.y,
location.z
)

override fun unmap(location: Location): SignLocation =
SignLocation(
override fun unmap(location: Location): SignLocationConfig =
SignLocationConfig(
location.world.name,
location.x,
location.y,
Expand Down
2 changes: 1 addition & 1 deletion sign-shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
api(rootProject.libs.simplecloud.controller.api)
api(rootProject.libs.bundles.simplecloud)
implementation(rootProject.libs.bundles.cloud.core)
implementation(rootProject.libs.bundles.adventure)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app.simplecloud.plugin.sign.shared

import app.simplecloud.plugin.sign.shared.config.location.SignLocation
import app.simplecloud.plugin.sign.shared.config.location.SignLocationConfig

interface LocationMapper<T> {

fun map(location: SignLocation): T
fun map(location: SignLocationConfig): T

fun unmap(location: T): SignLocation
fun unmap(location: T): SignLocationConfig

}
Loading