diff --git a/api/.gradle/caches/paperweight/taskCache/reobfJar.log b/api/.gradle/caches/paperweight/taskCache/reobfJar.log index db7dd04..40902d9 100644 --- a/api/.gradle/caches/paperweight/taskCache/reobfJar.log +++ b/api/.gradle/caches/paperweight/taskCache/reobfJar.log @@ -1,2 +1,17 @@ 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 2784.17 ms. +Exception in thread "main" java.lang.RuntimeException: java.nio.file.FileSystemException: D:\PC\Projects\KtBukkitGui\api\build\libs\api-2.4.1.jar: The process cannot access the file because it is being used by another process + at net.fabricmc.tinyremapper.Main.main(Main.java:267) +Caused by: java.nio.file.FileSystemException: D:\PC\Projects\KtBukkitGui\api\build\libs\api-2.4.1.jar: The process cannot access the file because it is being used by another process + at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92) + at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) + at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) + at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:275) + at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105) + at java.base/java.nio.file.Files.delete(Files.java:1152) + at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1914) + at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.lambda$close$10(ZipFileSystem.java:494) + at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) + at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:493) + at net.fabricmc.tinyremapper.FileSystemReference.close(FileSystemReference.java:131) + at net.fabricmc.tinyremapper.OutputConsumerPath.close(OutputConsumerPath.java:213) + at net.fabricmc.tinyremapper.Main.main(Main.java:266) diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandBuilder.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandBuilder.kt index 15554dd..26e7aa5 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandBuilder.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandBuilder.kt @@ -22,6 +22,7 @@ import org.bukkit.permissions.PermissionDefault import java.time.Duration import java.util.* import java.util.function.Consumer +import kotlin.math.exp open class DeclarativeCommandBuilder( val name: String @@ -192,10 +193,10 @@ open class DeclarativeCommandBuilder( } operator fun FlagArgument.unaryPlus() = withFlag(this) - operator fun OptionArgument.unaryPlus() = withOption(this) + operator fun OptionArgument.unaryPlus() = this.apply { withOption(this) } operator fun Argument.unaryPlus() = OptionArgument(this).unaryPlus() - fun getCurrentCommand(context: SuggestionInvocation<*>): Pair, DeclarativeCommandBuilder?> { + fun getCurrentCommand(context: StorageCommandContext<*>): Pair, DeclarativeCommandBuilder?> { val firstArg = context.rawArgs.firstOrNull() ?: return context to this @@ -208,7 +209,7 @@ open class DeclarativeCommandBuilder( return context to this } - fun getSuggestions(context: SuggestionInvocation<*>): List { + fun getSuggestions(context: StorageCommandContext<*>): List { val cmds = subcommands .filter { it.nameStarts(context.last) } .map { listOf(it.name) + it.aliases } @@ -218,7 +219,7 @@ open class DeclarativeCommandBuilder( val suggestedArgs = arrayListOf(*cmdsList.toTypedArray()) for (arg in expectedArguments) { - val processor = ArgumentProcessor(this, list) + val processor = ArgumentProcessor(this, context, list) val result = arg.consume(processor) if (result.isEmpty() && !arg.isRequired()) continue @@ -302,14 +303,9 @@ open class DeclarativeCommandBuilder( } // Move onto args - val argumentValues = hashMapOf>() -// var expectedArgumentIndex = 0 -// var providedArgumentIndex = 0 - - val argumentProcessor = ArgumentProcessor(this, context.rawArgs) - println(context.rawArgs) + val argumentProcessor = ArgumentProcessor(this, context, context.rawArgs) for ((index, arg) in expectedArguments.withIndex()) { if (argumentProcessor.done()) { if (arg.isRequired()) { @@ -357,6 +353,11 @@ open class DeclarativeCommandBuilder( } } + // If there are no args they might be using optionals or flags + if (expectedArguments.isEmpty()) { + argumentProcessor.next() + } + if (!argumentProcessor.done()) { // Too many args, unknown command maybe? if (unknownCommand.isPresent) { diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandWrapper.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandWrapper.kt index b7c59af..f550231 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandWrapper.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/DeclarativeCommandWrapper.kt @@ -19,7 +19,7 @@ class DeclarativeCommandWrapper( } override fun tabComplete(sender: CommandSender, alias: String, args: Array): MutableList { - val context = SuggestionInvocation(Optional.of(sender), alias, args.toList().subList(0, args.size - 1)) + val context = StorageCommandContext(sender, alias, args.toList().subList(0, args.size - 1)) val (newContext, finalCommand) = builder.getCurrentCommand(context) val outArgs = finalCommand?.getSuggestions(newContext) diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/Argument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/Argument.kt index 7595c1b..7200c48 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/Argument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/Argument.kt @@ -27,7 +27,7 @@ open class Argument( var invalidCallback = EventCallback>() protected set private var optional = false - // todo impl default value + private var default: T? = null init { withTypeSuggestions() @@ -63,6 +63,12 @@ open class Argument( this.optional = value } + infix fun defaultValue(default: T) = apply { + this.default = default + } + + fun getDefaultValue() = default + infix fun missing(block: InvalidArgContext<*>.() -> Unit) = apply { this.missingCallback.callbacks.add(block) } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt index 200e256..6457a18 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt @@ -81,7 +81,9 @@ fun interface ArgumentConsumer { infix fun untilPartial(predicate: (ArgumentProcessor, String) -> Boolean) = untilFalsePartial { p, s -> !predicate(p, s) } @JvmStatic - fun remaining() = untilFalse { processor, _ -> !processor.done() } + fun remaining() = untilFalse { processor, _ -> + !processor.done() + } @JvmStatic infix fun variable(amount: Int): ArgumentConsumer { diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentContext.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentContext.kt index 7aa468c..4995855 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentContext.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentContext.kt @@ -1,5 +1,6 @@ package com.mattmx.ktgui.commands.declarative.arg +import org.codehaus.plexus.util.cli.Arg import java.util.* class ArgumentContext( @@ -22,4 +23,9 @@ class ArgumentContext( fun asOptional() = value override fun toString() = getOrNull().toString() + + companion object { + fun empty(argument: Argument) = + ArgumentContext(null, Optional.ofNullable(argument.getDefaultValue()), argument) + } } \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentProcessor.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentProcessor.kt index e40c71d..075b0eb 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentProcessor.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentProcessor.kt @@ -2,9 +2,11 @@ package com.mattmx.ktgui.commands.declarative.arg import com.mattmx.ktgui.commands.declarative.DeclarativeCommandBuilder import com.mattmx.ktgui.commands.declarative.arg.impl.* +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext class ArgumentProcessor( val command: DeclarativeCommandBuilder, + val context: StorageCommandContext<*>, val args: List ) { var pointer = -1 @@ -18,18 +20,33 @@ class ArgumentProcessor( while (current().let { it != null && command.optionsSyntax.match(it) }) { val optionOrPointerId = command.optionsSyntax.removePrefixFrom(current()!!) - if (command.permittedFlags.any { it.chatName() == optionOrPointerId }) { - optionsAndFlagsValues[optionOrPointerId] = true + val flag = command.permittedFlags.firstOrNull { it.chatName() == optionOrPointerId } + + if (flag != null) { + val passed = if (flag.requiresCheck.isEmpty) true else flag.requiresCheck.isPresent + + if (passed) { + optionsAndFlagsValues[optionOrPointerId] = true + } + pointer++ - } else if (command.permittedOptions.any { it.chatName() == optionOrPointerId }) { + } else { + println(command.permittedOptions) + val option = command.permittedOptions.firstOrNull { + it.chatName() == optionOrPointerId + } + + if (option != null) { + val passed = if (option.requiresCheck.isEmpty) true else option.requiresCheck.get()(context) - // TODO this should read the argument type args (does that make sense?) - // e.g '--test "hello world"' -> hello world + if (passed) { + val value = peek(1) ?: continue + optionsAndFlagsValues[optionOrPointerId] = value + } - val value = peek(1) ?: continue - optionsAndFlagsValues[optionOrPointerId] = value - pointer += 2 - } else break + pointer += 2 + } else break + } } return current() @@ -40,7 +57,7 @@ class ArgumentProcessor( this.optionsAndFlagsValues.clear() } - fun clone() = ArgumentProcessor(command, args).apply { + fun clone() = ArgumentProcessor(command, context, args).apply { this.optionsAndFlagsValues = this@ArgumentProcessor.optionsAndFlagsValues this.pointer = this@ArgumentProcessor.pointer } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/FlagArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/FlagArgument.kt index a564cf9..9fbe95a 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/FlagArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/FlagArgument.kt @@ -3,10 +3,24 @@ package com.mattmx.ktgui.commands.declarative.arg.impl import com.mattmx.ktgui.commands.declarative.DeclarativeCommandBuilder import com.mattmx.ktgui.commands.declarative.arg.Argument import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext +import com.mattmx.ktgui.commands.declarative.invocation.RunnableCommandContext +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext +import java.util.* class FlagArgument( name: String ) : Argument(name, "boolean") { + // todo command auto builder permissions node + var requiresCheck = Optional.empty<(StorageCommandContext<*>) -> Boolean>() + var showsInSuggestions = true + + infix fun requires(context: StorageCommandContext<*>.() -> Boolean) = apply { + this.requiresCheck = Optional.of(context) + } + + infix fun requiresPermission(node: String) = requires { + sender.hasPermission(node) + } fun chatName() = name().replace("_", "-") diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiChoiceArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiChoiceArgument.kt index dfc050a..e269388 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiChoiceArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiChoiceArgument.kt @@ -8,23 +8,22 @@ import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext class MultiChoiceArgument( name: String, - initialChoices: HashMap + initialChoices: () -> HashMap ) : Argument(name, "multi-choice") { - private val choices = initialChoices + private val choices: () -> HashMap = initialChoices init { this.consumes( ArgumentConsumer.until { argumentProcessor, s -> - println("processing op '$s'") - choices.containsKey(s) + choices().containsKey(s) } ) - suggests { choices.keys.toList() } + suggests { choices().keys.toList() } } override fun getValueOfString( cmd: DeclarativeCommandBuilder, context: BaseCommandContext<*>, stringValue: String? - ) = choices[stringValue] + ) = choices()[stringValue] } \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OptionArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OptionArgument.kt index af48bb6..f05b279 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OptionArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OptionArgument.kt @@ -1,9 +1,30 @@ package com.mattmx.ktgui.commands.declarative.arg.impl import com.mattmx.ktgui.commands.declarative.arg.Argument +import com.mattmx.ktgui.commands.declarative.invocation.RunnableCommandContext +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext +import java.util.Optional class OptionArgument( val sub: Argument ) { + // todo command auto builder permissions node + var requiresCheck = Optional.empty<(StorageCommandContext<*>) -> Boolean>() + private set + var shownInSuggestions = true + private set + + infix fun requires(context: StorageCommandContext<*>.() -> Boolean) = apply { + this.requiresCheck = Optional.of(context) + } + + infix fun requiresPermission(node: String) = requires { + sender.hasPermission(node) + } + + infix fun shownInSuggestions(value: Boolean) = apply { + this.shownInSuggestions = value + } + fun chatName() = sub.name().replace("_", "-") } \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/StringArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/StringArgument.kt index 7c3ce14..4e13c4c 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/StringArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/StringArgument.kt @@ -24,7 +24,7 @@ class StringArgument( val range = (min..max) val matchesRange = stringValue.length in range - val matchesAllowed = allowed.any { it.matches(stringValue) } + val matchesAllowed = allowed.all { it.matches(stringValue) } val meetsDisallowed = disallow.none { it.matches(stringValue) } val all = matchesRange && matchesAllowed && meetsDisallowed diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/args.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/args.kt index 08fabf8..8e262a6 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/args.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/args.kt @@ -1,7 +1,6 @@ package com.mattmx.ktgui.commands.declarative.arg.impl import com.mattmx.ktgui.commands.declarative.arg.Argument -import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -48,7 +47,10 @@ inline fun > enumArgument(type: String = E::class.java.simpl fun flag() = delegateArgument(FlagArgument(DELEGATED_ARG_NAME)) fun multiChoiceArgument(vararg choices: Pair) = - delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME, hashMapOf(*choices))) + delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { hashMapOf(*choices) }) + +fun multiChoiceArgument(choiceSupplier: () -> HashMap) = + delegateArgument(MultiChoiceArgument(DELEGATED_ARG_NAME) { choiceSupplier() }) fun simpleMappedArgument() = delegateArgument(SimpleArgument(DELEGATED_ARG_NAME, "type")) \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/RunnableCommandContext.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/RunnableCommandContext.kt index 8336fcb..252ef68 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/RunnableCommandContext.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/RunnableCommandContext.kt @@ -24,7 +24,7 @@ class RunnableCommandContext( val Argument.context: ArgumentContext get() = getArgumentContext(name()) - ?: error("The argument ${name()} is not available in this command context.") + ?: ArgumentContext.empty(this) operator fun Argument.invoke(): S { val ctx = context diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/StorageCommandContext.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/StorageCommandContext.kt index badfa30..b4b8b2f 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/StorageCommandContext.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/invocation/StorageCommandContext.kt @@ -8,6 +8,8 @@ open class StorageCommandContext( rawArgs: List ) : BaseCommandContext(sender, alias, rawArgs) { val storage = hashMapOf() + val last: String + get() = rawArgs.lastOrNull() ?: "" override fun clone(newList: List): StorageCommandContext { return StorageCommandContext(sender, alias, newList) diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/CommandSuggestion.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/CommandSuggestion.kt index 1d2c01d..834ef18 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/CommandSuggestion.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/CommandSuggestion.kt @@ -1,11 +1,11 @@ package com.mattmx.ktgui.commands.suggestions -import com.mattmx.ktgui.commands.declarative.invocation.SuggestionInvocation +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext fun interface CommandSuggestion { - fun getSuggestion(invocation: SuggestionInvocation<*>): Collection? + fun getSuggestion(invocation: StorageCommandContext<*>): Collection? - fun getLastArgSuggestion(invocation: SuggestionInvocation<*>) = getSuggestion(invocation) + fun getLastArgSuggestion(invocation: StorageCommandContext<*>) = getSuggestion(invocation) ?.filter { it.startsWith((invocation.rawArgs.lastOrNull() ?: ""), true) } fun getValue(argumentString: String?) : V? { diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/SimpleCommandSuggestion.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/SimpleCommandSuggestion.kt index cf06412..c8810bd 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/SimpleCommandSuggestion.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/SimpleCommandSuggestion.kt @@ -1,5 +1,6 @@ package com.mattmx.ktgui.commands.suggestions +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext import com.mattmx.ktgui.commands.declarative.invocation.SuggestionInvocation import kotlin.reflect.KProperty import kotlin.reflect.jvm.javaMethod @@ -9,7 +10,7 @@ open class SimpleCommandSuggestion( val list: () -> List ) : CommandSuggestion { - override fun getSuggestion(invocation: SuggestionInvocation<*>): List? { + override fun getSuggestion(invocation: StorageCommandContext<*>): List? { val list = list() return list.map { obj -> field.getter.javaMethod?.invoke(obj).toString() } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/MaterialCommandSuggestion.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/MaterialCommandSuggestion.kt index 272ebaf..bfbb2a2 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/MaterialCommandSuggestion.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/MaterialCommandSuggestion.kt @@ -1,11 +1,12 @@ package com.mattmx.ktgui.commands.suggestions.impl +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext import com.mattmx.ktgui.commands.declarative.invocation.SuggestionInvocation import com.mattmx.ktgui.commands.suggestions.CommandSuggestion import org.bukkit.Material class MaterialCommandSuggestion : CommandSuggestion { - override fun getSuggestion(invocation: SuggestionInvocation<*>): List { + override fun getSuggestion(invocation: StorageCommandContext<*>): List { return Material.values().map { it.key.toString() } } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/OnlinePlayersCommandSuggestion.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/OnlinePlayersCommandSuggestion.kt index c2c29a0..2c1cb16 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/OnlinePlayersCommandSuggestion.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/suggestions/impl/OnlinePlayersCommandSuggestion.kt @@ -1,14 +1,15 @@ package com.mattmx.ktgui.commands.suggestions.impl +import com.mattmx.ktgui.commands.declarative.invocation.StorageCommandContext import com.mattmx.ktgui.commands.suggestions.CommandSuggestion import com.mattmx.ktgui.commands.declarative.invocation.SuggestionInvocation import org.bukkit.Bukkit import org.bukkit.entity.Player class OnlinePlayersCommandSuggestion : CommandSuggestion { - override fun getSuggestion(invocation: SuggestionInvocation<*>): List { + override fun getSuggestion(invocation: StorageCommandContext<*>): List { return Bukkit.getOnlinePlayers() - .filter { if (invocation.sender.orElse(null) is Player) (invocation.sender.get() as Player).canSee(it) else true } + .filter { if (invocation.sender is Player) invocation.sender.canSee(it) else true } .map { it.name } .toList() } diff --git a/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log b/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log index c20b37a..bde4027 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 1634.00 ms. +Finished after 2866.75 ms. diff --git a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt index d2ec71a..d8e131d 100644 --- a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt +++ b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt @@ -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 @@ -26,6 +27,7 @@ import org.bukkit.event.inventory.InventoryType import org.bukkit.plugin.java.JavaPlugin import java.time.Duration import java.util.logging.Logger +import kotlin.math.max class KotlinGui : JavaPlugin() { override fun onEnable() { @@ -313,6 +315,8 @@ class KotlinGui : JavaPlugin() { +username runs { + reply(username.context.stringValue() ?: "null") + val results = history .subList(0, maxResults.context.orElse(history.size).coerceAtMost(history.size)) .filter { it.first == username.context.orElse(it.first) } @@ -326,7 +330,7 @@ class KotlinGui : JavaPlugin() { val cooldownPeriod by longArgument() cooldownPeriod optional true - // fixme: args optional don't work + cooldownPeriod suggests { listOf(cooldownPeriod.toString()) } ("cooldown" / cooldownPeriod) { cooldown(Duration.ofSeconds(3)) @@ -348,24 +352,23 @@ class KotlinGui : JavaPlugin() { "obj" { val objects = hashMapOf>() - val objectId by stringArgument() - objectId range (3..16) matches "[a-z0-9_]{3,16}".toRegex() - objectId invalid { reply(!"Invalid object ID $provided") } + val newObjectId by stringArgument() + newObjectId range (3..16) matches "[a-z0-9_]{3,16}".toRegex() + newObjectId invalid { reply(!"Invalid object ID $provided") } - ("create" / objectId) { + ("create" / newObjectId) { runs { - objects.putIfAbsent(objectId(), hashMapOf()) - reply(!"&aCreated object ${objectId()}") + objects.putIfAbsent(newObjectId(), hashMapOf()) + reply(!"&aCreated object ${newObjectId()}") } } - val existingObjectId by simpleMappedArgument>() - existingObjectId getValue { objects[this] } - existingObjectId suggests { objects.keys.toList() } - existingObjectId invalid objectId.invalidCallback.first() + val existingObjectId by multiChoiceArgument { objects } + existingObjectId invalid newObjectId.invalidCallback.first() val path by stringArgument() path matches "([a-z0-9_]\\.?)+".toRegex() + val value by stringArgument() ("set" / existingObjectId / path / value) { runs {