aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ChatClickActionManager.kt36
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt28
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt2
6 files changed, 80 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index 2156872aa..2290b8eac 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.SkillAPI
import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigGuiManager
+import at.hannibal2.skyhanni.data.ChatClickActionManager
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix
import at.hannibal2.skyhanni.data.GuiEditManager
@@ -489,6 +490,7 @@ object Commands {
registerCommand("shsendcontests", "") { GardenNextJacobContest.shareContestConfirmed(it) }
registerCommand("shwords", "Opens the config list for modifying visual words") { openVisualWords() }
registerCommand("shstopaccountupgradereminder", "") { AccountUpgradeReminder.disable() }
+ registerCommand("shaction", "") { ChatClickActionManager.onCommand(it) }
}
private fun shortenedCommands() {
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatClickActionManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatClickActionManager.kt
new file mode 100644
index 000000000..2f283fe01
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/ChatClickActionManager.kt
@@ -0,0 +1,36 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.StringUtils
+
+object ChatClickActionManager {
+
+ private val actions = mutableListOf<ClickableAction>()
+
+ fun oneTimeClick(message: String, onClick: () -> Any) {
+ val action = ClickableAction(StringUtils.generateRandomId(), message, onClick)
+ actions.add(action)
+ action.sendToChat()
+ }
+
+ private fun ClickableAction.sendToChat() {
+ ChatUtils.clickableChat(message, "shaction $token")
+ }
+
+ fun onCommand(args: Array<String>) {
+ if (args.size == 1) {
+ getActionByToken(args[0])?.runAction()
+ }
+ }
+
+ private fun ClickableAction.runAction() {
+ onClick()
+ if (oneTime) {
+ actions.remove(this)
+ }
+ }
+
+ private fun getActionByToken(token: String) = actions.find { it.token == token }
+
+ class ClickableAction(val token: String, val message: String, val onClick: () -> Any, val oneTime: Boolean = true)
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
index 78fbf6731..9bff45019 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
@@ -37,27 +37,45 @@ object TrophyFishManager {
loadedNeu = true
- val savedFish = fish ?: return
+ val savedFishes = fish ?: return
var changed = false
+ val neuData = mutableListOf<Triple<String, TrophyRarity, Int>>()
for ((fishName, apiAmount) in caughtTrophyFish) {
val rarity = TrophyRarity.getByName(fishName) ?: continue
val name = fishName.split("_").dropLast(1).joinToString("")
- val savedFishData = savedFish.getOrPut(name) { mutableMapOf() }
+ val savedFishData = savedFishes.getOrPut(name) { mutableMapOf() }
val currentSavedAmount = savedFishData[rarity] ?: 0
+ neuData.add(Triple(name, rarity, apiAmount))
if (apiAmount > currentSavedAmount) {
- savedFishData[rarity] = apiAmount
- ChatUtils.debug("Updated trophy fishing data from NEU PV: $name $rarity: $currentSavedAmount -> $apiAmount")
changed = true
}
}
if (changed) {
- ChatUtils.chat("Updated Trophy Fishing data via NEU PV!")
+ ChatUtils.clickableChat("Click here to load data from NEU PV!", onClick = {
+ updateFromNeuPv(savedFishes, neuData)
+ })
}
}
+ private fun updateFromNeuPv(
+ savedFishes: MutableMap<String, MutableMap<TrophyRarity, Int>>,
+ neuData: MutableList<Triple<String, TrophyRarity, Int>>,
+ ) {
+ for ((name, rarity, newValue) in neuData) {
+ val saved = savedFishes[name] ?: continue
+
+ val current = saved[rarity] ?: 0
+ if (newValue > current) {
+ saved[rarity] = newValue
+ ChatUtils.debug("Updated trophy fishing data from NEU PV: $name $rarity: $current -> $newValue")
+ }
+ }
+ ChatUtils.chat("Updated Trophy Fishing data via NEU PV!")
+ }
+
private var trophyFishInfo = mapOf<String, TrophyFishInfo>()
fun getInfo(internalName: String) = trophyFishInfo[internalName]
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
index e7d0fa3cb..5b369a35c 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
@@ -4,10 +4,10 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeLimitedSet
import net.minecraft.client.Minecraft
-import java.util.UUID
import kotlin.time.Duration.Companion.minutes
object ErrorManager {
@@ -134,7 +134,7 @@ object ErrorManager {
fullStackTrace = throwable.getCustomStackTrace(true).joinToString("\n")
stackTrace = throwable.getCustomStackTrace(false).joinToString("\n")
}
- val randomId = UUID.randomUUID().toString()
+ val randomId = StringUtils.generateRandomId()
val extraDataString = buildExtraDataString(extraData)
val rawMessage = message.removeColor()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
index ae04b4535..d2f12b1d0 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ChatClickActionManager
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -128,6 +129,20 @@ object ChatUtils {
}
/**
+ * Sends a message to the user that they can click and run an action
+ * @param message The message to be sent
+ * @param onClick The runnable to be executed when the message is clicked
+ * @param prefix Whether to prefix the message with the chat prefix, default true
+ * @param prefixColor Color that the prefix should be, default yellow (§e)
+ *
+ * @see CHAT_PREFIX
+ */
+ fun clickableChat(message: String, onClick: () -> Any, prefix: Boolean = true, prefixColor: String = "§e") {
+ val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
+ ChatClickActionManager.oneTimeClick(msgPrefix + message, onClick)
+ }
+
+ /**
* Sends a message to the user that they can click and run a command
* @param message The message to be sent
* @param hover The message to be shown when the message is hovered
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index a937b6f12..bcb185f60 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -299,4 +299,6 @@ object StringUtils {
fun String.isRoman(): Boolean = UtilsPatterns.isRomanPattern.matches(this)
fun isEmpty(message: String): Boolean = message.removeColor().trimWhiteSpaceAndResets().isEmpty()
+
+ fun generateRandomId() = UUID.randomUUID().toString()
}