-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commands): Custom argument suggestions, command aliases
- Loading branch information
Showing
10 changed files
with
187 additions
and
83 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
43 changes: 0 additions & 43 deletions
43
idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/brigadier/BuildStep.kt
This file was deleted.
Oops, something went wrong.
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
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
46 changes: 46 additions & 0 deletions
46
idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/brigadier/RenderStep.kt
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,46 @@ | ||
package com.mineinabyss.idofront.commands.brigadier | ||
|
||
@Suppress("UnstableApiUsage") | ||
sealed interface RenderStep { | ||
fun reduce(rightAcc: List<RenderedCommand>): List<RenderedCommand> | ||
|
||
class Builder(val builder: IdoArgBuilder) : RenderStep { | ||
override fun reduce(rightAcc: List<RenderedCommand>): List<RenderedCommand> { | ||
return listOf(RenderedCommand.ThenFold(builder, rightAcc)) | ||
} | ||
} | ||
|
||
class Command(val command: IdoCommand) : RenderStep { | ||
override fun reduce(rightAcc: List<RenderedCommand>): List<RenderedCommand> { | ||
return listOf(RenderedCommand.ThenFold(command.initial, command.render())) + rightAcc | ||
} | ||
} | ||
|
||
class Apply(val apply: IdoArgBuilder.() -> Unit) : RenderStep { | ||
override fun reduce(rightAcc: List<RenderedCommand>): List<RenderedCommand> { | ||
return listOf(RenderedCommand.Apply(apply)) + rightAcc | ||
} | ||
} | ||
|
||
// class Executes( | ||
// val on: RenderStep, | ||
// var executes: IdoCommandContext.() -> Unit = { }, | ||
// ) : RenderStep { | ||
// @Suppress("UNCHECKED_CAST") // Paper's api always uses CommandSourceStack | ||
// override fun builder(): IdoArgBuilder = on.builder().executes { context -> | ||
// executes(IdoCommandContext(context)) | ||
// com.mojang.brigadier.Command.SINGLE_SUCCESS | ||
// } as IdoArgBuilder | ||
// } | ||
|
||
// class Nested( | ||
// val previous: RenderStep, | ||
// val inner: RenderStep, | ||
// ) : RenderStep { | ||
// override fun builder(): IdoArgBuilder { | ||
// return previous.builder().apply { | ||
// then(inner.builder()) | ||
// } | ||
// } | ||
// } | ||
} |
18 changes: 14 additions & 4 deletions
18
...t-commands/src/main/kotlin/com/mineinabyss/idofront/commands/brigadier/RootIdoCommands.kt
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
6 changes: 6 additions & 0 deletions
6
idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/brigadier/TypeAliases.kt
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,7 +1,13 @@ | ||
package com.mineinabyss.idofront.commands.brigadier | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder | ||
import com.mojang.brigadier.tree.CommandNode | ||
import io.papermc.paper.command.brigadier.CommandSourceStack | ||
|
||
@Suppress("UnstableApiUsage") | ||
internal typealias IdoArgBuilder = ArgumentBuilder<CommandSourceStack, *> | ||
internal typealias IdoCommandNode = CommandNode<CommandSourceStack> | ||
|
||
fun IdoArgBuilder.thenCast(other: IdoArgBuilder): IdoArgBuilder = then(other) as IdoArgBuilder | ||
|
||
fun IdoArgBuilder.thenCast(other: IdoCommandNode): IdoArgBuilder = then(other) as IdoArgBuilder |