From 0b5c904a3ff0f82834a4b9df5af8645d6c6cd45b Mon Sep 17 00:00:00 2001 From: MattMX Date: Sun, 7 Jul 2024 17:40:53 +0100 Subject: [PATCH] Bug fixes + tostring for placeholders --- .../caches/paperweight/taskCache/reobfJar.log | 4 ++-- .../declarative/arg/impl/SimpleArgument.kt | 3 ++- .../kotlin/com/mattmx/ktgui/papi/Placeholder.kt | 14 ++++++++++++++ api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt | 8 +++++++- .../kotlin/com/mattmx/ktgui/utils/formatting.kt | 1 + build.gradle.kts | 2 +- .../caches/paperweight/taskCache/reobfJar.log | 4 ++-- 7 files changed, 29 insertions(+), 7 deletions(-) diff --git a/api/.gradle/caches/paperweight/taskCache/reobfJar.log b/api/.gradle/caches/paperweight/taskCache/reobfJar.log index 73f8e1d..6794786 100644 --- a/api/.gradle/caches/paperweight/taskCache/reobfJar.log +++ b/api/.gradle/caches/paperweight/taskCache/reobfJar.log @@ -1,2 +1,2 @@ -Command: C:\Program Files\Java\jdk-17\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\api\build\libs\ktgui-2.4.1-dev-all.jar D:\PC\Projects\KtBukkitGui\api\build\libs\api-2.4.1.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1 -Finished after 2839.29 ms. +Command: C:\Program Files\Java\jdk-17\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\api\build\libs\ktgui-2.4.2-alpha-dev-all.jar D:\PC\Projects\KtBukkitGui\api\build\libs\api-2.4.2-alpha.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1 +Finished after 2991.53 ms. diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/SimpleArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/SimpleArgument.kt index f189aea..93394c2 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/SimpleArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/SimpleArgument.kt @@ -21,7 +21,8 @@ class SimpleArgument( context: BaseCommandContext<*>?, stringValue: String? ): T? { - stringValue ?: return null + stringValue ?: return getDefaultValue() + return if (valueFromString.isPresent) valueFromString.get()(stringValue) else null } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/papi/Placeholder.kt b/api/src/main/kotlin/com/mattmx/ktgui/papi/Placeholder.kt index 97d7d5a..b428ffb 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/papi/Placeholder.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/papi/Placeholder.kt @@ -1,12 +1,26 @@ package com.mattmx.ktgui.papi import com.mattmx.ktgui.commands.declarative.ChainCommandBuilder +import java.util.* class Placeholder( val match: ChainCommandBuilder, val supplier: (PlaceholderParseContext) -> Any? ) { + var description = Optional.empty() + private set var priority = 0 fun parse(context: PlaceholderParseContext) = supplier.invoke(context) + + infix fun description(desc: String?) = apply { + this.description = Optional.ofNullable(desc) + } + + override fun toString() = + "%${match.name}_${ + match.arguments.joinToString("_") { arg -> + "<${arg.name()}${if (arg.isOptional()) "?" else ""}:${arg.type()}>" + } + }%${if (description.isPresent) " - ${description.get()}" else ""}" } \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt b/api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt index bfe64d4..0fb72c2 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt @@ -1,10 +1,16 @@ package com.mattmx.ktgui.papi import com.mattmx.ktgui.commands.declarative.ChainCommandBuilder +import com.mattmx.ktgui.scheduling.sync +import com.mattmx.ktgui.scheduling.syncDelayed import org.bukkit.plugin.java.JavaPlugin inline fun JavaPlugin.placeholderExpansion(builder: PlaceholderExpansionWrapper.() -> Unit) = - PlaceholderExpansionWrapper(this).apply(builder).apply { register() } + PlaceholderExpansionWrapper(this) + .apply(builder) + .apply { + syncDelayed(2) { register() } + } fun PlaceholderExpansionWrapper.placeholder(string: String, supplier: PlaceholderParseContext.() -> Any?) = Placeholder(ChainCommandBuilder(string), supplier).apply { registerPlaceholder(this) } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/utils/formatting.kt b/api/src/main/kotlin/com/mattmx/ktgui/utils/formatting.kt index 8a89e87..0264865 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/utils/formatting.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/utils/formatting.kt @@ -1,5 +1,6 @@ package com.mattmx.ktgui.utils +import org.apache.commons.lang.time.DurationFormatUtils import java.math.RoundingMode import java.text.DecimalFormat import java.time.Duration diff --git a/build.gradle.kts b/build.gradle.kts index e907a5b..1f59660 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("io.papermc.paperweight.userdev") version "1.7.1" apply false } -val version = "2.4.1" +val version = "2.4.2-alpha" rootProject.version = version diff --git a/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log b/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log index b10cd69..0d837c4 100644 --- a/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log +++ b/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log @@ -1,2 +1,2 @@ -Command: C:\Program Files\Java\jdk-17\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\plugin\build\libs\ktgui-plugin-2.4.1-dev-all.jar D:\PC\Projects\KtBukkitGui\plugin\build\libs\plugin-unspecified.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1 -Finished after 1655.39 ms. +Command: C:\Program Files\Java\jdk-17\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\plugin\build\libs\ktgui-plugin-2.4.2-alpha-dev-all.jar D:\PC\Projects\KtBukkitGui\plugin\build\libs\plugin-unspecified.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\ff775525efc29c3503a07d1006e63e5695a742b7505cf63e157d49d32419c69f\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1 +Finished after 1810.39 ms.