aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
blob: 510f66f0d47c589fbcb25fd3a26ebb6af45ea12d (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
56
57
58
59
60
package at.hannibal2.skyhanni.config.commands

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigEditor
import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable
import at.hannibal2.skyhanni.config.core.GuiScreenElementWrapper
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper
import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper
import at.hannibal2.skyhanni.features.misc.CollectionCounter
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
import at.hannibal2.skyhanni.test.LorenzTest
import at.hannibal2.skyhanni.test.command.CopyItemCommand
import at.hannibal2.skyhanni.test.command.CopyNearbyEntitiesCommand
import net.minecraft.command.ICommandSender
import net.minecraftforge.client.ClientCommandHandler
import org.apache.commons.lang3.StringUtils

object Commands {

    private val openMainMenu: (Array<String>) -> Unit = {
        if (it.isNotEmpty()) {
            SkyHanniMod.screenToOpen =
                GuiScreenElementWrapper(ConfigEditor(SkyHanniMod.feature, StringUtils.join(it, " ")))
        } else {
            SkyHanniMod.screenToOpen = GuiScreenElementWrapper(ConfigEditor(SkyHanniMod.feature))
        }
    }

    fun init() {
        registerCommand("sh", openMainMenu)
        registerCommand("skyhanni", openMainMenu)
        registerCommand("shreloadlocalrepo") { SkyHanniMod.repo.reloadLocalRepo() }
        registerCommand("shupdaterepo") { SkyHanniMod.repo.updateRepo() }
        registerCommand("testhanni") { LorenzTest.testCommand(it) }
        registerCommand("copylocation") { LorenzTest.copyLocation() }
        registerCommand("copyentities") { CopyNearbyEntitiesCommand.command(it) }
        registerCommand("copyitem") { CopyItemCommand.command(it) }
        registerCommand("shconfigsave") { SkyHanniMod.configManager.saveConfig() }
        registerCommand("shmarkplayer") { MarkedPlayerManager.command(it) }
        registerCommand("togglepacketlog") { LorenzTest.togglePacketLog() }
        registerCommand("shreloadlisteners") { LorenzTest.reloadListeners() }
        registerCommand("shstoplisteners") { LorenzTest.stopListeners() }
        registerCommand("shresetburrowwarps") { BurrowWarpHelper.resetDisabledWarps() }
        registerCommand("shtrackcollection") { CollectionCounter.command(it) }
        registerCommand("shreloadbingodata") { BingoCardDisplay.command() }
        registerCommand("shprintbingohelper") { BingoNextStepHelper.command() }
    }

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

    private fun createCommand(function: (Array<String>) -> Unit) =
        object : ProcessCommandRunnable() {
            override fun processCommand(sender: ICommandSender?, args: Array<out String>) {
                function(args.asList().toTypedArray())
            }
        }
}