diff --git a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt index 2595e83ca..799cce2e6 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ContainerSellValue.kt @@ -27,7 +27,7 @@ import gg.skytils.skytilsmod.core.structure.GuiElement import gg.skytils.skytilsmod.core.tickTimer import gg.skytils.skytilsmod.events.impl.GuiContainerEvent import gg.skytils.skytilsmod.features.impl.handlers.AuctionData -import gg.skytils.skytilsmod.mixins.hooks.item.masterStarPattern +import gg.skytils.skytilsmod.mixins.hooks.item.masterStarRegex import gg.skytils.skytilsmod.mixins.hooks.item.masterStars import gg.skytils.skytilsmod.utils.* import gg.skytils.skytilsmod.utils.Utils.inDungeons @@ -158,8 +158,8 @@ object ContainerSellValue { } ?: 0.0 val masterStarCount = - if (itemStack.displayName?.contains("✪") == true) masterStarPattern.find(itemStack.displayName)?.let { - masterStars.indexOf(it.value.last()) + 1 + if (itemStack.displayName?.contains("✪") == true) masterStarRegex.find(itemStack.displayName)?.destructured?.let { (tier) -> + masterStars.indexOf(tier) + 1 } ?: 0 else 0 val masterStarValue = if (masterStarCount > 0) (1..masterStarCount).sumOf { i -> AuctionData.lowestBINs[listOf("FIRST", "SECOND", "THIRD", "FOURTH", "FIFTH")[i - 1] + "_MASTER_STAR"] ?: 0.0 diff --git a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt index 8ef80cea4..0d1b72f7f 100644 --- a/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt +++ b/src/main/kotlin/gg/skytils/skytilsmod/mixins/hooks/item/ItemStackHook.kt @@ -27,9 +27,10 @@ import gg.skytils.skytilsmod.utils.ifNull import net.minecraft.item.ItemStack import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable -const val starPattern = "§6✪" -val masterStars = ('➊'..'➎').toList() -val masterStarPattern = Regex("§c[${masterStars.joinToString("")}]") +const val star = "✪" +val masterStars = ('➊'..'➎').map { it.toString() } +val starRegex = Regex("§6${star}+") +val masterStarRegex = Regex("§c(?[${masterStars.joinToString("")}])") fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable) { (stack as ItemStack).apply { @@ -54,32 +55,28 @@ fun showEnchantmentGlint(stack: Any, cir: CallbackInfoReturnable) { } } -fun modifyDisplayName(s: String): String { - var displayName = s - if (!Utils.inSkyblock) return displayName +fun modifyDisplayName(displayName: String): String { + if (!Utils.inSkyblock || Skytils.config.starDisplayType == 0 || !displayName.contains(star)) return displayName + try { - if (Skytils.config.starDisplayType != 0 && displayName.contains("✪")) { - if (Skytils.config.starDisplayType == 2) { - masterStarPattern.find(displayName)?.let { - val star = it.value.last() - val count = masterStars.indexOf(star) + 1 + 5 - displayName = "${ - displayName.replace(starPattern, "") - .replace(masterStarPattern, "") - }§c${count}✪" - }.ifNull { - displayName = "${displayName.replace(starPattern, "")}§6${displayName.countMatches(starPattern)}✪" - } - } else if (Skytils.config.starDisplayType == 1) { - masterStarPattern.find(displayName)?.let { - val star = it.value.last() - val count = masterStars.indexOf(star) + 1 - displayName = displayName.replace(masterStarPattern, "") - .replaceFirst(starPattern.repeat(count), "§c✪".repeat(count)) + when (Skytils.config.starDisplayType) { + 1 -> { + masterStarRegex.find(displayName)?.destructured?.let { (tier) -> + val count = masterStars.indexOf(tier) + 1 + + return displayName.replace(masterStarRegex, "") + .replaceFirst("§6" + star.repeat(count), "§c" + star.repeat(count) + "§6") } } + + 2 -> { + masterStarRegex.find(displayName)?.destructured?.let { (tier) -> + val count = masterStars.indexOf(tier) + 1 + 5 + return displayName.replace(starRegex, "").replace(masterStarRegex, "") + "§c$count$star" + } ?: return displayName.replace(starRegex, "") + "§6${displayName.countMatches(star)}$star" + } } - } catch (ignored: Exception) { - } + } catch (ignored: Exception) { } + return displayName } \ No newline at end of file