aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/LorenzRarity.kt
blob: 35868027f58f5febfcb5eeda75207667ceb553ab (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
61
62
63
64
65
66
67
68
69
70
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import net.minecraft.item.ItemStack


// TODO: replace id with ordinal
enum class LorenzRarity(val color: LorenzColor, val id: Int) {
    COMMON(LorenzColor.WHITE, 0),
    UNCOMMON(LorenzColor.GREEN, 1),
    RARE(LorenzColor.BLUE, 2),
    EPIC(LorenzColor.DARK_PURPLE, 3),
    LEGENDARY(LorenzColor.GOLD, 4),
    MYTHIC(LorenzColor.LIGHT_PURPLE, 5),
    DIVINE(LorenzColor.AQUA, 6),
    SUPREME(LorenzColor.DARK_RED, 7),
    SPECIAL(LorenzColor.RED, 8),
    VERY_SPECIAL(LorenzColor.RED, 9),
    ;

    val chatColorCode by lazy { color.getChatColor() }
    private val rawName by lazy { name.replace("_", " ") }
    private val normalName by lazy { "$chatColorCode§l$rawName" }
    private val recombName by lazy { "$chatColorCode§l§ka§r $chatColorCode§l$chatColorCode§l$rawName" }

    //§d§l§ka§r §d§l§d§lMYTHIC

    fun oneBelow(logError: Boolean = true): LorenzRarity? {
        val rarityBelow = getById(ordinal - 1)
        if (rarityBelow == null && logError) {
            ErrorManager.logErrorStateWithData(
                "Problem with item rarity detected.",
                "Trying to get an item rarity below common",
                "ordinal" to ordinal
            )
        }
        return rarityBelow
    }

    fun oneAbove(logError: Boolean = true): LorenzRarity? {
        val rarityBelow = getById(ordinal + 1)
        if (rarityBelow == null && logError) {
            ErrorManager.logErrorStateWithData(
                "Problem with item rarity detected.",
                "Trying to get an item rarity above special",
                "ordinal" to ordinal
            )
        }
        return rarityBelow
    }

    companion object {
        fun getById(id: Int) = entries.firstOrNull { it.ordinal == id }
        fun getByName(name: String) = entries.firstOrNull { it.name == name }

        fun readItemRarity(itemStack: ItemStack): LorenzRarity? {
            for (line in itemStack.getLore()) {
                val string = line.replace("SHINY ", "")
                for (rarity in LorenzRarity.entries) {
                    if (string.startsWith(rarity.normalName) || string.startsWith(rarity.recombName)) {
                        return rarity
                    }
                }
            }
            return null
        }
    }

}