diff --git a/api/.gradle/caches/paperweight/taskCache/reobfJar.log b/api/.gradle/caches/paperweight/taskCache/reobfJar.log index 1d0273a..f38102e 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 3414.54 ms. +Finished after 2886.57 ms. 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 691b9bf..15554dd 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 @@ -4,9 +4,6 @@ import com.mattmx.ktgui.GuiManager import com.mattmx.ktgui.commands.declarative.arg.Argument import com.mattmx.ktgui.commands.declarative.arg.ArgumentContext import com.mattmx.ktgui.commands.declarative.arg.ArgumentProcessor -import com.mattmx.ktgui.commands.declarative.arg.consumer.GreedyArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumer.SingleArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.arg.impl.FlagArgument import com.mattmx.ktgui.commands.declarative.arg.impl.OptionArgument import com.mattmx.ktgui.commands.declarative.arg.impl.OptionSyntax @@ -312,6 +309,7 @@ open class DeclarativeCommandBuilder( // var providedArgumentIndex = 0 val argumentProcessor = ArgumentProcessor(this, context.rawArgs) + println(context.rawArgs) for ((index, arg) in expectedArguments.withIndex()) { if (argumentProcessor.done()) { if (arg.isRequired()) { @@ -342,7 +340,7 @@ open class DeclarativeCommandBuilder( val result = arg.consumer.consume(processorClone) val actualValue = arg.getValueOfString(this, context, result.stringValue) - if (arg.isOptional() || (result.isEmpty() && actualValue != null)) { + if (actualValue != null || arg.isOptional()) { argumentValues[arg.name()] = arg.createContext(result.stringValue, actualValue) argumentProcessor.pointer = processorClone.pointer argumentProcessor.optionsAndFlagsValues = processorClone.optionsAndFlagsValues @@ -355,6 +353,7 @@ open class DeclarativeCommandBuilder( } invalid.ifPresent { it.invoke(invalidArgumentContext) } + return } } 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 134772f..7595c1b 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 @@ -1,7 +1,7 @@ package com.mattmx.ktgui.commands.declarative.arg import com.mattmx.ktgui.commands.declarative.DeclarativeCommandBuilder -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.impl.OptionArgument import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext import com.mattmx.ktgui.commands.declarative.invocation.InvalidArgContext import com.mattmx.ktgui.commands.declarative.invocation.RunnableCommandContext @@ -117,6 +117,8 @@ open class Argument( } else null } + fun optionArgument() = OptionArgument(this) + @JavaCompatibility fun getContext(context: RunnableCommandContext<*>) = context.getArgumentContext(name()); diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumers/ArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt similarity index 78% rename from api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumers/ArgumentConsumer.kt rename to api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt index f730b79..200e256 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumers/ArgumentConsumer.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentConsumer.kt @@ -1,6 +1,4 @@ -package com.mattmx.ktgui.commands.declarative.arg.consumers - -import com.mattmx.ktgui.commands.declarative.arg.ArgumentProcessor +package com.mattmx.ktgui.commands.declarative.arg fun interface ArgumentConsumer { @@ -12,6 +10,8 @@ fun interface ArgumentConsumer { ) { fun isEmpty() = stringValue == null + override fun toString() = "Result('$stringValue', [${consumed.joinToString(", ")}])" + companion object { private val EMPTY = Result(null, emptyList()) fun empty() = EMPTY @@ -30,9 +30,9 @@ fun interface ArgumentConsumer { @JvmStatic infix fun untilFalse(predicate: (ArgumentProcessor, String) -> Boolean) = ArgumentConsumer { processor -> - var current = processor.next() - val startIndex = processor.pointer - var fullString = current ?: "" + var current: String? = "" + val startIndex = processor.pointer + 1 + var fullString = "" while (current != null) { current = processor.next() @@ -41,7 +41,8 @@ fun interface ArgumentConsumer { return@ArgumentConsumer Result.empty() } - fullString += " $current" + fullString += "$current " + fullString = fullString.trim() if (!predicate(processor, fullString)) { return@ArgumentConsumer Result(fullString, (startIndex..processor.pointer).toList()) @@ -55,9 +56,9 @@ fun interface ArgumentConsumer { @JvmStatic infix fun untilFalsePartial(predicate: (ArgumentProcessor, String) -> Boolean) = ArgumentConsumer { processor -> - var current = processor.next() - val startIndex = processor.pointer - var fullString = current ?: "" + var current: String? = null + val startIndex = processor.pointer + 1 + var fullString = "" while (current != null) { current = processor.next() @@ -66,7 +67,8 @@ fun interface ArgumentConsumer { return@ArgumentConsumer Result(fullString, (startIndex..processor.pointer).toList()) } - fullString += " $current" + fullString += "$current " + fullString = fullString.trim() if (!predicate(processor, current)) { return@ArgumentConsumer Result(fullString, (startIndex..processor.pointer).toList()) @@ -79,9 +81,7 @@ fun interface ArgumentConsumer { infix fun untilPartial(predicate: (ArgumentProcessor, String) -> Boolean) = untilFalsePartial { p, s -> !predicate(p, s) } @JvmStatic - fun remaining() = untilPartial { processor, _ -> - processor.pointer >= processor.args.size - } + 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/ArgumentProcessor.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/ArgumentProcessor.kt index 0ed2433..e40c71d 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 @@ -7,7 +7,7 @@ class ArgumentProcessor( val command: DeclarativeCommandBuilder, val args: List ) { - var pointer = 0 + var pointer = -1 var optionsAndFlagsValues = hashMapOf() fun peek(i: Int) = args.getOrNull(pointer + i) @@ -36,7 +36,7 @@ class ArgumentProcessor( } fun reset() { - this.pointer = 0 + this.pointer = -1 this.optionsAndFlagsValues.clear() } @@ -45,5 +45,5 @@ class ArgumentProcessor( this.pointer = this@ArgumentProcessor.pointer } - fun done() = pointer >= args.size + fun done() = pointer >= args.size - 1 } \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/ArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/ArgumentConsumer.kt deleted file mode 100644 index ff942da..0000000 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/ArgumentConsumer.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mattmx.ktgui.commands.declarative.arg.consumer - -fun interface ArgumentConsumer { - - fun consume(args: List) : List - - fun isVarArg() = false - -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/GreedyArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/GreedyArgumentConsumer.kt deleted file mode 100644 index c4afdf0..0000000 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/GreedyArgumentConsumer.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.mattmx.ktgui.commands.declarative.arg.consumer - -class GreedyArgumentConsumer : ArgumentConsumer { - override fun consume(args: List): List { - return args - } -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/SingleArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/SingleArgumentConsumer.kt deleted file mode 100644 index 36d8d75..0000000 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/SingleArgumentConsumer.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.mattmx.ktgui.commands.declarative.arg.consumer - -class SingleArgumentConsumer : ArgumentConsumer { - override fun consume(args: List): List { - return args.firstOrNull()?.let { listOf(it) } ?: emptyList() - } -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/VariableArgumentConsumer.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/VariableArgumentConsumer.kt deleted file mode 100644 index b39a8f9..0000000 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/consumer/VariableArgumentConsumer.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.mattmx.ktgui.commands.declarative.arg.consumer - -class VariableArgumentConsumer( - val to: Int -) : ArgumentConsumer { - override fun consume(args: List): List { - return args.subList(0, to) - } -} \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/BooleanArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/BooleanArgument.kt new file mode 100644 index 0000000..5cd741d --- /dev/null +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/BooleanArgument.kt @@ -0,0 +1,25 @@ +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.arg.suggests +import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext + +class BooleanArgument( + name: String, + typeName: String +) : Argument(name, typeName) { + + init { + suggests { listOf("true", "false") } + } + + override fun getValueOfString( + cmd: DeclarativeCommandBuilder, + context: BaseCommandContext<*>, + stringValue: String? + ): Boolean? { + return stringValue?.toBooleanStrictOrNull() + } + +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/DoubleArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/DoubleArgument.kt index ea1b982..1b750c0 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/DoubleArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/DoubleArgument.kt @@ -2,15 +2,14 @@ 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.arg.ArgumentProcessor -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext class DoubleArgument( name: String, typeName: String ) : Argument(name, typeName) { - var min: Double = Double.MIN_VALUE + var min: Double = -999999999999.0 var max: Double = Double.MAX_VALUE init { diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/EnumArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/EnumArgument.kt index a9dc617..0507a3c 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/EnumArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/EnumArgument.kt @@ -2,7 +2,7 @@ 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.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext import java.util.* diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/IntArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/IntArgument.kt index f9ea517..859eb1e 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/IntArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/IntArgument.kt @@ -2,8 +2,7 @@ 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.arg.consumer.SingleArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext class IntArgument( diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/LongArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/LongArgument.kt index 9663d6c..c4c9bb9 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/LongArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/LongArgument.kt @@ -2,8 +2,7 @@ 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.arg.consumer.SingleArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext class LongArgument( diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiArgument.kt index 083c4db..b50f14c 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/MultiArgument.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.consumer.ArgumentConsumer class MultiArgument( name: String, 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 5eaef69..dfc050a 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 @@ -2,8 +2,7 @@ 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.arg.consumer.SingleArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.arg.suggests import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext @@ -14,7 +13,12 @@ class MultiChoiceArgument( private val choices = initialChoices init { - this.consumes(ArgumentConsumer.until { argumentProcessor, s -> choices.containsKey(s) }) + this.consumes( + ArgumentConsumer.until { argumentProcessor, s -> + println("processing op '$s'") + choices.containsKey(s) + } + ) suggests { choices.keys.toList() } } diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OnlinePlayerArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OnlinePlayerArgument.kt index 3cc00e3..cb88a0a 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OnlinePlayerArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/OnlinePlayerArgument.kt @@ -2,7 +2,6 @@ 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.arg.consumer.SingleArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext import org.bukkit.Bukkit import org.bukkit.entity.Player diff --git a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/RelativeCoordinateArgument.kt b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/RelativeCoordinateArgument.kt index 68dbf71..a47893d 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/RelativeCoordinateArgument.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/commands/declarative/arg/impl/RelativeCoordinateArgument.kt @@ -2,8 +2,7 @@ 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.arg.consumer.VariableArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext import org.bukkit.Location import org.bukkit.entity.Entity 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 2458ae8..a445c69 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 @@ -2,7 +2,6 @@ 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.arg.consumer.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext import java.util.* 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 ef2aee3..7c3ce14 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 @@ -2,7 +2,7 @@ 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.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import com.mattmx.ktgui.commands.declarative.invocation.BaseCommandContext class StringArgument( @@ -11,7 +11,6 @@ class StringArgument( ) : Argument(name, type) { var min: Int = 0 var max: Int = Int.MAX_VALUE - lateinit var regex: Regex val allowed = arrayListOf() val disallow = arrayListOf() 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 9365cd5..08fabf8 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,9 +1,7 @@ package com.mattmx.ktgui.commands.declarative.arg.impl import com.mattmx.ktgui.commands.declarative.arg.Argument -import com.mattmx.ktgui.commands.declarative.arg.consumer.GreedyArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumer.SingleArgumentConsumer -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer +import com.mattmx.ktgui.commands.declarative.arg.ArgumentConsumer import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -24,7 +22,10 @@ fun stringArgument(type: String = "string") = delegateArgument(StringArgument(DELEGATED_ARG_NAME, type)) fun greedyStringArgument(type: String = "string") = - delegateArgument(StringArgument(DELEGATED_ARG_NAME, type).apply { this.consumes(ArgumentConsumer.remaining()) }) + delegateArgument(StringArgument(DELEGATED_ARG_NAME, type) greedy true) + +fun booleanArgument(type: String = "boolean") = + delegateArgument(BooleanArgument(DELEGATED_ARG_NAME, type)) fun intArgument(type: String = "int") = delegateArgument(IntArgument(DELEGATED_ARG_NAME, type)) 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 4d67e28..8336fcb 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 @@ -28,7 +28,7 @@ class RunnableCommandContext( operator fun Argument.invoke(): S { val ctx = context - return ctx.getOrNull()!! + return ctx.getOrNull() ?: error("The argument ${name()} wasn't provided in this invocation.") } } \ No newline at end of file diff --git a/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log b/plugin/.gradle/caches/paperweight/taskCache/reobfJar.log index bc9879d..6848d55 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 2176.44 ms. +Finished after 1904.84 ms. diff --git a/plugin/src/main/java/com/mattmx/ktgui/examples/JavaUpdateCommandExample.java b/plugin/src/main/java/com/mattmx/ktgui/examples/JavaUpdateCommandExample.java index e18aa7d..3e125bf 100644 --- a/plugin/src/main/java/com/mattmx/ktgui/examples/JavaUpdateCommandExample.java +++ b/plugin/src/main/java/com/mattmx/ktgui/examples/JavaUpdateCommandExample.java @@ -5,15 +5,11 @@ import com.mattmx.ktgui.commands.declarative.DeclarativeCommandBuilder; import com.mattmx.ktgui.commands.declarative.arg.Argument; import com.mattmx.ktgui.commands.declarative.arg.ArgumentContext; -import com.mattmx.ktgui.commands.declarative.arg.consumer.GreedyArgumentConsumer; -import com.mattmx.ktgui.commands.declarative.arg.consumers.ArgumentConsumer; import com.mattmx.ktgui.commands.declarative.arg.impl.OnlinePlayerArgument; import com.mattmx.ktgui.commands.declarative.arg.impl.StringArgument; import net.kyori.adventure.text.Component; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import static com.mattmx.ktgui.commands.declarative.DeclarativeCommandBuilderKt.command; import static com.mattmx.ktgui.utils.ColorKt.component; public class JavaUpdateCommandExample { diff --git a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt index e7746f5..edefdce 100644 --- a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt +++ b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt @@ -15,7 +15,6 @@ import com.mattmx.ktgui.papi.placeholder import com.mattmx.ktgui.papi.placeholderExpansion import com.mattmx.ktgui.scheduling.sync import com.mattmx.ktgui.sound.playSound -import com.mattmx.ktgui.sound.sound import com.mattmx.ktgui.sound.soundBuilder import com.mattmx.ktgui.utils.not import com.mattmx.ktgui.utils.pretty @@ -220,8 +219,8 @@ class KotlinGui : JavaPlugin() { ("sound") { runs { val sound = soundBuilder { - play(Sound.ENTITY_ENDERMAN_DEATH) - wait(10) + play(Sound.ENTITY_ENDERMAN_DEATH) volume 0.4f + wait(7) play(Sound.BLOCK_NOTE_BLOCK_BANJO) pitch 2f } relative true @@ -300,6 +299,7 @@ class KotlinGui : JavaPlugin() { val username by stringArgument() username suggests { history.map { it.first }.toSet() } + val maxResults by intArgument() maxResults min 1 max 100