Skip to content

Commit

Permalink
added command aliases
Browse files Browse the repository at this point in the history
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Sep 24, 2024
1 parent 36be37a commit 444d375
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gay.j10a1n15.sillygames.commands


import gay.j10a1n15.sillygames.config.Config
import gay.j10a1n15.sillygames.screens.GameSelector
import gay.j10a1n15.sillygames.screens.PictureInPicture
Expand All @@ -12,29 +11,31 @@ import net.minecraftforge.client.ClientCommandHandler
class CommandManager {

init {
registerCommand("sillygames") {
registerCommand("sillygames", listOf("sg", "silly")) {
Config.gui()?.display()
}
registerCommand("games") {
registerCommand("games", listOf("game")) {
GameSelector().display()
}
registerCommand("pip") {
PictureInPicture.visible = !PictureInPicture.visible
}
}

private fun registerCommand(name: String, function: (Array<String>) -> Unit) {
ClientCommandHandler.instance.registerCommand(SimpleCommand(name, createCommand(function)))
private fun registerCommand(name: String, aliases: List<String> = listOf(), function: (Array<String>) -> Unit) {
ClientCommandHandler.instance.registerCommand(SimpleCommand(name, aliases, createCommand(function)))
}

@Suppress("unused")
private fun registerCommand0(
name: String,
aliases: List<String> = listOf(),
function: (Array<String>) -> Unit,
autoComplete: ((Array<String>) -> List<String>) = { listOf() },
) {
val command = SimpleCommand(
name,
aliases,
createCommand(function),
object : SimpleCommand.TabCompleteRunnable {
override fun tabComplete(sender: ICommandSender?, args: Array<String>?, pos: BlockPos?): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import net.minecraft.util.BlockPos

class SimpleCommand : CommandBase {
private val commandName: String
private val aliases: List<String>
private val runnable: ProcessCommandRunnable
private var tabRunnable: TabCompleteRunnable? = null

constructor(commandName: String, runnable: ProcessCommandRunnable) {
constructor(commandName: String, aliases: List<String>, runnable: ProcessCommandRunnable) {
this.commandName = commandName
this.aliases = aliases
this.runnable = runnable
}

constructor(commandName: String, runnable: ProcessCommandRunnable, tabRunnable: TabCompleteRunnable?) {
constructor(commandName: String, aliases: List<String>, runnable: ProcessCommandRunnable, tabRunnable: TabCompleteRunnable?) {
this.commandName = commandName
this.aliases = aliases
this.runnable = runnable
this.tabRunnable = tabRunnable
}
Expand All @@ -40,6 +43,10 @@ class SimpleCommand : CommandBase {
return "/$commandName"
}

override fun getCommandAliases(): List<String> {
return aliases
}

override fun processCommand(sender: ICommandSender, args: Array<String>) {
try {
runnable.processCommand(sender, args)
Expand Down

0 comments on commit 444d375

Please sign in to comment.