aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-16 01:23:43 +0200
committernea <nea@nea.moe>2023-05-16 01:23:43 +0200
commitead6762eb1c005914b05f9d3c29f334989c67513 (patch)
treecd1409756be2bc4a93195c31d432fef053afe002 /src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt
parent96c546cc73880a7c502c17aadda6ca84c847692d (diff)
downloadfirmament-ead6762eb1c005914b05f9d3c29f334989c67513.tar.gz
firmament-ead6762eb1c005914b05f9d3c29f334989c67513.tar.bz2
firmament-ead6762eb1c005914b05f9d3c29f334989c67513.zip
Replace references to NEU with Firmament
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt81
1 files changed, 0 insertions, 81 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt b/src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt
deleted file mode 100644
index 6190d88..0000000
--- a/src/main/kotlin/moe/nea/notenoughupdates/commands/dsl.kt
+++ /dev/null
@@ -1,81 +0,0 @@
-package moe.nea.notenoughupdates.commands
-
-import com.mojang.brigadier.arguments.ArgumentType
-import com.mojang.brigadier.builder.ArgumentBuilder
-import com.mojang.brigadier.builder.LiteralArgumentBuilder
-import com.mojang.brigadier.builder.RequiredArgumentBuilder
-import com.mojang.brigadier.context.CommandContext
-import java.lang.reflect.ParameterizedType
-import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
-import moe.nea.notenoughupdates.util.iterate
-
-
-typealias DefaultSource = FabricClientCommandSource
-
-
-inline val <T : CommandContext<*>> T.context get() = this
-operator fun <T : Any, C : CommandContext<*>> C.get(arg: TypeSafeArg<T>): T {
- return arg.get(this)
-}
-
-fun literal(
- name: String,
- block: LiteralArgumentBuilder<DefaultSource>.() -> Unit
-): LiteralArgumentBuilder<DefaultSource> =
- LiteralArgumentBuilder.literal<DefaultSource>(name).also(block)
-
-data class TypeSafeArg<T : Any>(val name: String, val argument: ArgumentType<T>) {
- val argClass by lazy {
- argument.javaClass
- .iterate<Class<in ArgumentType<T>>> {
- it.superclass
- }
- .map {
- it.genericSuperclass
- }
- .filterIsInstance<ParameterizedType>()
- .find { it.rawType == ArgumentType::class.java }!!
- .let { it.actualTypeArguments[0] as Class<*> }
- }
-
- @JvmName("getWithThis")
- fun <S> CommandContext<S>.get(): T =
- get(this)
-
-
- fun <S> get(ctx: CommandContext<S>): T {
- return ctx.getArgument(name, argClass) as T
- }
-}
-
-
-fun <T : Any> argument(
- name: String,
- argument: ArgumentType<T>,
- block: RequiredArgumentBuilder<DefaultSource, T>.(TypeSafeArg<T>) -> Unit
-): RequiredArgumentBuilder<DefaultSource, T> =
- RequiredArgumentBuilder.argument<DefaultSource, T>(name, argument).also { block(it, TypeSafeArg(name, argument)) }
-
-fun <T : ArgumentBuilder<DefaultSource, T>, AT : Any> T.thenArgument(
- name: String,
- argument: ArgumentType<AT>,
- block: RequiredArgumentBuilder<DefaultSource, AT>.(TypeSafeArg<AT>) -> Unit
-): T = then(argument(name, argument, block))
-
-
-fun <T : ArgumentBuilder<DefaultSource, T>> T.thenLiteral(
- name: String,
- block: LiteralArgumentBuilder<DefaultSource>.() -> Unit
-): T =
- then(literal(name, block))
-
-fun <T : ArgumentBuilder<DefaultSource, T>> T.then(node: ArgumentBuilder<DefaultSource, *>, block: T.() -> Unit): T =
- then(node).also(block)
-
-fun <T : ArgumentBuilder<DefaultSource, T>> T.thenExecute(block: CommandContext<DefaultSource>.() -> Unit): T =
- executes {
- block(it)
- 1
- }
-
-