diff options
| author | Cal <cwolfson58@gmail.com> | 2024-10-30 11:54:17 +1100 |
|---|---|---|
| committer | Cal <cwolfson58@gmail.com> | 2024-10-30 11:54:17 +1100 |
| commit | 09494f6e0a48e619c486b073189e24288400d689 (patch) | |
| tree | 055af622ed4dc4cdedcb3ecb14c3662194378210 /src/main/java/at | |
| parent | 2dc24ced9d10a0fda4df70c90471499abd66595b (diff) | |
| parent | 3f4bdbab85ba6b54a54b99b23e176d52910c8d66 (diff) | |
| download | SkyHanni-09494f6e0a48e619c486b073189e24288400d689.tar.gz SkyHanni-09494f6e0a48e619c486b073189e24288400d689.tar.bz2 SkyHanni-09494f6e0a48e619c486b073189e24288400d689.zip | |
Merge branch 'refs/heads/beta' into fork/nea89o/formattedtextcompat
# Conflicts:
# build.gradle.kts
Diffstat (limited to 'src/main/java/at')
73 files changed, 799 insertions, 500 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt b/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt index 63d3e14cf..040ecc43c 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/event/EventHandler.kt @@ -2,12 +2,15 @@ package at.hannibal2.skyhanni.api.event import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.mixins.hooks.getValue +import at.hannibal2.skyhanni.mixins.hooks.setValue import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.inAnyIsland import at.hannibal2.skyhanni.utils.StringUtils import at.hannibal2.skyhanni.utils.chat.Text +import at.hannibal2.skyhanni.utils.system.PlatformUtils class EventHandler<T : SkyHanniEvent> private constructor( val name: String, @@ -21,9 +24,24 @@ class EventHandler<T : SkyHanniEvent> private constructor( constructor(event: Class<T>, listeners: List<EventListeners.Listener>) : this( (event.name.split(".").lastOrNull() ?: event.name).replace("$", "."), listeners.sortedBy { it.options.priority }.toList(), - listeners.any { it.options.receiveCancelled } + listeners.any { it.options.receiveCancelled }, ) + companion object { + private var eventHandlerDepth by object : ThreadLocal<Int>() { + override fun initialValue(): Int { + return 0 + } + } + + /** + * Returns true if the current thread is in an event handler. This is because the event handler catches exceptions which means + * that we are free to throw exceptions in the event handler without crashing the game. + * We also return true if we are in a dev environment to alert the developer of any errors effectively. + */ + val isInEventHandler get() = eventHandlerDepth > 0 || PlatformUtils.isDevEnvironment + } + fun post(event: T, onError: ((Throwable) -> Unit)? = null): Boolean { invokeCount++ if (this.listeners.isEmpty()) return false @@ -32,6 +50,7 @@ class EventHandler<T : SkyHanniEvent> private constructor( var errors = 0 + eventHandlerDepth++ for (listener in listeners) { if (!shouldInvoke(event, listener)) continue try { @@ -48,13 +67,14 @@ class EventHandler<T : SkyHanniEvent> private constructor( } if (event.isCancelled && !canReceiveCancelled) break } + eventHandlerDepth-- if (errors > 3) { val hiddenErrors = errors - 3 ChatUtils.chat( Text.text( - "§c[SkyHanni/${SkyHanniMod.version}] $hiddenErrors more errors in $name are hidden!" - ) + "§c[SkyHanni/${SkyHanniMod.version}] $hiddenErrors more errors in $name are hidden!", + ), ) } return event.isCancelled diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index b82d4d8f9..a534eac89 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.event.EventHandler import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.config.core.config.PositionList import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson @@ -96,7 +97,7 @@ class ConfigManager { try { findPositionLinks(features, mutableSetOf()) } catch (e: Exception) { - if (LorenzEvent.isInGuardedEventHandler) throw e + if (LorenzEvent.isInGuardedEventHandler || EventHandler.isInEventHandler) throw e } } diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index f8afe645c..d90ce7730 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - const val CONFIG_VERSION = 63 + const val CONFIG_VERSION = 64 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt index 0adf1bed5..bd50b46e3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt @@ -30,7 +30,6 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.NumberUtil.roundTo import at.hannibal2.skyhanni.utils.compat.GuiScreenUtils import at.hannibal2.skyhanni.utils.compat.SkyhanniBaseScreen -import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.GlStateManager import org.lwjgl.input.Keyboard @@ -115,8 +114,9 @@ class GuiPositionEditor( GlStateManager.pushMatrix() width = getScaledWidth() height = getScaledHeight() - val mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth - val mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + + val (mouseX, mouseY) = GuiScreenUtils.mousePos + for ((index, position) in positions.withIndex()) { var elementWidth = position.getDummySize(true).x var elementHeight = position.getDummySize(true).y @@ -154,8 +154,8 @@ class GuiPositionEditor( override fun mouseClicked(originalX: Int, priginalY: Int, mouseButton: Int) { super.mouseClicked(originalX, priginalY, mouseButton) - val mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth - val mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + val (mouseX, mouseY) = GuiScreenUtils.mousePos + for (i in positions.indices.reversed()) { val position = positions[i] val elementWidth = position.getDummySize().x @@ -222,8 +222,8 @@ class GuiPositionEditor( for (position in positions) { if (!position.clicked) continue - val mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth - val mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1 + val (mouseX, mouseY) = GuiScreenUtils.mousePos + val elementWidth = position.getDummySize(true).x val elementHeight = position.getDummySize(true).y grabbedX += position.moveX(mouseX - grabbedX, elementWidth) @@ -236,13 +236,14 @@ class GuiPositionEditor( super.handleMouseInput() val mw = Mouse.getEventDWheel() if (mw == 0) return - val mx = Mouse.getEventX() * width / mc.displayWidth - val my = height - Mouse.getEventY() * height / mc.displayHeight - 1 + + val (mouseX, mouseY) = GuiScreenUtils.mousePos + val hovered = positions.firstOrNull { it.clicked } ?: positions.lastOrNull { val size = it.getDummySize() GuiRenderUtils.isPointInRect( - mx, my, + mouseX, mouseY, it.getAbsX() - border, it.getAbsY() - border, size.x + border * 2, size.y + border * 2, ) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java index 738f24c93..378242b7b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/chat/StashConfig.java @@ -24,13 +24,18 @@ public class StashConfig { public String notice = ""; @Expose + @ConfigOption(name = "Hide Added Messages", desc = "Hide the messages when something is added to your stash.") + @ConfigEditorBoolean + public boolean hideAddedMessages = true; + + @Expose @ConfigOption(name = "Hide Duplicate Warnings", desc = "Hide duplicate warnings for previously reported stash counts.") @ConfigEditorBoolean public boolean hideDuplicateCounts = true; @Expose @ConfigOption(name = "Hide Low Warnings", desc = "Hide warnings with a total count below this number.") - @ConfigEditorSlider(minValue = 0, maxValue = 1000000, minStep = 100) + @ConfigEditorSlider(minValue = 0, maxValue = 1_000_000, minStep = 100) public int hideLowWarningsThreshold = 0; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java index 56a17dfb9..4607ab8df 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.config.features.dev; import at.hannibal2.skyhanni.config.core.config.Position; -import at.hannibal2.skyh |
