aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-04-10 09:00:22 +0200
committerGitHub <noreply@github.com>2024-04-10 09:00:22 +0200
commit3397cc4474e3165865707182a5dcacf5bb4e68bd (patch)
treec714eab2aae2453a01f546cb4811c87dcd18a7e7 /src/main/java
parent8c86c32807dc697218d71bdc9eef7aef68ba90e7 (diff)
downloadskyhanni-3397cc4474e3165865707182a5dcacf5bb4e68bd.tar.gz
skyhanni-3397cc4474e3165865707182a5dcacf5bb4e68bd.tar.bz2
skyhanni-3397cc4474e3165865707182a5dcacf5bb4e68bd.zip
Backend: Chat and Open Config (#1396)
Co-authored-by: Empa <42304516+ItsEmpa@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt37
6 files changed, 64 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
index 96baef5a3..7fd5cde54 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt
@@ -328,7 +328,11 @@ object GriffinBurrowHelper {
if (!isEnabled()) {
if (currentMayor != Mayor.DIANA) {
- ChatUtils.clickableChat("§cSelect Diana as mayor overwrite!", "sh assume mayor")
+ ChatUtils.chatAndOpenConfig(
+ "§cSelect Diana as mayor overwrite!",
+ SkyHanniMod.feature.dev.debug::assumeMayor
+ )
+
} else {
ChatUtils.userError("Have an Ancestral Spade in the inventory!")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
index d89437a5b..b696d05ba 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt
@@ -58,7 +58,10 @@ object GardenCustomKeybinds {
.let { values -> values.size != values.toSet().size }
if (areDuplicates) {
if (lastDuplicateKeybindsWarnTime.passedSince() > 30.seconds) {
- ChatUtils.clickableUserError("Duplicate Custom Keybinds aren't allowed!", "sh custom keybinds")
+ ChatUtils.chatAndOpenConfig(
+ "Duplicate Custom Keybinds aren't allowed!",
+ GardenAPI.config::keyBind
+ )
lastDuplicateKeybindsWarnTime = SimpleTimeMark.now()
}
return false
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
index 843e8e558..b746e03ea 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
@@ -20,10 +20,9 @@ object GardenStartLocation {
return
}
if (!config.enabled) {
- ChatUtils.clickableChat(
+ ChatUtils.chatAndOpenConfig(
"This feature is disabled. Enable it in the config: §e/sh crop start location",
- "sh crop start location",
- prefixColor = "§c"
+ GardenAPI.config::cropStartLocation
)
return
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
index 58aada3ff..a1a3c859d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt
@@ -151,10 +151,9 @@ class VisitorListener {
event.isCanceled = true
ChatUtils.chat("§cBlocked refusing visitor ${visitor.visitorName} §7(${it.displayName}§7)")
if (config.rewardWarning.bypassKey == Keyboard.KEY_NONE) {
- ChatUtils.clickableChat(
+ ChatUtils.chatAndOpenConfig(
"§eIf you want to deny this visitor, set a keybind in §e/sh bypass",
- "sh bypass",
- false
+ GardenAPI.config.visitors.rewardWarning::bypassKey
)
}
Minecraft.getMinecraft().thePlayer.closeScreen()
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
index d2dd5c9b0..eaae104ac 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
@@ -4,6 +4,7 @@ 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.ConfigUtils.jumpToEditor
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.Minecraft
import net.minecraft.event.ClickEvent
@@ -12,6 +13,7 @@ import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.LinkedList
import java.util.Queue
+import kotlin.reflect.KMutableProperty0
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.times
@@ -194,7 +196,7 @@ object ChatUtils {
message: String,
hover: List<String>,
command: String? = null,
- runCommand: Boolean = true
+ runCommand: Boolean = true,
): ChatComponentText {
val text = ChatComponentText(message)
text.chatStyle.chatHoverEvent =
@@ -225,7 +227,7 @@ object ChatUtils {
hover: String = "§eOpen $url",
autoOpen: Boolean = false,
prefix: Boolean = true,
- prefixColor: String = "§e"
+ prefixColor: String = "§e",
) {
val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
val text = ChatComponentText(msgPrefix + message)
@@ -246,7 +248,7 @@ object ChatUtils {
fun multiComponentMessage(
components: List<ChatComponentText>,
prefix: Boolean = true,
- prefixColor: String = "§e"
+ prefixColor: String = "§e",
) {
val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
val baseMessage = ChatComponentText(msgPrefix)
@@ -297,4 +299,13 @@ object ChatUtils {
fun MessageSendToServerEvent.eventWithNewMessage(message: String) =
MessageSendToServerEvent(message, message.split(" "), this.originatingModContainer)
+
+ fun chatAndOpenConfig(message: String, property: KMutableProperty0<*>) {
+ clickableChat(
+ message,
+ onClick = {
+ property.jumpToEditor()
+ }
+ )
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt
index 55773a9c7..b6f096371 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ConfigUtils.kt
@@ -1,9 +1,18 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.config.HasLegacyId
+import at.hannibal2.skyhanni.events.LorenzEvent
+import at.hannibal2.skyhanni.test.command.ErrorManager
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonPrimitive
+import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
+import io.github.notenoughupdates.moulconfig.gui.MoulConfigEditor
+import io.github.notenoughupdates.moulconfig.processor.ProcessedOption
+import kotlin.reflect.KMutableProperty0
+import kotlin.reflect.jvm.javaField
object ConfigUtils {
@@ -55,4 +64,32 @@ object ConfigUtils {
require(element is JsonPrimitive) { "Expected a JsonPrimitive but got ${element.javaClass.simpleName}" }
return JsonPrimitive(getEnumConstantFromLegacyId(element.asInt, enumClass)?.name)
}
+
+ fun KMutableProperty0<*>.tryFindEditor(editor: MoulConfigEditor<*>): ProcessedOption? {
+ return editor.processedConfig.getOptionFromField(this.javaField ?: return null)
+ }
+
+ fun KMutableProperty0<*>.jumpToEditor() {
+ if (tryJumpToEditor(ConfigGuiManager.getEditorInstance())) return
+
+ // TODO create utils function "crashIfInDevEnv"
+ if (LorenzEvent.isInGuardedEventHandler) {
+ throw Error("can not jump to editor $name")
+ }
+ ErrorManager.logErrorStateWithData(
+ "Can not open the config",
+ "error while trying to jump to an editor element",
+ "this.name" to this.name,
+ "this.toString()" to this.toString(),
+ "this" to this,
+ )
+ }
+
+ private fun KMutableProperty0<*>.tryJumpToEditor(editor: MoulConfigEditor<*>): Boolean {
+ val option = tryFindEditor(editor) ?: return false
+ editor.search("")
+ if (!editor.goToOption(option)) return false
+ SkyHanniMod.screenToOpen = GuiScreenElementWrapper(editor)
+ return true
+ }
}