summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt72
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt4
3 files changed, 45 insertions, 65 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index 57889cc48..8cce72bba 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -8,14 +8,18 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
+import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
+import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.JsonObject
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
@@ -25,14 +29,11 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
import kotlin.concurrent.thread
+import kotlin.time.Duration.Companion.seconds
class HypixelData {
private val patternGroup = RepoPattern.group("data.hypixeldata")
- private val tabListProfilePattern by patternGroup.pattern(
- "tablistprofile",
- "§e§lProfile: §r§a(?<profile>.*)"
- )
private val lobbyTypePattern by patternGroup.pattern(
"lobbytype",
"(?<lobbyType>.*lobby)\\d+"
@@ -42,10 +43,9 @@ class HypixelData {
"(?:§.)*(Area|Dungeon): (?:§.)*(?<island>.*)"
)
- private var lastLocRaw = 0L
+ private var lastLocRaw = SimpleTimeMark.farPast()
companion object {
-
private val patternGroup = RepoPattern.group("data.hypixeldata")
private val serverIdScoreboardPattern by patternGroup.pattern(
"serverid.scoreboard",
@@ -147,6 +147,7 @@ class HypixelData {
val message = event.message.removeColor().lowercase()
if (message.startsWith("your profile was changed to:")) {
val newProfile = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim()
+ if (profileName == newProfile) return
profileName = newProfile
ProfileJoinEvent(newProfile).postAndCatch()
}
@@ -159,6 +160,21 @@ class HypixelData {
}
@SubscribeEvent
+ fun onTabListUpdate(event: TabListUpdateEvent) {
+ for (line in event.tabList) {
+ UtilsPatterns.tabListProfilePattern.matchMatcher(line) {
+ var newProfile = group("profile").lowercase()
+ // Hypixel shows the profile name reversed while in the Rift
+ if (RiftAPI.inRift()) newProfile = newProfile.reversed()
+ if (profileName == newProfile) return
+ profileName = newProfile
+ ProfileJoinEvent(newProfile).postAndCatch()
+ return
+ }
+ }
+ }
+
+ @SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) {
// Modified from NEU.
@@ -169,9 +185,9 @@ class HypixelData {
val currentTime = System.currentTimeMillis()
if (LorenzUtils.onHypixel &&
locrawData == null &&
- currentTime - lastLocRaw > 15000
+ lastLocRaw.passedSince() > 15.seconds
) {
- lastLocRaw = System.currentTimeMillis()
+ lastLocRaw = SimpleTimeMark.now()
thread(start = true) {
Thread.sleep(1000)
NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw")
@@ -213,7 +229,7 @@ class HypixelData {
private fun checkProfileName(): Boolean {
if (profileName.isEmpty()) {
val text = TabListData.getTabList().firstOrNull { it.contains("Profile:") } ?: return true
- tabListProfilePattern.matchMatcher(text) {
+ UtilsPatterns.tabListProfilePattern.matchMatcher(text) {
profileName = group("profile").lowercase()
ProfileJoinEvent(profileName).postAndCatch()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
index 08894d4a3..b81e09640 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt
@@ -3,18 +3,21 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.SackData
import at.hannibal2.skyhanni.config.Storage
+import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
-import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import kotlin.time.Duration.Companion.seconds
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -23,7 +26,7 @@ object ProfileStorageData {
var playerSpecific: Storage.PlayerSpecific? = null
var profileSpecific: Storage.ProfileSpecific? = null
var loaded = false
- private var noTabListTime = -1L
+ private var noTabListTime = SimpleTimeMark.farPast()
private var nextProfile: String? = null
@@ -32,44 +35,11 @@ object ProfileStorageData {
"switch",
"§7Switching to profile (?<name>.*)\\.\\.\\."
)
- private val profileNamePattern by patternGroup.pattern(
- "name",
- "§e§lProfile: §r§a(?<name>.*)"
- )
-
private var sackPlayers: SackData.PlayerSpecific? = null
var sackProfiles: SackData.ProfileSpecific? = null
@SubscribeEvent(priority = EventPriority.HIGHEST)
- fun onChat(event: LorenzChatEvent) {
- profileSwitchPattern.matchMatcher(event.message) {
- nextProfile = group("name").lowercase()
- loaded = false
- PreProfileSwitchEvent().postAndCatch()
- }
- }
-
- @SubscribeEvent(priority = EventPriority.HIGHEST)
- fun onWorldChange(event: LorenzWorldChangeEvent) {
- val profileName = nextProfile ?: return
- nextProfile = null
-
- val playerSpecific = playerSpecific
- val sackPlayers = sackPlayers
- if (playerSpecific == null) {
- ChatUtils.error("profileSpecific after profile swap can not be set: playerSpecific is null!")
- return
- }
- if (sackPlayers == null) {
- ChatUtils.error("sackPlayers after profile swap can not be set: sackPlayers is null!")
- return
- }
- loadProfileSpecific(playerSpecific, sackPlayers, profileName)
- ConfigLoadEvent().postAndCatch()
- }
-
- @SubscribeEvent(priority = EventPriority.HIGHEST)
fun onProfileJoin(event: ProfileJoinEvent) {
val playerSpecific = playerSpecific
val sackPlayers = sackPlayers
@@ -78,42 +48,36 @@ object ProfileStorageData {
return
}
if (sackPlayers == null) {
- ChatUtils.error("sackPlayers is null in sackPlayers!")
+ ChatUtils.error("sackPlayers is null in ProfileJoinEvent!")
return
}
- if (profileSpecific == null) {
- val profileName = event.name
- loadProfileSpecific(playerSpecific, sackPlayers, profileName)
- }
+ val profileName = event.name
+ loadProfileSpecific(playerSpecific, sackPlayers, profileName)
+ ConfigLoadEvent().postAndCatch()
}
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
- if (profileSpecific != null) return
- val playerSpecific = playerSpecific ?: return
- val sackPlayers = sackPlayers ?: return
+ if (!LorenzUtils.inSkyBlock) return
+
for (line in event.tabList) {
- profileNamePattern.matchMatcher(line) {
- val profileName = group("name").lowercase()
- loadProfileSpecific(playerSpecific, sackPlayers, profileName)
- nextProfile = null
+ UtilsPatterns.tabListProfilePattern.matchMatcher(line) {
+ noTabListTime = SimpleTimeMark.farPast()
return
}
}
- if (LorenzUtils.inSkyBlock) {
- noTabListTime = System.currentTimeMillis()
- }
+ noTabListTime = SimpleTimeMark.now()
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) return
- if (noTabListTime == -1L) return
+ if (noTabListTime == SimpleTimeMark.farPast()) return
- if (System.currentTimeMillis() > noTabListTime + 3_000) {
- noTabListTime = System.currentTimeMillis()
+ if (noTabListTime.passedSince() > 3.seconds) {
+ noTabListTime = SimpleTimeMark.now()
ChatUtils.chat(
"Extra Information from Tab list not found! " +
"Enable it: SkyBlock Menu ➜ Settings ➜ Personal ➜ User Interface ➜ Player List Info"
@@ -126,7 +90,7 @@ object ProfileStorageData {
sackProfile: SackData.PlayerSpecific,
profileName: String,
) {
- noTabListTime = -1
+ noTabListTime = SimpleTimeMark.farPast()
profileSpecific = playerSpecific.profiles.getOrPut(profileName) { Storage.ProfileSpecific() }
sackProfiles = sackProfile.profiles.getOrPut(profileName) { SackData.ProfileSpecific() }
loaded = true
diff --git a/src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt b/src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt
index 6b904bc37..a60fe10d4 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/TitleManager.kt
@@ -1,7 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.PreProfileSwitchEvent
+import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import io.github.moulberry.moulconfig.internal.TextRenderUtils
@@ -53,7 +53,7 @@ class TitleManager {
}
@SubscribeEvent
- fun onPreProfileSwitch(event: PreProfileSwitchEvent) {
+ fun onProfileJoin(event: ProfileJoinEvent) {
endTime = SimpleTimeMark.farPast()
}