Make brigardier argument and literal chainable

This commit is contained in:
Jakob K
2021-08-24 01:58:25 +02:00
parent 3ab5cbc14b
commit 1dbcec3b1d

View File

@@ -9,6 +9,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType
import com.mojang.brigadier.tree.LiteralCommandNode import com.mojang.brigadier.tree.LiteralCommandNode
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.future.asCompletableFuture import kotlinx.coroutines.future.asCompletableFuture
import net.minecraft.commands.CommandListenerWrapper import net.minecraft.commands.CommandListenerWrapper
@@ -53,9 +54,7 @@ inline fun <S> ArgumentBuilder<S, *>.simpleExecutes(
inline fun ArgumentBuilder<CommandListenerWrapper, *>.literal( inline fun ArgumentBuilder<CommandListenerWrapper, *>.literal(
name: String, name: String,
builder: LiteralArgumentBuilder<CommandListenerWrapper>.() -> Unit, builder: LiteralArgumentBuilder<CommandListenerWrapper>.() -> Unit,
) { ) = command(name, false, builder).also { then(it) }
then(command(name, false, builder))
}
/** /**
* Add an argument. * Add an argument.
@@ -67,11 +66,10 @@ inline fun <T> ArgumentBuilder<CommandListenerWrapper, *>.argument(
name: String, name: String,
type: ArgumentType<T>, type: ArgumentType<T>,
builder: RequiredArgumentBuilder<CommandListenerWrapper, T>.() -> Unit, builder: RequiredArgumentBuilder<CommandListenerWrapper, T>.() -> Unit,
) { ): RequiredArgumentBuilder<CommandListenerWrapper, T> =
then(RequiredArgumentBuilder.argument<CommandListenerWrapper, T>(name, type).apply(builder)) RequiredArgumentBuilder.argument<CommandListenerWrapper, T>(name, type).apply(builder).also { then(it) }
}
private val argumentCoroutineScope = CoroutineScope(Dispatchers.IO) private val argumentCoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
/** /**
* Add custom suspending suggestion logic for an argument. * Add custom suspending suggestion logic for an argument.