diff --git a/build.gradle.kts b/build.gradle.kts index 6c152ad..acafebc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,7 @@ import java.time.Instant plugins { kotlin("jvm") version "2.4.10" id("com.gradleup.shadow") version "9.6.1" + id("xyz.jpenilla.run-paper") version "3.1.0" } val generateGitProperties by tasks.registering { @@ -76,6 +77,10 @@ dependencies { compileOnly("com.mysql:mysql-connector-j:9.7.0") compileOnly("org.xerial:sqlite-jdbc:3.53.2.0") compileOnly("com.google.code.gson:gson:2.10.1") + compileOnly(platform("net.kyori:adventure-bom:4.26.1")) + compileOnly("net.kyori:adventure-api") + compileOnly("net.kyori:adventure-text-minimessage") + compileOnly("net.kyori:adventure-platform-bukkit:4.4.1") compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") @@ -87,55 +92,65 @@ kotlin { jvmToolchain(21) } -tasks.processResources { - dependsOn(generateGitProperties) - - val props = mapOf( - "name" to project.name, - "version" to project.version.toString(), - "gitCommit" to gitCommitShort, - ) - inputs.properties(props) - filesMatching("plugin.yml") { - expand(props) +tasks { + processResources { + dependsOn(generateGitProperties) + + val props = mapOf( + "name" to project.name, + "version" to project.version.toString(), + "gitCommit" to gitCommitShort, + ) + inputs.properties(props) + filesMatching("plugin.yml") { + expand(props) + } } -} -tasks.shadowJar { - archiveClassifier.set("") - archiveFileName.set("${project.name}-${project.version}+${gitCommitShort}.jar") + shadowJar { + archiveClassifier.set("") + archiveFileName.set("${project.name}-${project.version}+${gitCommitShort}.jar") + + dependencies { + include(dependency("com.tcoded:FoliaLib")) + include(dependency("org.bstats:bstats-bukkit")) + include(dependency("org.bstats:bstats-base")) + } - dependencies { - include(dependency("com.tcoded:FoliaLib")) - include(dependency("org.bstats:bstats-bukkit")) - include(dependency("org.bstats:bstats-base")) + relocate("com.tcoded.folialib", "tech.qhuyy.insureinv.libs.folialib") + relocate("org.bstats", "tech.qhuyy.insureinv.libs.bstats") + + exclude("META-INF/*.SF") + exclude("META-INF/*.DSA") + exclude("META-INF/*.RSA") + exclude("META-INF/MANIFEST.MF") + exclude("META-INF/NOTICE*") + exclude("META-INF/versions/**") + exclude("META-INF/maven/**") + exclude("META-INF/proguard/**") } - relocate("com.tcoded.folialib", "dev.hqng.insureinv.libs.folialib") - relocate("org.bstats", "dev.hqng.insureinv.libs.bstats") - - exclude("META-INF/*.SF") - exclude("META-INF/*.DSA") - exclude("META-INF/*.RSA") - exclude("META-INF/MANIFEST.MF") - exclude("META-INF/NOTICE*") - exclude("META-INF/versions/**") - exclude("META-INF/maven/**") - exclude("META-INF/proguard/**") -} + build { + dependsOn(shadowJar) + } -tasks.build { - dependsOn(tasks.shadowJar) -} + runServer { + minecraftVersion("1.21.11") + jvmArgs("-Xmx2G", "-Xms2G", "-XX:+UseG1GC", "-Dcom.mojang.eula.agree=true") + systemProperty("file.encoding", "UTF-8") + workingDir(layout.projectDirectory.dir("insureinv-server")) + args("--nogui") + } -tasks.register("printGitInfo") { - group = "help" - description = "Prints current git information" - doLast { - file(layout.buildDirectory.file("generated/resources/git/git.properties").get().asFile) - .takeIf { it.exists() } - ?.readLines() - ?.forEach { println(it) } - ?: println("Git properties not generated yet. Run 'build' first.") + register("printGitInfo") { + group = "help" + description = "Prints current git information" + doLast { + file(layout.buildDirectory.file("generated/resources/git/git.properties").get().asFile) + .takeIf { it.exists() } + ?.readLines() + ?.forEach { println(it) } + ?: println("Git properties not generated yet. Run 'build' first.") + } } } diff --git a/gradle.properties b/gradle.properties index a17efa0..9c60f20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -group=dev.hqng.insureinv +group=tech.qhuyy.insureinv version=1.3.5 kotlinVersion=2.4.10 coroutinesVersion=1.11.0 diff --git a/src/main/kotlin/tech/qhuyy/insureinv/InsureInv.kt b/src/main/kotlin/tech/qhuyy/insureinv/InsureInv.kt index 6bc5662..3d8a599 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/InsureInv.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/InsureInv.kt @@ -1,7 +1,12 @@ package tech.qhuyy.insureinv import com.tcoded.folialib.FoliaLib +import net.kyori.adventure.audience.Audience +import net.kyori.adventure.platform.bukkit.BukkitAudiences +import net.kyori.adventure.text.minimessage.MiniMessage import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin import tech.qhuyy.insureinv.command.InsureInvCommand import tech.qhuyy.insureinv.economy.EconomyManager @@ -17,6 +22,8 @@ private const val PLUGIN_ID: Int = 29775 open class InsureInv : JavaPlugin() { + lateinit var audienceBukkit: BukkitAudiences + private set lateinit var serverSoftware: ServerSoftware private set lateinit var pluginBuildInfo: PluginBuildInfo @@ -33,30 +40,31 @@ open class InsureInv : JavaPlugin() { private set lateinit var storageManager: StorageManager private set + @Suppress("DEPRECATION") + val pluginVersion: String get() = description.version override fun onEnable() { foliaLib = FoliaLib(this) serverSoftware = ServerSoftware.detectServerSoftware(foliaLib) if (serverSoftware in setOf( - ServerSoftware.UNKNOWN, - ServerSoftware.SPIGOT + ServerSoftware.UNKNOWN ) ) { logger.severe("═══════════════════════════════════════════════════════════════") - logger.severe("InsureInv requires Paper or Folia to run ( including forks ).") - logger.severe("Spigot, non-bukkit and other server software are not supported.") + logger.severe("InsureInv requires Paper, Spigot or Folia to run ( including forks ).") + logger.severe("Non-bukkit and other server software are not supported.") logger.severe("Please upgrade to Paper: https://papermc.io/downloads/paper") logger.severe("═══════════════════════════════════════════════════════════════") server.pluginManager.disablePlugin(this) return } - + audienceBukkit = BukkitAudiences.create(this) pluginBuildInfo = PluginBuildInfo(this) if (foliaLib.isFolia) { logger.info("Running on Folia - region-safe scheduling enabled") } else { - logger.info("Running on Paper - standard scheduling enabled") + logger.info("Running on Spigot/Paper - standard scheduling enabled") } configManager = ConfigManager(this) @@ -82,7 +90,7 @@ open class InsureInv : JavaPlugin() { registerCommands() registerEvents() - logger.info("InsureInv v${this.pluginMeta.version} enabled successfully! Have Fun :D") + logger.info("InsureInv v$pluginVersion enabled successfully! Have Fun :D") sendStartupLog() } @@ -91,6 +99,10 @@ open class InsureInv : JavaPlugin() { storageManager.shutdown() } + if(::audienceBukkit.isInitialized) { + audienceBukkit.close() + } + logger.info("InsureInv disabled.") } @@ -100,7 +112,8 @@ open class InsureInv : JavaPlugin() { configManager, storageManager, economyManager, - messageManager + messageManager, + audienceBukkit ) getCommand("insureinv")?.apply { @@ -122,16 +135,16 @@ open class InsureInv : JavaPlugin() { private fun sendStartupLog() { listOf( "", - " &b${pluginBuildInfo.getPluginName(true)} &7ᴠ${pluginBuildInfo.buildVersion}", - " &8--------------------------------------", - " &cɪɴꜰᴏʀᴍᴀᴛɪᴏɴ", - "&7 • &fɴᴀᴍᴇ: &b${pluginBuildInfo.getPluginName(true)}", - "&7 • &fᴀᴜᴛʜᴏʀ: &bꞯʜᴜʏʏ", - " &8--------------------------------------", + " ${pluginBuildInfo.getPluginName(true)} ᴠ${pluginBuildInfo.buildVersion}", + " --------------------------------------", + " ɪɴꜰᴏʀᴍᴀᴛɪᴏɴ", + " • ɴᴀᴍᴇ: ${pluginBuildInfo.getPluginName(true)}", + " • ᴀᴜᴛʜᴏʀ: birri", + " --------------------------------------", "" ).forEach { - server.consoleSender.sendMessage( - LegacyComponentSerializer.legacyAmpersand().deserialize(it) + audienceBukkit.console().sendMessage( + MiniMessage.miniMessage().deserialize(it) ) } } diff --git a/src/main/kotlin/tech/qhuyy/insureinv/command/CommandContext.kt b/src/main/kotlin/tech/qhuyy/insureinv/command/CommandContext.kt index 5303842..9ab14bf 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/command/CommandContext.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/command/CommandContext.kt @@ -1,16 +1,23 @@ package tech.qhuyy.insureinv.command +import net.kyori.adventure.platform.bukkit.BukkitAudiences import org.bukkit.command.CommandSender import org.bukkit.entity.Player +import tech.qhuyy.insureinv.InsureInv +import tech.qhuyy.insureinv.economy.EconomyManager +import tech.qhuyy.insureinv.managers.ConfigManager +import tech.qhuyy.insureinv.managers.MessageManager +import tech.qhuyy.insureinv.storages.StorageManager data class CommandContext( val sender: CommandSender, val args: Array, - val plugin: tech.qhuyy.insureinv.InsureInv, - val configManager: tech.qhuyy.insureinv.managers.ConfigManager, - val storageManager: tech.qhuyy.insureinv.storages.StorageManager, - val economyManager: tech.qhuyy.insureinv.economy.EconomyManager, - val messageManager: tech.qhuyy.insureinv.managers.MessageManager + val plugin: InsureInv, + val configManager: ConfigManager, + val storageManager: StorageManager, + val economyManager: EconomyManager, + val messageManager: MessageManager, + val audienceBukkit: BukkitAudiences ) { val player: Player? get() = sender as? Player diff --git a/src/main/kotlin/tech/qhuyy/insureinv/command/InsureInvCommand.kt b/src/main/kotlin/tech/qhuyy/insureinv/command/InsureInvCommand.kt index c990ee8..6b79a47 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/command/InsureInvCommand.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/command/InsureInvCommand.kt @@ -1,5 +1,6 @@ package tech.qhuyy.insureinv.command +import net.kyori.adventure.platform.bukkit.BukkitAudiences import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender @@ -17,7 +18,8 @@ class InsureInvCommand( private val configManager: ConfigManager, private val storageManager: StorageManager, private val economyManager: EconomyManager, - private val messageManager: MessageManager + private val messageManager: MessageManager, + private val audienceBukkit: BukkitAudiences ) : CommandExecutor, TabCompleter { private val subcommands: Map = buildMap { @@ -68,7 +70,8 @@ class InsureInvCommand( configManager = configManager, storageManager = storageManager, economyManager = economyManager, - messageManager = messageManager + messageManager = messageManager, + audienceBukkit ) subcommand.execute(context) diff --git a/src/main/kotlin/tech/qhuyy/insureinv/command/subcommands/VersionCommand.kt b/src/main/kotlin/tech/qhuyy/insureinv/command/subcommands/VersionCommand.kt index 2d4a533..6463301 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/command/subcommands/VersionCommand.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/command/subcommands/VersionCommand.kt @@ -15,10 +15,11 @@ class VersionCommand( override val permission: String = "insureinv.admin" override val requiresPlayer: Boolean = false + @Suppress("DEPRECATION") override fun execute(context: CommandContext) { listOf( "${plugin.pluginBuildInfo.getPluginName(true)} ${i.buildVersion} ʙʏ ${ - plugin.pluginMeta.authors.joinToString( + plugin.description.authors.joinToString( " and " ) }", @@ -28,7 +29,7 @@ class VersionCommand( "├─ʙᴜɪʟᴛ: <#85C1E9>${i.buildTime}", "└─ᴅɪʀᴛʏ: <${if (i.isDirty) "red" else "green"}>${if (i.isDirty) "ᴛʀᴜᴇ" else "ғᴀʟsᴇ"}" ).forEach { - context.sender.sendMessage( + context.audienceBukkit.sender(context.sender).sendMessage( mm.deserialize(it) ) } diff --git a/src/main/kotlin/tech/qhuyy/insureinv/managers/MessageManager.kt b/src/main/kotlin/tech/qhuyy/insureinv/managers/MessageManager.kt index bec6977..243d44a 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/managers/MessageManager.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/managers/MessageManager.kt @@ -28,9 +28,7 @@ class MessageManager( private val keyMapping = buildKeyMapping() - init { - reload() - } + init { reload() } fun reload() { val messagesFile = File(plugin.dataFolder, "messages.yml") @@ -46,9 +44,13 @@ class MessageManager( if (sender is Player) { val shouldAddPrefix = configManager.isPrefixEnabled() && !noPrefixKeys.contains(i18nKey) val fullMessage = if (shouldAddPrefix) configManager.getPrefix() + rawMessage else rawMessage - sender.sendMessage(miniMessage.deserialize(fullMessage)) + plugin.audienceBukkit.player(sender).sendMessage( + miniMessage.deserialize(fullMessage) + ) } else { - sender.sendMessage(miniMessage.deserialize(rawMessage)) + plugin.audienceBukkit.sender(sender).sendMessage( + miniMessage.deserialize(rawMessage) + ) } } @@ -57,7 +59,9 @@ class MessageManager( val rawMessage = resolveMessage(i18nKey, placeholders) val shouldAddPrefix = configManager.isPrefixEnabled() && !noPrefixKeys.contains(i18nKey) val fullMessage = if (shouldAddPrefix) configManager.getPrefix() + rawMessage else rawMessage - player.sendMessage(miniMessage.deserialize(fullMessage)) + plugin.audienceBukkit.player(player).sendMessage( + miniMessage.deserialize(fullMessage) + ) } fun parseMessage(message: String): Component { @@ -76,7 +80,7 @@ class MessageManager( fun sendRawMessage(sender: CommandSender, message: String, placeholders: Map = emptyMap()) { val resolvedMessage = replacePlaceholders(message, placeholders) val component = miniMessage.deserialize(resolvedMessage) - sender.sendMessage(component) + plugin.audienceBukkit.sender(sender).sendMessage(component) } private fun resolveKey(legacyKey: String): String { diff --git a/src/main/kotlin/tech/qhuyy/insureinv/metrics/MetricsManager.kt b/src/main/kotlin/tech/qhuyy/insureinv/metrics/MetricsManager.kt index ff5c681..42947af 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/metrics/MetricsManager.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/metrics/MetricsManager.kt @@ -30,7 +30,7 @@ class MetricsManager( private fun registerPluginVersion(metrics: Metrics) { metrics.addCustomChart( - SimplePie("plugin_version") { plugin.pluginMeta.version } + SimplePie("plugin_version") { plugin.pluginVersion } ) } diff --git a/src/main/kotlin/tech/qhuyy/insureinv/utils/PluginBuildInfo.kt b/src/main/kotlin/tech/qhuyy/insureinv/utils/PluginBuildInfo.kt index 62707e8..690576c 100644 --- a/src/main/kotlin/tech/qhuyy/insureinv/utils/PluginBuildInfo.kt +++ b/src/main/kotlin/tech/qhuyy/insureinv/utils/PluginBuildInfo.kt @@ -35,7 +35,7 @@ class PluginBuildInfo(private val plugin: InsureInv) { commitTime = props.getProperty("git.commit.time")?.let { raw -> format(raw) } ?: "Unknown", branch = props.getProperty("git.branch", "Unknown"), buildTime = props.getProperty("git.build.time")?.let { raw -> format(raw) } ?: "Unknown", - buildVersion = plugin.pluginMeta.version, + buildVersion = plugin.pluginVersion, isDirty = props.getProperty("git.dirty", "false") .toBooleanStrictOrNull() ?: false ) @@ -60,7 +60,7 @@ class PluginBuildInfo(private val plugin: InsureInv) { commitTime = "Unknown", branch = "Unknown", buildTime = "Unknown", - buildVersion = plugin.pluginMeta.version, + buildVersion = plugin.pluginVersion, isDirty = false ) @@ -84,10 +84,8 @@ class PluginBuildInfo(private val plugin: InsureInv) { "isDirty" to isDirty ) + @Suppress("DEPRECATION") fun getPluginName(fancy: Boolean): String { - return if (!fancy) plugin.pluginMeta.name else "ɪɴѕᴜʀᴇɪɴᴠ" + return if (!fancy) plugin.description.name else "ɪɴѕᴜʀᴇɪɴᴠ" } - - fun toJson(): String = - toMap().entries.joinToString(prefix = "{", postfix = "}") { "\"${it.key}\":\"${it.value}\"" } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 695044e..6a91e4e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: '${version}-${gitCommit}' main: tech.qhuyy.insureinv.InsureInv api-version: '1.21' folia-supported: true -authors: [ qhuyy ] +authors: [ birri ] website: https://qhuyy.tech/ description: Inventory protection plugin with economy integration @@ -15,6 +15,9 @@ softdepend: libraries: - org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0 - com.zaxxer:HikariCP:5.1.0 + - net.kyori:adventure-api:4.26.1 + - net.kyori:adventure-text-minimessage:4.26.1 + - net.kyori:adventure-platform-bukkit:4.4.1 commands: insureinv: