aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt69
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt2
3 files changed, 60 insertions, 46 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
index 180eaf5a2..3a88fd51f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
@@ -57,12 +57,11 @@ object ChatUtils {
* 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
+ * 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
- * @param prefix Whether to prefix the message with the error prefix, default true
*
* @see ERROR_PREFIX
*/
@@ -92,20 +91,26 @@ object ChatUtils {
}
private fun internalChat(message: String): Boolean {
- log.log(message)
+ return internalChat(ChatComponentText(message))
+ }
+
+ private fun internalChat(message: ChatComponentText): Boolean {
+ val formattedMessage = message.formattedText
+ log.log(formattedMessage)
+
val minecraft = Minecraft.getMinecraft()
if (minecraft == null) {
- LorenzUtils.consoleLog(message.removeColor())
+ LorenzUtils.consoleLog(formattedMessage.removeColor())
return false
}
val thePlayer = minecraft.thePlayer
if (thePlayer == null) {
- LorenzUtils.consoleLog(message.removeColor())
+ LorenzUtils.consoleLog(formattedMessage.removeColor())
return false
}
- thePlayer.addChatMessage(ChatComponentText(message))
+ thePlayer.addChatMessage(message)
return true
}
@@ -120,12 +125,19 @@ object ChatUtils {
*/
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 fullMessage = msgPrefix + message
+
+ internalChat(createClickableChat(fullMessage, command))
+ }
+
+ fun createClickableChat(message: String, command: String): ChatComponentText {
+ val text = ChatComponentText(message)
val fullCommand = "/" + command.removePrefix("/")
text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, fullCommand)
text.chatStyle.chatHoverEvent =
HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§eExecute $fullCommand"))
- Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+
+ return text
}
/**
@@ -160,15 +172,27 @@ object ChatUtils {
prefixColor: String = "§e",
) {
val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
- val text = ChatComponentText(msgPrefix + message)
+ val fullMessage = msgPrefix + message
+
+ internalChat(createHoverableChat(fullMessage, hover, command))
+ }
+
+ fun createHoverableChat(
+ message: String,
+ hover: List<String>,
+ command: String? = null,
+ runCommand: Boolean = true
+ ): ChatComponentText {
+ val text = ChatComponentText(message)
text.chatStyle.chatHoverEvent =
HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(hover.joinToString("\n")))
command?.let {
- text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${it.removePrefix("/")}")
+ val eventType = if (runCommand) ClickEvent.Action.RUN_COMMAND else ClickEvent.Action.SUGGEST_COMMAND
+ text.chatStyle.chatClickEvent = ClickEvent(eventType, "/${it.removePrefix("/")}")
}
- Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+ return text
}
/**
@@ -194,10 +218,31 @@ object ChatUtils {
val text = ChatComponentText(msgPrefix + message)
text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.OPEN_URL, url)
text.chatStyle.chatHoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("$prefixColor$hover"))
- Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+ internalChat(text)
if (autoOpen) OSUtils.openBrowser(url)
}
+ /**
+ * Sends a message to the user that combines many message components e.g. clickable, hoverable and regular text
+ * @param components The list of components to be joined together to form the final message
+ * @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 multiComponentMessage(
+ components: List<ChatComponentText>,
+ prefix: Boolean = true,
+ prefixColor: String = "§e"
+ ) {
+ val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
+ val baseMessage = ChatComponentText(msgPrefix)
+
+ for (component in components) baseMessage.appendSibling(component)
+
+ internalChat(baseMessage)
+ }
+
private var lastMessageSent = SimpleTimeMark.farPast()
private val sendQueue: Queue<String> = LinkedList()
private val messageDelay = 300.milliseconds
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 9d65eca03..c45bcae0e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -336,13 +336,13 @@ object LorenzUtils {
inline fun <reified T : Enum<T>> enumValueOf(name: String) =
enumValueOfOrNull<T>(name)
- ?: kotlin.error("Unknown enum constant for ${enumValues<T>().first().name.javaClass.simpleName}: '$name'")
+ ?: error("Unknown enum constant for ${enumValues<T>().first().name.javaClass.simpleName}: '$name'")
inline fun <reified T : Enum<T>> enumJoinToPattern(noinline transform: (T) -> CharSequence = { it.name }) =
enumValues<T>().joinToString("|", transform = transform)
// TODO move to val by lazy
- fun isInDevEnviromen() = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean
+ fun isInDevEnvironment() = Launch.blackboard["fml.deobfuscatedEnvironment"] as Boolean
fun shutdownMinecraft(reason: String? = null) {
System.err.println("SkyHanni-${SkyHanniMod.version} forced the game to shutdown.")
@@ -352,11 +352,6 @@ object LorenzUtils {
FMLCommonHandler.instance().handleExit(-1)
}
- @Deprecated("moved", ReplaceWith("ChatUtils.sendCommandToServer(command)"))
- fun sendCommandToServer(command: String) {
- ChatUtils.sendCommandToServer(command)
- }
-
/**
* Get the group, otherwise, return null
* @param groupName The group name in the pattern
@@ -365,32 +360,6 @@ object LorenzUtils {
return runCatching { this.group(groupName) }.getOrNull()
}
- @Deprecated("moved", ReplaceWith("ChatUtils.debug(message)"))
- fun debug(message: String) = ChatUtils.debug(message)
-
- @Deprecated("moved", ReplaceWith("ChatUtils.userError(message)"))
- fun userError(message: String) = ChatUtils.userError(message)
-
- @Deprecated("moved", ReplaceWith("ChatUtils.chat(message, prefix, prefixColor)"))
- fun chat(message: String, prefix: Boolean = true, prefixColor: String = "§e") =
- ChatUtils.chat(message, prefix, prefixColor)
-
- @Deprecated("moved", ReplaceWith("ChatUtils.clickableChat(message, command, prefix, prefixColor)"))
- fun clickableChat(message: String, command: String, prefix: Boolean = true, prefixColor: String = "§e") =
- ChatUtils.clickableChat(message, command, prefix, prefixColor)
-
- @Deprecated("moved", ReplaceWith("ChatUtils.hoverableChat(message, hover, command, prefix, prefixColor)"))
- fun hoverableChat(
- message: String,
- hover: List<String>,
- command: String? = null,
- prefix: Boolean = true,
- prefixColor: String = "§e",
- ) = ChatUtils.hoverableChat(message, hover, command, prefix, prefixColor)
-
- @Deprecated("moved", ReplaceWith("ChatUtils.sendMessageToServer(message)"))
- fun sendMessageToServer(message: String) = ChatUtils.sendMessageToServer(message)
-
fun inAdvancedMiningIsland() =
IslandType.DWARVEN_MINES.isInIsland() || IslandType.CRYSTAL_HOLLOWS.isInIsland() || IslandType.MINESHAFT.isInIsland()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
index 15dbfbaf0..26452e58f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/repopatterns/RepoPatternManager.kt
@@ -58,7 +58,7 @@ object RepoPatternManager {
}
}
- val localLoading: Boolean get() = config.forceLocal.get() || LorenzUtils.isInDevEnviromen()
+ val localLoading: Boolean get() = config.forceLocal.get() || LorenzUtils.isInDevEnvironment()
/**
* Crash if in a development environment, or if inside a guarded event handler.