aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-02-20 00:59:39 +1100
committerGitHub <noreply@github.com>2024-02-19 14:59:39 +0100
commitc19a902d2ef4aa93ff2d3cc93230f067e9315b71 (patch)
tree588e197fa91adc383223948d003db565b5e9f5a5 /src/main
parentab769839034888bc10ddfb2ef815be2400d64641 (diff)
downloadskyhanni-c19a902d2ef4aa93ff2d3cc93230f067e9315b71.tar.gz
skyhanni-c19a902d2ef4aa93ff2d3cc93230f067e9315b71.tar.bz2
skyhanni-c19a902d2ef4aa93ff2d3cc93230f067e9315b71.zip
Created ActionBarUpdateEvent and used it. #977
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ActionBarData.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/ActionBarUpdateEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdateEvent.kt (renamed from src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdate.kt)2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzActionBarEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/SkyblockXPInChat.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyActionBarCommand.kt20
14 files changed, 86 insertions, 41 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index e6be89916..fc3fd348a 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.config.Features
import at.hannibal2.skyhanni.config.SackData
import at.hannibal2.skyhanni.config.commands.Commands.init
+import at.hannibal2.skyhanni.data.ActionBarData
import at.hannibal2.skyhanni.data.ActionBarStatsData
import at.hannibal2.skyhanni.data.BlockData
import at.hannibal2.skyhanni.data.BossbarData
@@ -446,6 +447,7 @@ class SkyHanniMod {
loadModule(BingoCardReader())
loadModule(DeepCavernsParkour())
loadModule(GardenBestCropTime())
+ loadModule(ActionBarData)
loadModule(TrackerManager)
loadModule(UtilsPatterns)
loadModule(PetAPI)
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 6e7c80ce1..3a0290b6a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -57,6 +57,7 @@ import at.hannibal2.skyhanni.test.SkyHanniConfigSearchResetCommand
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.test.TestBingo
import at.hannibal2.skyhanni.test.WorldEdit
+import at.hannibal2.skyhanni.test.command.CopyActionBarCommand
import at.hannibal2.skyhanni.test.command.CopyBossbarCommand
import at.hannibal2.skyhanni.test.command.CopyItemCommand
import at.hannibal2.skyhanni.test.command.CopyNearbyEntitiesCommand
@@ -374,7 +375,14 @@ object Commands {
"shcopyentities",
"Copies entities in the specified radius around the player to the clipboard"
) { CopyNearbyEntitiesCommand.command(it) }
- registerCommand("shcopytablist", "Copies the tab list data to the clipboard") { TabListData.copyCommand(it) }
+ registerCommand(
+ "shcopytablist",
+ "Copies the tab list data to the clipboard"
+ ) { TabListData.copyCommand(it) }
+ registerCommand(
+ "shcopyactionbar",
+ "Copies the action bar to the clipboard, including formatting codes"
+ ) { CopyActionBarCommand.command(it) }
registerCommand(
"shcopyscoreboard",
"Copies the scoreboard data to the clipboard"
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ActionBarData.kt b/src/main/java/at/hannibal2/skyhanni/data/ActionBarData.kt
new file mode 100644
index 000000000..aa72e9868
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/ActionBarData.kt
@@ -0,0 +1,29 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object ActionBarData {
+ private var actionBar = ""
+
+ fun getActionBar() = actionBar
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ actionBar = ""
+ }
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onChatReceive(event: ClientChatReceivedEvent) {
+ if (event.type.toInt() != 2) return
+
+ val original = event.message
+ val message = LorenzUtils.stripVanillaMessage(original.formattedText)
+ if (message == actionBar) return
+ actionBar = message
+ ActionBarUpdateEvent(actionBar).postAndCatch()
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
index e4f78142f..3c962ad0a 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ActionBarStatsData.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.events.ActionBarValueUpdate
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
+import at.hannibal2.skyhanni.events.ActionBarValueUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
@@ -44,15 +44,15 @@ enum class ActionBarStatsData(@Language("RegExp") rawPattern: String) {
}
@SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
+ fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return
entries.mapNotNull { data ->
- data.pattern.matchMatcher(event.message) {
+ data.pattern.matchMatcher(event.actionBar) {
val newValue = group(1)
if (data.value != newValue) {
data.value = newValue
- ActionBarValueUpdate(data)
+ ActionBarValueUpdateEvent(data)
} else null
}
}.forEach { it.postAndCatch() }
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
index 7d0bb6728..9a5f93c0f 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.events.PacketEvent
@@ -17,12 +16,10 @@ import net.minecraft.client.gui.ChatLine
import net.minecraft.client.gui.GuiNewChat
import net.minecraft.event.HoverEvent
import net.minecraft.network.play.client.C01PacketChatMessage
-import net.minecraft.network.play.server.S02PacketChat
import net.minecraft.util.ChatComponentText
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.IChatComponent
import net.minecraftforge.client.event.ClientChatReceivedEvent
-import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.relauncher.ReflectionHelper
import java.lang.invoke.MethodHandles
@@ -71,18 +68,6 @@ object ChatManager {
val hoverExtraInfo: List<String> = listOf(),
)
- @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
- fun onActionBarPacket(event: PacketEvent.ReceiveEvent) {
- val packet = event.packet as? S02PacketChat ?: return
-
- val messageComponent = packet.chatComponent
- val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText)
- if (packet.type.toInt() == 2) {
- val actionBarEvent = LorenzActionBarEvent(message)
- actionBarEvent.postAndCatch()
- }
- }
-
@SubscribeEvent
fun onSendMessageToServerPacket(event: PacketEvent.SendEvent) {
val packet = event.packet as? C01PacketChatMessage ?: return
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
index 93fb6e14e..78a44cda3 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.data
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SkillExpGainEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
@@ -35,10 +35,10 @@ class SkillExperience {
}
@SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
+ fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return
- actionBarPattern.matchMatcher(event.message) {
+ actionBarPattern.matchMatcher(event.actionBar) {
val skill = group("skill").lowercase()
val overflow = group("overflow").formatNumber()
val neededForNextLevel = group("needed").formatNumber()
@@ -48,7 +48,7 @@ class SkillExperience {
skillExp[skill] = totalExp
SkillExpGainEvent(skill).postAndCatch()
}
- actionBarLowLevelPattern.matchMatcher(event.message) {
+ actionBarLowLevelPattern.matchMatcher(event.actionBar) {
val skill = group("skill").lowercase()
SkillExpGainEvent(skill).postAndCatch()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/ActionBarUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ActionBarUpdateEvent.kt
new file mode 100644
index 000000000..9b9c0f8dd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/ActionBarUpdateEvent.kt
@@ -0,0 +1,3 @@
+package at.hannibal2.skyhanni.events
+
+class ActionBarUpdateEvent(val actionBar: String) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdate.kt b/src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdateEvent.kt
index f6afd98e2..fa3d6a730 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdate.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/ActionBarValueUpdateEvent.kt
@@ -2,4 +2,4 @@ package at.hannibal2.skyhanni.events
import at.hannibal2.skyhanni.data.ActionBarStatsData
-class ActionBarValueUpdate(val updated: ActionBarStatsData) : LorenzEvent()
+class ActionBarValueUpdateEvent(val updated: ActionBarStatsData) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzActionBarEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzActionBarEvent.kt
deleted file mode 100644
index 83cddb287..000000000
--- a/src/main/java/at/hannibal2/skyhanni/events/LorenzActionBarEvent.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package at.hannibal2.skyhanni.events
-
-class LorenzActionBarEvent(val message: String) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/SkyblockXPInChat.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/SkyblockXPInChat.kt
index 8859220ee..190ddb493 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/SkyblockXPInChat.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/SkyblockXPInChat.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.chat
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ActionBarStatsData
-import at.hannibal2.skyhanni.events.ActionBarValueUpdate
+import at.hannibal2.skyhanni.events.ActionBarValueUpdateEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -11,7 +11,7 @@ class SkyblockXPInChat {
val config get() = SkyHanniMod.feature.chat.skyBlockXPInChat
@SubscribeEvent
- fun onActionBarValueUpdate(event: ActionBarValueUpdate) {
+ fun onActionBarValueUpdate(event: ActionBarValueUpdateEvent) {
if (event.updated != ActionBarStatsData.SKYBLOCK_XP) return
if (!config) return
ChatUtils.chat(event.updated.value)
diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt
index 0364bda1a..733be8cd0 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/combat/ghostcounter/GhostCounter.kt
@@ -6,10 +6,10 @@ import at.hannibal2.skyhanni.config.features.combat.ghostcounter.GhostCounterCon
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.SkillExperience
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.PurseChangeCause
@@ -333,12 +333,12 @@ object GhostCounter {
}
@SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
+ fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!isEnabled()) return
if (!inMist) return
- combatSectionPattern.matchMatcher(event.message) {
+ combatSectionPattern.matchMatcher(event.actionBar) {
if (group("skillName").lowercase() != "combat") return
- parseCombatSection(event.message)
+ parseCombatSection(event.actionBar)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
index 2e7a4b8cc..180a09ca2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt
@@ -2,8 +2,8 @@ package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ItemClickEvent
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
@@ -191,10 +191,10 @@ class ItemAbilityCooldown {
}
@SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
+ fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!isEnabled()) return
- val message: String = event.message
+ val message: String = event.actionBar
handleOldAbilities(message)
when {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
index e7f8ad5a1..c995fa405 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/rift/everywhere/RiftTimer.kt
@@ -1,8 +1,8 @@
package at.hannibal2.skyhanni.features.rift.everywhere
+import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.utils.ConditionalUtils
@@ -36,10 +36,11 @@ class RiftTimer {
currentTime = 0
}
+ //todo use ActionBarValueUpdateEvent
@SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
+ fun onActionBarUpdate(event: ActionBarUpdateEvent) {
if (!isEnabled()) return
- for (entry in event.message.split(" ")) {
+ for (entry in event.actionBar.split(" ")) {
timePattern.matchMatcher(entry) {
val color = group("color")
val newTime = getTime(group("time"))
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyActionBarCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyActionBarCommand.kt
new file mode 100644
index 000000000..2f07483b2
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyActionBarCommand.kt
@@ -0,0 +1,20 @@
+package at.hannibal2.skyhanni.test.command
+
+import at.hannibal2.skyhanni.data.ActionBarData
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+
+object CopyActionBarCommand {
+ fun command(args: Array<String>) {
+ val noFormattingCodes = args.size == 1 && args[0] == "true"
+
+ val status = if (noFormattingCodes) "without" else "with"
+
+ var actionBar = ActionBarData.getActionBar()
+ if (noFormattingCodes) actionBar = actionBar.removeColor()
+
+ OSUtils.copyToClipboard(actionBar)
+ ChatUtils.chat("Action bar name copied to clipboard $status formatting codes!")
+ }
+}