Skip to content

Commit

Permalink
Bug fixes + tostring for placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Jul 7, 2024
1 parent 382da33 commit 0b5c904
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/.gradle/caches/paperweight/taskCache/reobfJar.log
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class SimpleArgument<T : Any>(
context: BaseCommandContext<*>?,
stringValue: String?
): T? {
stringValue ?: return null
stringValue ?: return getDefaultValue()

return if (valueFromString.isPresent) valueFromString.get()(stringValue) else null
}

Expand Down
14 changes: 14 additions & 0 deletions api/src/main/kotlin/com/mattmx/ktgui/papi/Placeholder.kt
Original file line number Diff line number Diff line change
@@ -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<String>()
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 ""}"
}
8 changes: 7 additions & 1 deletion api/src/main/kotlin/com/mattmx/ktgui/papi/dsl.kt
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down
1 change: 1 addition & 0 deletions api/src/main/kotlin/com/mattmx/ktgui/utils/formatting.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions plugin/.gradle/caches/paperweight/taskCache/reobfJar.log
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 0b5c904

Please sign in to comment.