aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-11-19 00:02:48 +0000
committerGitHub <noreply@github.com>2023-11-19 01:02:48 +0100
commit0b1fa4dedc21e997234694d9d11805e4996b54b6 (patch)
tree7bb6d201573f0205bf9ce73f19d65a98fb128e60 /src/main/java/at/hannibal2/skyhanni/utils
parentcfa64d7f4360093523029b52dabea8e30ce966b6 (diff)
downloadskyhanni-0b1fa4dedc21e997234694d9d11805e4996b54b6.tar.gz
skyhanni-0b1fa4dedc21e997234694d9d11805e4996b54b6.tar.bz2
skyhanni-0b1fa4dedc21e997234694d9d11805e4996b54b6.zip
Internal Change: Auto-Prefix Chat Messages (#622)
Add auto prefix to chat message methods. #622
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt107
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt6
7 files changed, 109 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
index c0116f57c..5e935b407 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
@@ -60,7 +60,7 @@ object APIUtil {
} else if (retSrc.contains("<center><h1>502 Bad Gateway</h1></center>")) {
if (showApiErrors && apiName == "Hypixel API") {
LorenzUtils.clickableChat(
- "[SkyHanni] Problems with detecting the Hypixel API. §eClick here to hide this message for now.",
+ "Problems with detecting the Hypixel API. §eClick here to hide this message for now.",
"shtogglehypixelapierrors"
)
}
@@ -128,6 +128,6 @@ object APIUtil {
fun toggleApiErrorMessages() {
showApiErrors = !showApiErrors
- LorenzUtils.chat("§e[SkyHanni] Hypixel API error messages " + if (showApiErrors) "§chidden" else "§ashown")
+ LorenzUtils.chat("Hypixel API error messages " + if (showApiErrors) "§chidden" else "§ashown")
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 2c5ab63d3..0028b8e38 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -65,7 +65,7 @@ object ItemUtils {
val list: LinkedList<ItemStack> = LinkedList()
val player = Minecraft.getMinecraft().thePlayer
if (player == null) {
- LorenzUtils.warning("getItemsInInventoryWithSlots: player is null!")
+ LorenzUtils.error("getItemsInInventoryWithSlots: player is null!")
return list
}
for (slot in player.openContainer.inventorySlots) {
@@ -84,7 +84,7 @@ object ItemUtils {
val map: LinkedHashMap<ItemStack, Int> = LinkedHashMap()
val player = Minecraft.getMinecraft().thePlayer
if (player == null) {
- LorenzUtils.warning("getItemsInInventoryWithSlots: player is null!")
+ LorenzUtils.error("getItemsInInventoryWithSlots: player is null!")
return map
}
for (slot in player.openContainer.inventorySlots) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 967f183f6..683b64c3a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -64,28 +64,78 @@ object LorenzUtils {
val lastWorldSwitch get() = HypixelData.joinedWorld
- const val DEBUG_PREFIX = "[SkyHanni Debug] §7"
+ // TODO log based on chat category (error, warning, debug, user error, normal)
private val log = LorenzLogger("chat/mod_sent")
var lastButtonClicked = 0L
+ 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] "
+
+ /**
+ * Sends a debug message to the chat and the console.
+ * This is only sent if the debug feature is enabled.
+ *
+ * @param message The message to be sent
+ *
+ * @see DEBUG_PREFIX
+ */
fun debug(message: String) {
if (SkyHanniMod.feature.dev.debug.enabled && internalChat(DEBUG_PREFIX + message)) {
consoleLog("[Debug] $message")
}
}
- // TODO remove ig?
- fun warning(message: String) {
- internalChat("§cWarning! $message")
- }
-
+ /**
+ * Sends a message to the user that they did something incorrectly.
+ * We should tell them what to do instead as well.
+ *
+ * @param message The message to be sent
+ *
+ * @see USER_ERROR_PREFIX
+ */
+ fun userError(message: String) {
+ 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 inconsitencies 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
+ * @param prefix Whether to prefix the message with the error prefix, default true
+ *
+ * @see ERROR_PREFIX
+ */
+ @Deprecated(
+ "Do not send the user a non clickable non stacktrace containing error message.",
+ ReplaceWith("ErrorManager")
+ )
fun error(message: String) {
println("error: '$message'")
- internalChat("§c$message")
- }
-
- fun chat(message: String) {
- internalChat(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
+ * @param prefixColor Color that the prefix should be, default yellow (§e)
+ *
+ * @see CHAT_PREFIX
+ */
+ fun chat(message: String, prefix: Boolean = true, prefixColor: String = "§e") {
+ if (prefix) {
+ internalChat(prefixColor + CHAT_PREFIX + message)
+ } else {
+ internalChat(message)
+ }
}
private fun internalChat(message: String): Boolean {
@@ -244,8 +294,18 @@ object LorenzUtils {
lines[index] = ChatComponentText(text.capAtMinecraftLength(90))
}
- fun clickableChat(message: String, command: String) {
- val text = ChatComponentText(message)
+ /**
+ * Sends a message to the user that they can click and run a command
+ * @param message The message to be sent
+ * @param command The command 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, command: String, prefix: Boolean = true, prefixColor: String = "§e") {
+ val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
+ val text = ChatComponentText(msgPrefix + message)
val fullCommand = "/" + command.removePrefix("/")
text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, fullCommand)
text.chatStyle.chatHoverEvent =
@@ -253,8 +313,25 @@ object LorenzUtils {
Minecraft.getMinecraft().thePlayer.addChatMessage(text)
}
- fun hoverableChat(message: String, hover: List<String>, command: String? = null) {
- val text = ChatComponentText(message)
+ /**
+ * 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
+ * @param command The command 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 hoverableChat(
+ message: String,
+ hover: List<String>,
+ command: String? = null,
+ prefix: Boolean = true,
+ prefixColor: String = "§e"
+ ) {
+ val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
+ val text = ChatComponentText(msgPrefix + message)
text.chatStyle.chatHoverEvent =
HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(hover.joinToString("\n")))
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
index b083b2d3b..1f28effae 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.test.command.ErrorManager
import java.awt.Desktop
import java.io.IOException
import java.net.URI
@@ -12,12 +13,11 @@ object OSUtils {
try {
Desktop.getDesktop().browse(URI(url))
} catch (e: IOException) {
- e.printStackTrace()
- LorenzUtils.error("[SkyHanni] Error opening website: $url!")
+ ErrorManager.logError(e, "Error opening website: $url")
}
} else {
copyToClipboard(url)
- LorenzUtils.warning("[SkyHanni] Web browser is not supported! Copied url to clipboard.")
+ LorenzUtils.error("Web browser is not supported! Copied url to clipboard.")
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt
index d2403d4c6..326283d92 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt
@@ -58,7 +58,7 @@ object SoundUtils {
fun command(args: Array<String>) {
if (args.isEmpty()) {
- LorenzUtils.chat("§c[SkyHanni] Specify a sound effect to test")
+ LorenzUtils.userError("Specify a sound effect to test")
return
}
@@ -72,4 +72,4 @@ object SoundUtils {
fun playErrorSound() {
errorSound.playSound()
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
index 67ea197d2..fe07509be 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListData.kt
@@ -29,20 +29,20 @@ class TabListData {
fun toggleDebugCommand() {
if (debugCache != null) {
- LorenzUtils.chat("§e[SkyHanni] Disabled tab list debug.")
+ LorenzUtils.chat("Disabled tab list debug.")
debugCache = null
return
}
SkyHanniMod.coroutineScope.launch {
val clipboard = OSUtils.readFromClipboard() ?: return@launch
debugCache = clipboard.lines()
- LorenzUtils.chat("§e[SkyHanni] Enabled tab list debug with your clipboard.")
+ LorenzUtils.chat("Enabled tab list debug with your clipboard.")
}
}
fun copyCommand(args: Array<String>) {
if (debugCache != null) {
- LorenzUtils.clickableChat("§c[SkyHanni] Tab list debug is enambed!", "shdebugtablist")
+ LorenzUtils.clickableChat("Tab list debug is enabled!", "shdebugtablist")
return
}
@@ -57,7 +57,7 @@ class TabListData {
val tabFooter = tabList.footer_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText })
val string = "Header:\n\n$tabHeader\n\nBody:\n\n${resultList.joinToString("\n")}\n\nFooter:\n\n$tabFooter"
OSUtils.copyToClipboard(string)
- LorenzUtils.chat("§e[SkyHanni] Tab list copied into the clipboard!")
+ LorenzUtils.chat("Tab list copied into the clipboard!")
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
index 26153e5c9..f882a268e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniTracker.kt
@@ -29,12 +29,12 @@ class SkyHanniTracker<Data : TrackerData>(
fun resetCommand(args: Array<String>, command: String) {
if (args.size == 1 && args[0].lowercase() == "confirm") {
- reset(DisplayMode.TOTAL, "§e[SkyHanni] Reset total $name!")
+ reset(DisplayMode.TOTAL, "Reset total $name!")
return
}
LorenzUtils.clickableChat(
- "§e[SkyHanni] Are you sure you want to reset your total $name? Click here to confirm.",
+ "Are you sure you want to reset your total $name? Click here to confirm.",
"$command confirm"
)
}
@@ -86,7 +86,7 @@ class SkyHanniTracker<Data : TrackerData>(
),
) {
if (sessionResetTime.passedSince() > 3.seconds) {
- reset(DisplayMode.SESSION, "§e[SkyHanni] Reset this session of $name!")
+ reset(DisplayMode.SESSION, "Reset this session of $name!")
sessionResetTime = SimpleTimeMark.now()
}
}