diff --git a/build.gradle b/build.gradle index 23dd92a..7defb0e 100644 --- a/build.gradle +++ b/build.gradle @@ -39,12 +39,17 @@ repositories { name = "aikar-repo" url = "https://repo.aikar.co/content/groups/aikar/" } + maven { + name = "placeholderapi" + url = "https://repo.extendedclip.com/content/repositories/placeholderapi/" + } } dependencies { compileOnly "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT" - implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.21" + compileOnly "me.clip:placeholderapi:2.11.5" + implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.21" implementation "dev.dejvokep:boosted-yaml-spigot:1.4" shadow "org.bstats:bstats-bukkit:3.0.1" diff --git a/src/main/java/dev/mikchan/mcnp/motd/Creators.kt b/src/main/java/dev/mikchan/mcnp/motd/Creators.kt index 75a7959..25669ba 100644 --- a/src/main/java/dev/mikchan/mcnp/motd/Creators.kt +++ b/src/main/java/dev/mikchan/mcnp/motd/Creators.kt @@ -6,6 +6,9 @@ import dev.mikchan.mcnp.motd.config.creator.IConfigCreator import dev.mikchan.mcnp.motd.config.creator.boostedYaml.BoostedYamlConfigCreator import dev.mikchan.mcnp.motd.events.creator.EventManagerCreator import dev.mikchan.mcnp.motd.events.creator.IEventManagerCreator +import dev.mikchan.mcnp.motd.formatter.creator.FormatterCreator +import dev.mikchan.mcnp.motd.formatter.creator.IFormatterCreator +import dev.mikchan.mcnp.motd.formatter.creator.papi.PapiFormatterCreator import dev.mikchan.mcnp.motd.image.creator.IImageManagerCreator import dev.mikchan.mcnp.motd.image.creator.ImageManagerCreator import dev.mikchan.mcnp.motd.motd.creator.IMOTDManagerCreator @@ -17,4 +20,5 @@ object Creators { var imageManager: IImageManagerCreator = ImageManagerCreator() var motdManager: IMOTDManagerCreator = MOTDManagerCreator() var eventManager: IEventManagerCreator = EventManagerCreator() + var formatter: IFormatterCreator = PapiFormatterCreator(FormatterCreator()) } diff --git a/src/main/java/dev/mikchan/mcnp/motd/MOTDPlugin.kt b/src/main/java/dev/mikchan/mcnp/motd/MOTDPlugin.kt index ff95a03..d86d142 100644 --- a/src/main/java/dev/mikchan/mcnp/motd/MOTDPlugin.kt +++ b/src/main/java/dev/mikchan/mcnp/motd/MOTDPlugin.kt @@ -3,6 +3,7 @@ package dev.mikchan.mcnp.motd import dev.mikchan.mcnp.motd.commands.manager.ICommandManager import dev.mikchan.mcnp.motd.config.config.IConfig import dev.mikchan.mcnp.motd.events.manager.IEventManager +import dev.mikchan.mcnp.motd.formatter.formatter.IFormatter import dev.mikchan.mcnp.motd.image.manager.IImageManager import dev.mikchan.mcnp.motd.motd.manager.IMOTDManager import org.bstats.bukkit.Metrics @@ -17,6 +18,7 @@ class MOTDPlugin : JavaPlugin() { val config: IConfig by lazy { Creators.config.build(this) } val imageManager: IImageManager by lazy { Creators.imageManager.build(this) } val motdManager: IMOTDManager by lazy { Creators.motdManager.build(this) } + val formatter: IFormatter by lazy { Creators.formatter.build(this) } private val commandManager: ICommandManager by lazy { Creators.commandManager.build(this) } private val eventManager: IEventManager by lazy { Creators.eventManager.build(this) } diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/FormatterCreator.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/FormatterCreator.kt new file mode 100644 index 0000000..60918fa --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/FormatterCreator.kt @@ -0,0 +1,11 @@ +package dev.mikchan.mcnp.motd.formatter.creator + +import dev.mikchan.mcnp.motd.MOTDPlugin +import dev.mikchan.mcnp.motd.formatter.formatter.Formatter +import dev.mikchan.mcnp.motd.formatter.formatter.IFormatter + +internal class FormatterCreator : IFormatterCreator { + override fun build(plugin: MOTDPlugin): IFormatter { + return Formatter() + } +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/IFormatterCreator.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/IFormatterCreator.kt new file mode 100644 index 0000000..a4a025b --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/IFormatterCreator.kt @@ -0,0 +1,8 @@ +package dev.mikchan.mcnp.motd.formatter.creator + +import dev.mikchan.mcnp.motd.MOTDPlugin +import dev.mikchan.mcnp.motd.formatter.formatter.IFormatter + +interface IFormatterCreator { + fun build(plugin: MOTDPlugin): IFormatter +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/papi/PapiFormatterCreator.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/papi/PapiFormatterCreator.kt new file mode 100644 index 0000000..ffeedf9 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/creator/papi/PapiFormatterCreator.kt @@ -0,0 +1,17 @@ +package dev.mikchan.mcnp.motd.formatter.creator.papi + +import dev.mikchan.mcnp.motd.MOTDPlugin +import dev.mikchan.mcnp.motd.formatter.creator.IFormatterCreator +import dev.mikchan.mcnp.motd.formatter.formatter.IFormatter +import dev.mikchan.mcnp.motd.formatter.formatter.papi.PapiFormatter +import me.clip.placeholderapi.PlaceholderAPIPlugin + +internal class PapiFormatterCreator(private val fallback: IFormatterCreator) : IFormatterCreator { + override fun build(plugin: MOTDPlugin): IFormatter { + val papi = plugin.server.pluginManager.getPlugin("PlaceholderAPI") as? PlaceholderAPIPlugin? + return papi?.let { + plugin.logger.info("PlaceholderAPI found! Hooking in...") + PapiFormatter() + } ?: fallback.build(plugin) + } +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/Formatter.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/Formatter.kt new file mode 100644 index 0000000..2eb2738 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/Formatter.kt @@ -0,0 +1,10 @@ +package dev.mikchan.mcnp.motd.formatter.formatter + +import org.bukkit.ChatColor +import org.bukkit.OfflinePlayer + +internal class Formatter : IFormatter { + override fun format(str: String, player: OfflinePlayer?): String { + return ChatColor.translateAlternateColorCodes('&', str) + } +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/IFormatter.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/IFormatter.kt new file mode 100644 index 0000000..19311c1 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/IFormatter.kt @@ -0,0 +1,7 @@ +package dev.mikchan.mcnp.motd.formatter.formatter + +import org.bukkit.OfflinePlayer + +interface IFormatter { + fun format(str: String, player: OfflinePlayer? = null): String +} diff --git a/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/papi/PapiFormatter.kt b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/papi/PapiFormatter.kt new file mode 100644 index 0000000..c67022d --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/motd/formatter/formatter/papi/PapiFormatter.kt @@ -0,0 +1,13 @@ +package dev.mikchan.mcnp.motd.formatter.formatter.papi + +import dev.mikchan.mcnp.motd.formatter.formatter.IFormatter +import me.clip.placeholderapi.PlaceholderAPI +import org.bukkit.ChatColor +import org.bukkit.OfflinePlayer + +internal class PapiFormatter : IFormatter { + override fun format(str: String, player: OfflinePlayer?): String { + val format = PlaceholderAPI.setPlaceholders(player, str) + return ChatColor.translateAlternateColorCodes('&', format) + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2ef9c19..dbd1ff3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,6 +11,9 @@ api-version: '1.20' load: STARTUP +softdepend: + - PlaceholderAPI + permissions: mcn.motd.admin: default: op