-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Context Receivers for advanced usage
Now supports things like this: ``` dispatcher { "literal_arg_1" { executesX { // ... do something } "typed_arg_1"(StringArgumentType.greedyString()) { executesX { val theString = StringArgumentType.getString(it, "typed_arg_1") println(theString) } } } } } ```
- Loading branch information
Showing
6 changed files
with
77 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = "brigadierx" | ||
rootProject.name = "brigadierX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cn.taskeren.brigadierx | ||
|
||
import com.mojang.brigadier.CommandDispatcher | ||
import com.mojang.brigadier.arguments.ArgumentType | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder | ||
|
||
operator fun <S> CommandDispatcher<S>.invoke(block: CommandDispatcher<S>.() -> Unit) = block(this) | ||
|
||
context(CommandDispatcher<S>) | ||
operator fun <S> String.invoke(block: LiteralArgumentBuilder<S>.() -> Unit) = register(this, block) | ||
|
||
context(CommandDispatcher<*>, LiteralArgumentBuilder<S>) | ||
operator fun <S> String.invoke(block: LiteralArgumentBuilder<S>.() -> Unit) = literal(this, block) | ||
|
||
context(CommandDispatcher<*>, LiteralArgumentBuilder<S>) | ||
operator fun <S, T> String.invoke(type: ArgumentType<T>, block: RequiredArgumentBuilder<S, T>.() -> Unit) = | ||
argument(this, type, block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.taskeren.sample.brigadier | ||
|
||
import cn.taskeren.brigadierx.executesX | ||
import cn.taskeren.brigadierx.invoke | ||
import com.mojang.brigadier.CommandDispatcher | ||
import com.mojang.brigadier.arguments.StringArgumentType | ||
|
||
fun main() { | ||
TestNew().testCase1() | ||
} | ||
|
||
internal class TestNew { | ||
|
||
fun testCase1() { | ||
val dispatcher = CommandDispatcher<Any>() | ||
|
||
dispatcher { | ||
"help" { | ||
"what" { | ||
|
||
"what"(StringArgumentType.greedyString()) { | ||
executesX { | ||
val what = StringArgumentType.getString(it, "what") | ||
println("Help What? $what") | ||
} | ||
} | ||
|
||
executesX { | ||
println("Idk what to help!") | ||
} | ||
} | ||
|
||
executesX { | ||
println("Help!") | ||
} | ||
} | ||
} | ||
|
||
dispatcher.execute(readlnOrNull(), object {}) | ||
} | ||
|
||
} |