Skip to content

Commit

Permalink
make multi choice arg more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Jul 15, 2024
1 parent 5ef159e commit 8e8ef5d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 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.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 2923.07 ms.
Finished after 3172.69 ms.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ open class DeclarativeCommandBuilder(
val cmds = subcommands
.filter { it.nameStarts(context.last) }
.map { listOf(it.name) + it.aliases }

val cmdsList = cmds.flatten()

val list = context.rawArgs.toMutableList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext

class MultiChoiceArgument<T : Any>(
name: String,
initialChoices: () -> HashMap<String, T>
initialChoices: () -> Map<String, T>
) : Argument<T>(name, "multi-choice") {
private val choices: () -> HashMap<String, T> = initialChoices
private val choices: () -> Map<String, T> = initialChoices

init {
this.consumes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ 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>) =
fun <T : Any> multiChoiceArgument(choices: List<Pair<String, T>>) =
delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { choices.toMap() })

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

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

fun multiChoiceStringArgument(choiceSupplier: List<String>) =
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.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.
Finished after 1764.07 ms.
10 changes: 6 additions & 4 deletions plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mattmx.ktgui

import com.mattmx.ktgui.commands.declarative.arg.impl.*
import com.mattmx.ktgui.commands.declarative.arg.suggests
import com.mattmx.ktgui.commands.declarative.arg.suggestsTopLevel
import com.mattmx.ktgui.commands.declarative.arg.withArgs
import com.mattmx.ktgui.commands.declarative.div
Expand Down Expand Up @@ -155,9 +156,9 @@ class KotlinGui : JavaPlugin() {
}
}

val invType by enumArgument<InventoryType>()

invType getStringValueOf { name.lowercase() }
val invType by multiChoiceArgument(
InventoryType.values().map { it.name.lowercase() to it }
)
invType invalid { reply(!"&cThat is not a valid inventory type.") }

("inventory" / invType) {
Expand Down Expand Up @@ -189,7 +190,7 @@ class KotlinGui : JavaPlugin() {
val target = player()
reply(
!"&aFound ${target.name} @ ${
target.location.clone().toVector()
target.location.clone().toVector().toString().replace(",", ", ")
} in world '${target.location.world.name}'."
)
}
Expand All @@ -198,6 +199,7 @@ class KotlinGui : JavaPlugin() {
val msg by greedyStringArgument()
msg min 1
msg invalid { reply(!"&cMust provide a valid msg (at least 1 char)") }
msg suggests { emptyList() }
("msg" / player / msg) {
runs<CommandSender> {
reply(!"&f[Me -> ${player().name}]: ${msg()}")
Expand Down

0 comments on commit 8e8ef5d

Please sign in to comment.