diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-06-21 07:39:24 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 23:39:24 +0200 |
commit | d534f73b63578d384c7a69462ca18cf0883926f5 (patch) | |
tree | 80e21e1f0ec41c5dee47712c5d2144281afeb0e7 /src/main | |
parent | 6410dcf999a08d4b6625fdc25f2db148c9df8338 (diff) | |
download | skyhanni-d534f73b63578d384c7a69462ca18cf0883926f5.tar.gz skyhanni-d534f73b63578d384c7a69462ca18cf0883926f5.tar.bz2 skyhanni-d534f73b63578d384c7a69462ca18cf0883926f5.zip |
Backend: Remove deprecated function ChatUtils.error (#2021)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
12 files changed, 85 insertions, 94 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index fdd4d23d2..7599cc80f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -318,33 +318,20 @@ object HypixelData { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!LorenzUtils.inSkyBlock) { - // Modified from NEU. - // NEU does not send locraw when not in SkyBlock. - // So, as requested by Hannibal, use locraw from - // NEU and have NEU send it. - // Remove this when NEU dependency is removed - if (LorenzUtils.onHypixel && locrawData == null && lastLocRaw.passedSince() > 15.seconds) { - lastLocRaw = SimpleTimeMark.now() - thread(start = true) { - Thread.sleep(1000) - NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw") - } - } + checkNEULocraw() } - if (LorenzUtils.onHypixel) { - if (LorenzUtils.inSkyBlock) { - loop@ for (line in ScoreboardData.sidebarLinesFormatted) { - skyblockAreaPattern.matchMatcher(line) { - val originalLocation = group("area") - skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation - skyBlockAreaWithSymbol = line.trim() - break@loop - } + if (LorenzUtils.onHypixel && LorenzUtils.inSkyBlock) { + loop@ for (line in ScoreboardData.sidebarLinesFormatted) { + skyblockAreaPattern.matchMatcher(line) { + val originalLocation = group("area") + skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation + skyBlockAreaWithSymbol = line.trim() + break@loop } - - checkProfileName() } + + checkProfileName() } if (!LorenzUtils.onHypixel) { @@ -368,6 +355,21 @@ object HypixelData { skyBlock = inSkyBlock } + // Modified from NEU. + // NEU does not send locraw when not in SkyBlock. + // So, as requested by Hannibal, use locraw from + // NEU and have NEU send it. + // Remove this when NEU dependency is removed + private fun checkNEULocraw() { + if (LorenzUtils.onHypixel && locrawData == null && lastLocRaw.passedSince() > 15.seconds) { + lastLocRaw = SimpleTimeMark.now() + thread(start = true) { + Thread.sleep(1000) + NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw") + } + } + } + @SubscribeEvent fun onTabListUpdate(event: WidgetUpdateEvent) { when (event.widget) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt index 358b00c9c..2080a1354 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt @@ -8,8 +8,12 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.chat.Text +import at.hannibal2.skyhanni.utils.chat.Text.asComponent +import at.hannibal2.skyhanni.utils.chat.Text.send import com.google.gson.JsonObject import net.minecraft.client.Minecraft +import net.minecraft.util.IChatComponent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.apache.commons.io.FileUtils import java.io.BufferedReader @@ -98,15 +102,16 @@ class RepoManager(private val configLocation: File) { } if (latestRepoCommit == null || latestRepoCommit!!.isEmpty()) return@supplyAsync false val file = File(configLocation, "repo") - if (file.exists() && currentCommitJSON != null && currentCommitJSON["sha"].asString == latestRepoCommit + if (file.exists() && + currentCommitJSON?.get("sha")?.asString == latestRepoCommit && + unsuccessfulConstants.isEmpty() && + lastRepoUpdate.passedSince() < 1.minutes ) { - if (unsuccessfulConstants.isEmpty() && lastRepoUpdate.passedSince() < 1.minutes) { - if (command) { - ChatUtils.chat("§7The repo is already up to date!") - atomicShouldManuallyReload.set(false) - } - return@supplyAsync false + if (command) { + ChatUtils.chat("§7The repo is already up to date!") + atomicShouldManuallyReload.set(false) } + return@supplyAsync false } lastRepoUpdate = SimpleTimeMark.now() RepoUtils.recursiveDelete(repoLocation) @@ -125,7 +130,7 @@ class RepoManager(private val configLocation: File) { urlConnection.getInputStream().use { `is` -> FileUtils.copyInputStreamToFile( `is`, - itemsZip + itemsZip, ) } } catch (e: IOException) { @@ -139,7 +144,7 @@ class RepoManager(private val configLocation: File) { } RepoUtils.unzipIgnoreFirstFolder( itemsZip.absolutePath, - repoLocation.absolutePath + repoLocation.absolutePath, ) if (currentCommitJSON == null || currentCommitJSON["sha"].asString != latestRepoCommit) { val newCurrentCommitJSON = JsonObject() @@ -187,7 +192,7 @@ class RepoManager(private val configLocation: File) { onClick = { SkyHanniMod.repo.updateRepo() }, - prefixColor = "§c" + prefixColor = "§c", ) if (unsuccessfulConstants.isEmpty()) { unsuccessfulConstants.add("All Constants") @@ -224,15 +229,19 @@ class RepoManager(private val configLocation: File) { fun displayRepoStatus(joinEvent: Boolean) { if (joinEvent) { if (unsuccessfulConstants.isNotEmpty()) { - ChatUtils.error( - "§7Repo Issue! Some features may not work. Please report this error on the Discord!\n" - + "§7Repo Auto Update Value: §c${config.repoAutoUpdate}\n" - + "§7If you have Repo Auto Update turned off, please try turning that on.\n" - + "§cUnsuccessful Constants §7(${unsuccessfulConstants.size}):" + val text = mutableListOf<IChatComponent>() + text.add( + ("§c[SkyHanni-${SkyHanniMod.version}] §7Repo Issue! Some features may not work. " + + "Please report this error on the Discord!").asComponent(), ) + text.add("§7Repo Auto Update Value: §c${config.repoAutoUpdate}".asComponent()) + text.add("§7If you have Repo Auto Update turned off, please try turning that on.".asComponent()) + text.add("§cUnsuccessful Constants §7(${unsuccessfulConstants.size}):".asComponent()) + for (constant in unsuccessfulConstants) { - ChatUtils.chat(" §e- §7$constant") + text.add(" §e- §7$constant".asComponent()) } + Text.multiline(text).send() } return } @@ -243,7 +252,7 @@ class RepoManager(private val configLocation: File) { ChatUtils.chat("Repo has errors! Commit has: ${latestRepoCommit ?: "null"}", prefixColor = "§c") if (successfulConstants.isNotEmpty()) ChatUtils.chat( "Successful Constants §7(${successfulConstants.size}):", - prefixColor = "§a" + prefixColor = "§a", ) for (constant in successfulConstants) { ChatUtils.chat(" §a- §7$constant", false) @@ -262,8 +271,8 @@ class RepoManager(private val configLocation: File) { BufferedReader( InputStreamReader( FileInputStream(file), - StandardCharsets.UTF_8 - ) + StandardCharsets.UTF_8, + ), ).use { reader -> return gson.fromJson(reader, JsonObject::class.java) } @@ -291,8 +300,8 @@ class RepoManager(private val configLocation: File) { BufferedWriter( OutputStreamWriter( FileOutputStream(file), - StandardCharsets.UTF_8 - ) + StandardCharsets.UTF_8, + ), ).use { writer -> writer.write(gson.toJson(json)) } } @@ -318,11 +327,13 @@ class RepoManager(private val configLocation: File) { name = defaultName branch = defaultBranch if (manual) { - ChatUtils.clickableChat("Reset Repo settings to default. " + - "Click §aUpdate Repo Now §ein config or run /shupdaterepo to update!", + ChatUtils.clickableChat( + "Reset Repo settings to default. " + + "Click §aUpdate Repo Now §ein config or run /shupdaterepo to update!", onClick = { updateRepo() - }) + }, + ) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt index f957b75ff..f5566e278 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt @@ -1,11 +1,13 @@ package at.hannibal2.skyhanni.events +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.EventCounter import at.hannibal2.skyhanni.mixins.hooks.getValue import at.hannibal2.skyhanni.mixins.hooks.setValue import at.hannibal2.skyhanni.mixins.transformers.AccessorEventBus import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.chat.Text import at.hannibal2.skyhanni.utils.system.PlatformUtils import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.common.eventhandler.Event @@ -60,7 +62,11 @@ abstract class LorenzEvent : Event() { eventHandlerDepth-- if (errors > visibleErrors) { val hiddenErrors = errors - visibleErrors - ChatUtils.error("$hiddenErrors more errors in $eventName are hidden!") + ChatUtils.chat( + Text.text( + "§c[SkyHanni-${SkyHanniMod.version}] $hiddenErrors more errors in $eventName are hidden!", + ), + ) } return if (isCancelable) isCanceled else false } diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt index 7da6d6704..baacbfa43 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostUtil.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.combat.ghostcounter import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision @@ -85,7 +86,7 @@ object GhostUtil { c.ctDataImported = true ChatUtils.chat("§aImported data successfully!") } else - ChatUtils.error("GhostCounterV3 ChatTriggers module not found!") + ErrorManager.skyHanniError("GhostCounterV3 ChatTriggers module not found!") } fun String.formatText(option: GhostData.Option) = formatText(option.getInt(), option.getInt(true)) diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index d9539fe15..e9e4ebd5a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.events.diana.InquisitorFoundEvent import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.editCopy import at.hannibal2.skyhanni.utils.EntityUtils @@ -49,7 +50,7 @@ object InquisitorWaypointShare { "(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ,]+),? y: (?<y>[^ ,]+),? z: (?<z>[^ ,]+)" ) - //Support for https://www.chattriggers.com/modules/v/inquisitorchecker + // Support for https://www.chattriggers.com/modules/v/inquisitorchecker /** * REGEX-TEST: §9Party §8> UserName§f: §rA MINOS INQUISITOR has spawned near [Foraging Island ] at Coords 1 2 3 */ @@ -108,7 +109,7 @@ object InquisitorWaypointShare { inquisitorsNearby = emptyList() } - val inquisitorTime = mutableListOf<SimpleTimeMark>() + private val inquisitorTime = mutableListOf<SimpleTimeMark>() @HandleEvent fun onInquisitorFound(event: InquisitorFoundEvent) { @@ -194,14 +195,13 @@ object InquisitorWaypointShare { HypixelCommands.partyChat("Inquisitor dead!") } - fun sendInquisitor() { + private fun sendInquisitor() { if (!isEnabled()) return if (lastShareTime.passedSince() < 5.seconds) return lastShareTime = SimpleTimeMark.now() if (inquisitor == -1) { - ChatUtils.error("No Inquisitor Found!") - return + ErrorManager.skyHanniError("No Inquisitor Found!") } val inquisitor = EntityUtils.getEntityByID(inquisitor) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt index f7ca31109..d49de324c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestAPI.kt @@ -281,10 +281,9 @@ object PestAPI { } private fun removeNearestPest() { - val plot = getNearestInfestedPlot() ?: run { - ChatUtils.error("Can not remove nearest pest: No infested plots detected.") - return - } + val plot = getNearestInfestedPlot() + ?: ErrorManager.skyHanniError("Can not remove nearest pest: No infested plots detected.") + if (!plot.isPestCountInaccurate) plot.pests-- scoreboardPests-- updatePests() diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt index f7944fcde..3fad28589 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -14,7 +14,7 @@ import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavatorAPI import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.features.rift.RiftAPI.motesNpcPrice import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.equalsOneOf import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName @@ -134,7 +134,7 @@ object HideNotClickableItems { event.toolTip.add("") if (hideReason == "") { event.toolTip.add("§4No hide reason!") - ChatUtils.error("No hide reason for not clickable item!") + ErrorManager.skyHanniError("No hide reason for not clickable item!") } else { event.toolTip.add("§c$hideReason") if (config.itemsBypass && !hideReason.contains("SkyBlock Menu")) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt index f0722c8df..7ad645259 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/tiarelay/TiaRelayHelper.kt @@ -75,7 +75,7 @@ object TiaRelayHelper { val name = sounds.values.first().name for (sound in sounds.toMutableMap()) { if (sound.value.name != name) { - ChatUtils.error("Tia Relay Helper error: Too much background noise! Try turning off the music and then try again.") + ChatUtils.userError("Tia Relay Helper error: Too much background noise! Try turning off the music and then try again.") ChatUtils.clickableChat("Click here to run /togglemusic", onClick = { HypixelCommands.toggleMusic() }) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt index 20cd0bcdc..2741605ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt @@ -157,7 +157,7 @@ object QuickModMenuSwitch { } catch (_: Exception) { } } - ChatUtils.error("Error trying to open the gui for mod " + mod.name + "!") + ErrorManager.skyHanniError("Error trying to open the gui for mod " + mod.name + "!") } "hytil" -> { diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index 466a632fe..4a0fb0013 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -20,6 +20,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.getBazaarData import at.hannibal2.skyhanni.features.mining.OreBlock import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.BlockUtils import at.hannibal2.skyhanni.utils.BlockUtils.getBlockStateAt import at.hannibal2.skyhanni.utils.ChatUtils @@ -363,10 +364,7 @@ object SkyHanniDebugsAndTests { } val internalName = hand.getInternalNameOrNull() - if (internalName == null) { - ChatUtils.error("§cInternal name is null for item ${hand.name}") - return - } + ?: ErrorManager.skyHanniError("Internal name is null for item ${hand.name}") val rawInternalName = internalName.asString() OSUtils.copyToClipboard(rawInternalName) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt index aff0e745a..664def423 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt @@ -33,7 +33,6 @@ object ChatUtils { private const val DEBUG_PREFIX = "[SkyHanni Debug] §7" private const val USER_ERROR_PREFIX = "§c[SkyHanni] " - private val ERROR_PREFIX by lazy { "§c[SkyHanni-${SkyHanniMod.version}] " } private const val CHAT_PREFIX = "[SkyHanni] " /** @@ -63,28 +62,6 @@ object ChatUtils { } /** - * Sends a message to the user that an error occurred caused by something in the code. - * This should be used for errors that are not caused by the user. - * - * Why deprecate this? Even if this message is descriptive for the user and the developer, - * we don't want inconsistencies in errors, and we would need to search - * for the code line where this error gets printed any way. - * So it's better to use the stack trace still. - * - * @param message The message to be sent - * - * @see ERROR_PREFIX - */ - @Deprecated( - "Do not send the user a non clickable non stacktrace containing error message.", - ReplaceWith("ErrorManager.logErrorStateWithData(message)") - ) - fun error(message: String) { - println("error: '$message'") - internalChat(ERROR_PREFIX + message) - } - - /** * Sends a message to the user * @param message The message to be sent * @param prefix Whether to prefix the message with the chat prefix, default true diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 6af19e382..54cdfa91e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches -import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated @@ -61,10 +60,8 @@ object ItemUtils { fun getItemsInInventory(withCursorItem: Boolean = false): List<ItemStack> { val list: LinkedList<ItemStack> = LinkedList() val player = Minecraft.getMinecraft().thePlayer - if (player == null) { - ChatUtils.error("getItemsInInventoryWithSlots: player is null!") - return list - } + ?: ErrorManager.skyHanniError("getItemsInInventoryWithSlots: player is null!") + for (slot in player.openContainer.inventorySlots) { if (slot.hasStack) { list.add(slot.stack) |