Skip to content

Commit

Permalink
placeholder expansion wrapper api complete
Browse files Browse the repository at this point in the history
Now working but likely will be changed internally
  • Loading branch information
Matt-MX committed Jul 7, 2024
1 parent 28f409a commit 1d8cf9d
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 42 deletions.
2 changes: 1 addition & 1 deletion 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 2782.23 ms.
Finished after 2640.75 ms.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ open class Argument<T : Any>(

open fun getValueOfString(
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>,
context: BaseCommandContext<*>?,
split: List<String>
): T? {
return getValueOfString(cmd, context, split.joinToString(" "))
Expand All @@ -140,8 +140,8 @@ open class Argument<T : Any>(
@JavaCompatibility
fun getValue(context: RunnableCommandContext<*>) = context.getArgumentContext<T>(name())?.getOrNull()

fun createContext(cmd: DeclarativeCommandBuilder?, context: BaseCommandContext<*>?, stringValue: String?) =
createContext(stringValue, getValueOfString(cmd, context, stringValue))
fun createContext(cmd: DeclarativeCommandBuilder?, context: BaseCommandContext<*>?, stringValue: List<String>) =
createContext(stringValue.joinToString(" "), getValueOfString(cmd, context, stringValue))

fun createContext(stringValue: String?, actualValue: Any?): ArgumentContext<T> {
return ArgumentContext(stringValue, Optional.ofNullable(actualValue as T?), this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ArgumentProcessor(

pointer++
} else {
println(command.permittedOptions)
val option = command.permittedOptions.firstOrNull {
it.chatName() == optionOrPointerId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class BooleanArgument(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): Boolean? {
return stringValue?.toBooleanStrictOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class DoubleArgument(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): Double? {
val doubleValue = stringValue?.toDoubleOrNull() ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class EnumArgument<E : Enum<E>>(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): E? {
return if (toString.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class FlagArgument(
fun chatName() = name().replace("_", "-")

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
split: List<String>
): Boolean? {
): Boolean {
// todo context should contain included flags/options
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class IntArgument(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): Int? {
val intValue = stringValue?.toIntOrNull() ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class LongArgument(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): Long? {
val longValue = stringValue?.toLongOrNull() ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class MultiChoiceArgument<T : Any>(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
) = choices()[stringValue]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class OnlinePlayerArgument(
) : Argument<Player>(name, typeName) {

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): Player? {
stringValue ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class RelativeCoordinateArgument(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
split: List<String>
): Location? {
if (split.size != 3) return null

val entity = (context.sender as Entity)
val entity = (context?.sender as Entity?)
?: return null
val location = entity.location.clone().toVector().list()

var i = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SimpleArgument<T : Any>(
}

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): T? {
stringValue ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class StringArgument(
val disallow = arrayListOf<Regex>()

override fun getValueOfString(
cmd: DeclarativeCommandBuilder,
context: BaseCommandContext<*>,
cmd: DeclarativeCommandBuilder?,
context: BaseCommandContext<*>?,
stringValue: String?
): String? {
stringValue ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ fun flag() = delegateArgument(FlagArgument(DELEGATED_ARG_NAME))
fun <T : Any> multiChoiceArgument(vararg choices: Pair<String, T>) =
delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { hashMapOf(*choices) })

fun <T : Any> multiChoiceArgument(choices: HashMap<String, T>) =
delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { choices })

fun <T : Any> multiChoiceArgument(choiceSupplier: () -> HashMap<String, T>) =
delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { choiceSupplier() })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ class PlaceholderExpansionWrapper(
else null

for (placeholder in placeholders.sortedByDescending { it.priority }) {
// todo support no identifiers (root placeholder)
val identifier = placeholder.match.name
if (paramsSplit.getOrNull(0) != identifier) continue

val argumentParser = ArgumentProcessor(emptyCommand, baseContext, paramsSplit)
val argumentParser = ArgumentProcessor(
emptyCommand,
baseContext,
paramsSplit.subList(1, paramsSplit.size)
)

var invalid = false

Expand All @@ -80,15 +85,22 @@ class PlaceholderExpansionWrapper(

val stringValue = expArg.consume(argumentParser)

if (isDebug) {
owner.logger.warning("Failed parsing for arg $expArg in placeholder $name")
}

if (expArg.isRequired() && stringValue.isEmpty()) {
invalid = true
if (isDebug) {
owner.logger.warning(
"Placeholder(${
identifier
}) Failed parsing for arg $expArg in placeholder $name - $stringValue"
)
}
continue
} else {
args[expArg.name()] = expArg.createContext(emptyCommand, baseContext, stringValue.stringValue)
args[expArg.name()] = expArg.createContext(
emptyCommand,
baseContext,
stringValue.stringValue?.split("_", " ") ?: emptyList()
)
}
}
if (invalid) continue
Expand Down
2 changes: 1 addition & 1 deletion 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 2866.75 ms.
Finished after 1620.52 ms.
20 changes: 14 additions & 6 deletions plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,27 @@ class KotlinGui : JavaPlugin() {
String(original.map { c -> fontMap[c] ?: c }.toCharArray())

val smallFont = mapFont("ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ")
val doubleStruck =
mapFont("\uD835\uDD52\uD835\uDD53\uD835\uDD54\uD835\uDD55\uD835\uDD56\uD835\uDD57\uD835\uDD58\uD835\uDD59\uD835\uDD5A\uD835\uDD5B\uD835\uDD5C\uD835\uDD5D\uD835\uDD5E\uD835\uDD5F\uD835\uDD60\uD835\uDD61\uD835\uDD62\uD835\uDD63\uD835\uDD64\uD835\uDD65\uD835\uDD66\uD835\uDD67\uD835\uDD68\uD835\uDD69\uD835\uDD6A\uD835\uDD6B")
val balls = mapFont("ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ")
val block =
mapFont("\uD83C\uDDE6\u200C\uD83C\uDDE7\u200C\uD83C\uDDE8\u200C\uD83C\uDDE9\u200C\uD83C\uDDEA\u200C\uD83C\uDDEB\u200C\uD83C\uDDEC\u200C\uD83C\uDDED\u200C\uD83C\uDDEE\u200C\uD83C\uDDEF\u200C\uD83C\uDDF0\u200C\uD83C\uDDF1\u200C\uD83C\uDDF2\u200C\uD83C\uDDF3\u200C\uD83C\uDDF4\u200C\uD83C\uDDF5\u200C\uD83C\uDDF6\u200C\uD83C\uDDF7\u200C\uD83C\uDDF8\u200C\uD83C\uDDF9\u200C\uD83C\uDDFA\u200C\uD83C\uDDFB\u200C\uD83C\uDDFC\u200C\uD83C\uDDFD\u200C\uD83C\uDDFE\u200C\uD83C\uDDFF\u200C")
val blackSquares =
mapFont("\uD83C\uDD70\uD83C\uDD71\uD83C\uDD72\uD83C\uDD73\uD83C\uDD74\uD83C\uDD75\uD83C\uDD76\uD83C\uDD77\uD83C\uDD78\uD83C\uDD79\uD83C\uDD7A\uD83C\uDD7B\uD83C\uDD7C\uD83C\uDD7D\uD83C\uDD7E\uD83C\uDD7F\uD83C\uDD80\uD83C\uDD81\uD83C\uDD82\uD83C\uDD83\uD83C\uDD84\uD83C\uDD85\uD83C\uDD86\uD83C\uDD87\uD83C\uDD88\uD83C\uDD89")

val stringToConvert by greedyStringArgument()
val fontType by multiChoiceArgument<(String) -> String>(
"smalltext" to { convertFont(it, smallFont) },
"doublestruck" to { convertFont(it, doubleStruck) },
"balls" to { convertFont(it, balls) },
"block" to { convertFont(it, block) }
"blacksquares" to { convertFont(it, blackSquares) }
)

val brandingType by multiChoiceArgument(
config.getConfigurationSection("branding")
?.let { section ->
section.getKeys(false).associateWithTo(HashMap()) { k -> section.getString(k) ?: "null" }
}
?: hashMapOf()
)

placeholderExpansion {
isDebug = true
placeholder("font" / fontType / stringToConvert) {
fontType()(stringToConvert())
}
Expand All @@ -105,6 +111,8 @@ class KotlinGui : JavaPlugin() {
fontType()(string)
}

placeholder("branding" / brandingType) { brandingType() }

} id "ktgui" author "MattMX"

("font" / fontType / stringToConvert).runs<CommandSender> {
Expand Down
8 changes: 8 additions & 0 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
branding:
name: "sᴇʀᴠᴇʀ ɴᴀᴍᴇ"
title: '&#B34262'
highlight: '&#AE76A6'
off-white: '&#A3C3D9'
dull: '&#CCD6EB'
primary: '&#E9ECF5'

gui:
example:
title: "Config Gui"
Expand Down

0 comments on commit 1d8cf9d

Please sign in to comment.