diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-08-14 12:41:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 12:41:29 +0200 |
commit | 0a027ea5dac41002a460a2627d5c4ff3820c271d (patch) | |
tree | 0bebf33c70517b24c2fdbba27b63182172a1a3cb /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 085240750f346d8f5e57b3f2b5bef3ec31c44763 (diff) | |
download | skyhanni-0a027ea5dac41002a460a2627d5c4ff3820c271d.tar.gz skyhanni-0a027ea5dac41002a460a2627d5c4ff3820c271d.tar.bz2 skyhanni-0a027ea5dac41002a460a2627d5c4ff3820c271d.zip |
Improvement: Repo Errors (#2338)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
3 files changed, 57 insertions, 17 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 95dad660c..cd55107db 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.data.PetAPI +import at.hannibal2.skyhanni.events.DebugDataCollectEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -14,7 +16,9 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.removeResets +import com.google.common.collect.Lists import io.github.moulberry.notenoughupdates.recipes.NeuRecipe +import io.github.moulberry.notenoughupdates.util.NotificationHandler import net.minecraft.client.Minecraft import net.minecraft.init.Items import net.minecraft.item.ItemStack @@ -22,14 +26,18 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagList import net.minecraft.nbt.NBTTagString import net.minecraftforge.common.util.Constants +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.LinkedList import java.util.regex.Matcher import kotlin.time.Duration.Companion.seconds +@SkyHanniModule object ItemUtils { private val itemNameCache = mutableMapOf<NEUInternalName, String>() // internal name -> item name + private val missingRepoItems = mutableSetOf<String>() + fun ItemStack.cleanName() = this.displayName.removeColor() fun isSack(stack: ItemStack) = stack.getInternalName().endsWith("_SACK") && stack.cleanName().endsWith(" Sack") @@ -264,7 +272,7 @@ object ItemUtils { */ var ItemStack.name: String get() = this.displayName ?: ErrorManager.skyHanniError( - "Could not get name if ItemStack", + "Could not get name of ItemStack", "itemStack" to this, "displayName" to displayName, "internal name" to getInternalNameOrNull(), @@ -360,7 +368,11 @@ object ItemUtils { } val itemStack = getItemStackOrNull() - val name = itemStack?.name ?: error("Could not find item name for $this") + val name = itemStack?.name ?: run { + val name = toString() + addMissingRepoItem(name, "Could not find item name for $name") + return "§c$name" + } // show enchanted book name if (itemStack.getItemCategoryOrNull() == ItemCategory.ENCHANTED_BOOK) { @@ -411,4 +423,39 @@ object ItemUtils { it.key.getPrice(pastRecipes = pastRecipes) * it.value }.sum() + @SubscribeEvent + fun onDebugDataCollect(event: DebugDataCollectEvent) { + event.title("Missing Repo Items") + + if (missingRepoItems.isNotEmpty()) { + event.addData { + add("Detected ${missingRepoItems.size} missing items:") + for (itemName in missingRepoItems) { + add(" - $itemName") + } + } + } else { + event.addIrrelevant("No Repo Item fails detected.") + } + } + + fun addMissingRepoItem(name: String, message: String) { + if (!missingRepoItems.add(name)) return + ChatUtils.debug(message) +// showRepoWarning() + } + + // Running NEU's function `Utils.showOutdatedRepoNotification()` caused a NoSuchMethodError in dev env. + // Therefore we run NotificationHandler.displayNotification directly + private fun showRepoWarning() { + NotificationHandler.displayNotification( + Lists.newArrayList( + "§c§lMissing repo data", + "§cData used for some SkyHanni features is not up to date, this should normally not be the case.", + "§cYou can try §l/neuresetrepo§r§c and restart your game to see if that fixes the issue.", + "§cIf the problem persists please join the SkyHanni Discord and message in §l#support§r§c to get support.", + ), + true, true, + ) + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt index 98f903468..18568869a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -1,7 +1,5 @@ package at.hannibal2.skyhanni.utils -import at.hannibal2.skyhanni.test.command.ErrorManager - class NEUInternalName private constructor(private val internalName: String) { companion object { @@ -24,11 +22,11 @@ class NEUInternalName private constructor(private val internalName: String) { fun fromItemNameOrNull(itemName: String): NEUInternalName? = ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet")) - fun fromItemName(itemName: String): NEUInternalName = - fromItemNameOrNull(itemName) ?: ErrorManager.skyHanniError( - "NEUInternalName is null for item name: '$itemName'", - "inventoryName" to InventoryUtils.openInventoryName() - ) + fun fromItemName(itemName: String): NEUInternalName = fromItemNameOrNull(itemName) ?: run { + val name = "itemName:$itemName" + ItemUtils.addMissingRepoItem(name, "Could not find internal name for $name") + return NEUInternalName.MISSING_ITEM + } } fun asString() = internalName diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index ae3863410..b7cf23eeb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -197,14 +197,9 @@ object NEUItems { getItemStackOrNull() ?: run { getPriceOrNullNew() ?: return@run fallbackItem if (ignoreItemsFilter.match(this.asString())) return@run fallbackItem - ErrorManager.logErrorWithData( - IllegalStateException("Something went wrong!"), - "Encountered an error getting the item for §7$this§c. " + - "This may be because your NEU repo is outdated. Please ask in the SkyHanni " + - "Discord if this is the case.", - "Item name" to this.asString(), - "repo commit" to manager.latestRepoCommit, - ) + + val name = this.toString() + ItemUtils.addMissingRepoItem(name, "Could not create item stack for $name") fallbackItem } |