aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/caelo/CaeloCommand.kt
blob: e355540e21b0b3d00934541d7f69c829d1ed6882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package moe.nea.caelo

import moe.nea.caelo.config.CConfig
import moe.nea.caelo.util.MC
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
import net.minecraft.util.BlockPos

object CaeloCommand : CommandBase() {
    override fun getCommandName(): String {
        return "veloxcaelo"
    }

    override fun getCommandAliases(): List<String> {
        return listOf("velox")
    }

    override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean {
        return true
    }

    override fun getCommandUsage(sender: ICommandSender?): String {
        return ""
    }

    override fun addTabCompletionOptions(
        sender: ICommandSender?,
        args: Array<out String>,
        pos: BlockPos?
    ): List<String> {
        if (args.size == 1) {
            return getListOfStringsMatchingLastWord(args, subcommands.keys)
        }
        return emptyList()
    }

    private val subcommands = mutableMapOf<String, (args: Array<String>) -> Unit>()

    fun subcommand(name: String, function: (args: Array<String>) -> Unit) {
        subcommands[name] = function
    }

    override fun processCommand(iCommandSender: ICommandSender?, args: Array<String>) {
        if (args.isEmpty()) {
            Caelo.toOpen = CConfig.managed.getGui()
            return
        }
        val subCommand = subcommands[args[0]]
        if (subCommand == null) {
            MC.display("§cInvalid subcommand. Check the tab completions.")
            return
        }
        subCommand.invoke(args)
    }
}