aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/commands/AutoBuyCommand.kt
blob: 9899d407cea7093753ef867930aa3c629758ad65 (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
package com.ambientaddons.commands

import AmbientAddons.Companion.persistentData
import com.ambientaddons.utils.Chat
import com.ambientaddons.utils.Extensions.withModPrefix
import gg.essential.universal.UChat

object AutoBuyCommand {
    fun processCommand(args: List<String>) {
        when (args.getOrNull(0)) {
            "add" -> {
                val item = args[1]
                val newPrice = args.getOrNull(2)?.toIntOrNull()
                persistentData.autoBuyItems[item] = newPrice
                persistentData.save()
                UChat.chat("§aAdded item §a§l$item §awith ${if (newPrice == null) "no maximum price." else "maximum price §a§l$newPrice"}".withModPrefix())
            }
            "remove" -> {
                val item = args[1]
                if (persistentData.autoBuyItems.contains(item)) {
                    persistentData.autoBuyItems.remove(item)
                    persistentData.save()
                    UChat.chat("§aRemoved item §a§l$item§a.".withModPrefix())
                } else UChat.chat("§cItem §c§l$item §cdoes not exist!".withModPrefix())
            }
            "list" -> {
                UChat.chat(Chat.getChatBreak())
                UChat.chat("§b§lAutobuy List")
                persistentData.autoBuyItems.forEach {
                    if (it.value == null) {
                        UChat.chat(" §a${it.key}")
                    } else {
                        UChat.chat(" §a${it.key} §e(maximum price §a§l${it.value} §ecoins)")
                    }
                }
                UChat.chat(Chat.getChatBreak())
            }
            else -> {
                UChat.chat("""
                    ${Chat.getChatBreak()}
                    §b§lUsage:
                     §a/ambient buy add <Skyblock ID> [max price] §eto add an item.           
                     §a/ambient buy remove <Skyblock ID> §eto remove an item.
                     §a/ambient buy list §eto view current autobuy list
                    ${Chat.getChatBreak()}
                """.trimIndent())
            }
        }
    }
}