generated from UndefinedCreations/Template
-
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.
feat: add even rougher implementation of CommandContext
- Loading branch information
1 parent
cc5fca4
commit d868b18
Showing
15 changed files
with
120 additions
and
61 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
2 changes: 1 addition & 1 deletion
2
...ndefined/stellar/data/arguments/Anchor.kt → ...undefined/stellar/data/argument/Anchor.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
10 changes: 10 additions & 0 deletions
10
common/src/main/kotlin/com/undefined/stellar/data/argument/CommandContext.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,10 @@ | ||
package com.undefined.stellar.data.argument | ||
|
||
import java.util.* | ||
|
||
typealias CommandNode = LinkedList<Any?> | ||
|
||
class CommandContext(val arguments: CommandNode, val input: String) { | ||
fun <T> getSubCommand(int: Int): T = arguments[int] as T | ||
operator fun get(int: Int) = arguments[int] | ||
} |
2 changes: 1 addition & 1 deletion
2
...fined/stellar/data/arguments/Operation.kt → ...efined/stellar/data/argument/Operation.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
2 changes: 1 addition & 1 deletion
2
...ed/stellar/data/arguments/ParticleData.kt → ...ned/stellar/data/argument/ParticleData.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
4 changes: 3 additions & 1 deletion
4
common/src/main/kotlin/com/undefined/stellar/sub/AbstractStellarSubCommand.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,9 +1,11 @@ | ||
package com.undefined.stellar.sub | ||
|
||
import com.undefined.stellar.AbstractStellarCommand | ||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
abstract class AbstractStellarSubCommand<T>(val parent: AbstractStellarCommand<*>, name: String) : AbstractStellarCommand<AbstractStellarSubCommand<T>>(name) { | ||
abstract class AbstractStellarSubCommand<T>(val parent: AbstractStellarCommand<*>, name: String) : AbstractStellarCommand<T>(name) { | ||
override fun getBase(): AbstractStellarCommand<*> = parent.getBase() | ||
override fun register(plugin: JavaPlugin) = parent.register(plugin) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
common/src/main/kotlin/com/undefined/stellar/sub/brigadier/entity/EntityAnchorSubCommand.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
2 changes: 1 addition & 1 deletion
2
common/src/main/kotlin/com/undefined/stellar/sub/brigadier/math/OperationSubCommand.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
2 changes: 1 addition & 1 deletion
2
common/src/main/kotlin/com/undefined/stellar/sub/brigadier/world/ParticleSubCommand.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
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,23 +1,43 @@ | ||
package com.undefined.stellar | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import com.undefined.stellar.data.suggestion.Suggestion | ||
import org.bukkit.entity.Player | ||
import org.bukkit.plugin.java.JavaPlugin | ||
import java.util.LinkedList | ||
|
||
class Main : JavaPlugin() { | ||
typealias CommandNode = LinkedList<Any?> | ||
|
||
companion object { | ||
lateinit var INSTANCE: Main | ||
} | ||
class Main : JavaPlugin() { | ||
|
||
override fun onEnable() { | ||
INSTANCE = this | ||
|
||
StellarCommand("test") | ||
StellarCommand("test", description = "this is a description", "alias") | ||
.addAlias("othertest") | ||
.setDescription("This is a description") | ||
.setUsageText("/test <string>") | ||
.setUsageText("/test <other>") | ||
.addStringSubCommand("test") | ||
.addStringSubCommand("test") | ||
.addSuggestion("Text", "Tooltip") | ||
.addSuggestions(Suggestion("suggestion", "t")) | ||
.alwaysRun<Player> { | ||
sendMessage("This will always run no matter what") | ||
true | ||
} | ||
.addExecution<Player> { sendMessage("Execution") } | ||
.addSubCommandExecution<Player> { context -> | ||
sendMessage(context.getSubCommand<String>(1)) | ||
} | ||
.addFailureExecution<Player> { sendMessage("Failure!") } | ||
.addFailureExecution<Player> { sendMessage("Incorrect!") } | ||
.hideDefaultFailureMessages() | ||
.register(this) | ||
|
||
// val main = StellarCommand("test") | ||
// main.addOnlinePlayersSubCommand("onlinePlayers") | ||
// .addExecution<Player> { context -> | ||
// context.input | ||
// context.<String>get(1) | ||
// context<String>[1] | ||
// } | ||
} | ||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandContextAdapter.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,28 @@ | ||
package com.undefined.stellar.v1_20_6 | ||
|
||
import com.mojang.brigadier.context.CommandContext | ||
import com.undefined.stellar.AbstractStellarCommand | ||
import com.undefined.stellar.StellarCommands | ||
import com.undefined.stellar.data.argument.CommandNode | ||
import com.undefined.stellar.sub.BaseStellarSubCommand | ||
import com.undefined.stellar.sub.custom.CustomSubCommand | ||
import net.minecraft.commands.CommandSourceStack | ||
|
||
class CommandContextAdapter(private val context: CommandContext<CommandSourceStack>) { | ||
fun getStellarCommandContext(): com.undefined.stellar.data.argument.CommandContext { | ||
// val arguments: CommandNode = CommandNode() | ||
// arguments.addAll(context.nodes.map { ArgumentHelper.getParsedArgumentFromBrigadier(context, BrigadierCommandRegistrar.) }) | ||
println(context.input.startsWith('/')) | ||
val input = context.input.removePrefix("/") | ||
val baseCommand: AbstractStellarCommand<*> = StellarCommands.getStellarCommand(input.substring(input.indexOf('/') + 1, input.indexOf(' ')))!! | ||
val arguments: CommandNode = CommandNode() | ||
arguments.addAll(BrigadierCommandRegistrar.getSubCommands(baseCommand, context).map { | ||
if (it is CustomSubCommand) return@map it.parse(context.source.bukkitSender, input) | ||
ArgumentHelper.getParsedArgumentFromSubCommand(context, it as? BaseStellarSubCommand ?: return@map null) | ||
}) | ||
return com.undefined.stellar.data.argument.CommandContext( | ||
arguments, | ||
input | ||
) | ||
} | ||
} |