blob: 274cf24e0e8c55ddf0886a272123509f8ab98f4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
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.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
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 net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
object ProfileStorageData {
var playerSpecific: Storage.PlayerSpecific? = null
var profileSpecific: Storage.ProfileSpecific? = null
var loaded = false
private var noTabListTime = SimpleTimeMark.farPast()
private var sackPlayers: SackData.PlayerSpecific? = null
var sackProfiles: SackData.ProfileSpecific? = null
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onProfileJoin(event: ProfileJoinEvent) {
val playerSpecific = playerSpecific
val sackPlayers = sackPlayers
if (playerSpecific == null) {
ChatUtils.error("playerSpecific is null in ProfileJoinEvent!")
return
}
if (sackPlayers == null) {
ChatUtils.error("sackPlayers is null in ProfileJoinEvent!")
return
}
val profileName = event.name
loadProfileSpecific(playerSpecific, sackPlayers, profileName)
ConfigLoadEvent().postAndCatch()
}
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
if (!LorenzUtils.inSkyBlock) return
for (line in event.tabList) {
UtilsPatterns.tabListProfilePattern.matchMatcher(line) {
noTabListTime = SimpleTimeMark.farPast()
return
}
}
noTabListTime = SimpleTimeMark.now()
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) return
if (noTabListTime == SimpleTimeMark.farPast()) return
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"
)
}
}
private fun loadProfileSpecific(
playerSpecific: Storage.PlayerSpecific,
sackProfile: SackData.PlayerSpecific,
profileName: String,
) {
noTabListTime = SimpleTimeMark.farPast()
profileSpecific = playerSpecific.profiles.getOrPut(profileName) { Storage.ProfileSpecific() }
sackProfiles = sackProfile.profiles.getOrPut(profileName) { SackData.ProfileSpecific() }
loaded = true
ConfigLoadEvent().postAndCatch()
}
@SubscribeEvent
fun onHypixelJoin(event: HypixelJoinEvent) {
val playerUuid = LorenzUtils.getRawPlayerUuid()
playerSpecific = SkyHanniMod.feature.storage.players.getOrPut(playerUuid) { Storage.PlayerSpecific() }
sackPlayers = SkyHanniMod.sackData.players.getOrPut(playerUuid) { SackData.PlayerSpecific() }
ConfigLoadEvent().postAndCatch()
}
}
|