aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/garden
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-03 21:05:41 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-03 21:05:41 +0200
commit94521196a742a211594a1fdd29fa4dab9cbfb41f (patch)
tree8be33ad785ea72d631cf1474a8b991e35c537fff /src/main/java/at/hannibal2/skyhanni/features/garden
parentf93585fe40a1dd2a1ccb2cbc160497af16006f86 (diff)
downloadskyhanni-94521196a742a211594a1fdd29fa4dab9cbfb41f.tar.gz
skyhanni-94521196a742a211594a1fdd29fa4dab9cbfb41f.tar.bz2
skyhanni-94521196a742a211594a1fdd29fa4dab9cbfb41f.zip
Added a recent teleport pad used display and option to hide teleport pad chat message
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenRecentTeleportPadsDisplay.kt64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenRecentTeleportPadsDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenRecentTeleportPadsDisplay.kt
new file mode 100644
index 000000000..0577088bd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenRecentTeleportPadsDisplay.kt
@@ -0,0 +1,64 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.ConfigLoadEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils.onToggle
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class GardenRecentTeleportPadsDisplay {
+ private val config get() = SkyHanniMod.feature.garden.teleportPadsRecentDisplay
+ private var display = listOf<String>()
+ private var recentTeleports = mutableListOf<Pair<String, String>>()
+ private val pattern =
+ "§aWarped from the §r(?<from>.*) Teleport Pad§r§a to the §r(?<to>.*) Teleport Pad§r§a!".toPattern()
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!GardenAPI.inGarden()) return
+
+ pattern.matchMatcher(event.message) {
+ if (config.enabled) {
+ recentTeleports.add(Pair(group("from"), group("to")))
+ if (recentTeleports.size > 3) recentTeleports.removeFirst()
+ update()
+ }
+
+ if (config.hideChat) {
+ event.blockedReason = "recent_teleport_pads"
+ }
+ }
+ }
+
+ private fun update() {
+ display = buildList {
+ add("§6Recent TPs")
+ for ((from, to) in recentTeleports) {
+ if (config.onlyTarget.get()) {
+ add(to)
+ } else {
+ add(" $from §7-> $to")
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onConfigLoad(event: ConfigLoadEvent) {
+ config.onlyTarget.onToggle {
+ update()
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
+ if (!isEnabled()) return
+
+ config.pos.renderStrings(display, posLabel = "Recent Teleport Pads Display")
+ }
+
+ fun isEnabled() = GardenAPI.inGarden() && config.enabled
+}