Skip to content

Commit

Permalink
Backend: Remove deprecated function ChatUtils.error (hannibal002#2021)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
CalMWolfs and hannibal002 authored Jun 20, 2024
1 parent 6410dcf commit d534f73
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 94 deletions.
48 changes: 25 additions & 23 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
59 changes: 35 additions & 24 deletions src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -125,7 +130,7 @@ class RepoManager(private val configLocation: File) {
urlConnection.getInputStream().use { `is` ->
FileUtils.copyInputStreamToFile(
`is`,
itemsZip
itemsZip,
)
}
} catch (e: IOException) {
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)) }
}

Expand All @@ -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()
})
},
)
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -108,7 +109,7 @@ object InquisitorWaypointShare {
inquisitorsNearby = emptyList()
}

val inquisitorTime = mutableListOf<SimpleTimeMark>()
private val inquisitorTime = mutableListOf<SimpleTimeMark>()

@HandleEvent
fun onInquisitorFound(event: InquisitorFoundEvent) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 0 additions & 23 deletions src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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] "

/**
Expand Down Expand Up @@ -62,28 +61,6 @@ object ChatUtils {
internalChat(USER_ERROR_PREFIX + message)
}

/**
* 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
Expand Down
Loading

0 comments on commit d534f73

Please sign in to comment.