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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
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.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.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object ProfileStorageData {
var playerSpecific: Storage.PlayerSpecific? = null
var profileSpecific: Storage.ProfileSpecific? = null
var loaded = false
private var noTabListTime = -1L
private var nextProfile: String? = null
private var sackPlayers: SackData.PlayerSpecific? = null
var sackProfiles: SackData.ProfileSpecific? = null
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onChat(event: LorenzChatEvent) {
// TODO USE SH-REPO
"§7Switching to profile (?<name>.*)\\.\\.\\.".toPattern().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) {
LorenzUtils.error("profileSpecific after profile swap can not be set: playerSpecific is null!")
return
}
if (sackPlayers == null) {
LorenzUtils.error("sackPlayers after profile swap can not be set: sackPlayers is null!")
return
}
loadProfileSpecific(playerSpecific, sackPlayers, profileName, "profile swap (chat message)")
ConfigLoadEvent().postAndCatch()
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onProfileJoin(event: ProfileJoinEvent) {
val playerSpecific = playerSpecific
val sackPlayers = sackPlayers
if (playerSpecific == null) {
LorenzUtils.error("playerSpecific is null in ProfileJoinEvent!")
return
}
if (sackPlayers == null) {
LorenzUtils.error("sackPlayers is null in sackPlayers!")
return
}
if (profileSpecific == null) {
val profileName = event.name
loadProfileSpecific(playerSpecific, sackPlayers, profileName, "first join (chat message)")
}
}
@SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
if (profileSpecific != null) return
val playerSpecific = playerSpecific ?: return
val sackPlayers = sackPlayers ?: return
for (line in event.tabList) {
val pattern = "§e§lProfile: §r§a(?<name>.*)".toPattern()
pattern.matchMatcher(line) {
val profileName = group("name").lowercase()
loadProfileSpecific(playerSpecific, sackPlayers, profileName, "tab list")
nextProfile = null
return
}
}
if (LorenzUtils.inSkyBlock) {
noTabListTime = System.currentTimeMillis()
}
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) return
if (noTabListTime == -1L) return
if (System.currentTimeMillis() > noTabListTime + 3_000) {
noTabListTime = System.currentTimeMillis()
LorenzUtils.chat(
"§c[SkyHanni] 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, reason: String) {
noTabListTime = -1
profileSpecific = playerSpecific.profiles.getOrPut(profileName) { Storage.ProfileSpecific() }
sackProfiles = sackProfile.profiles.getOrPut(profileName) { SackData.ProfileSpecific() }
tryMigrateProfileSpecific()
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() }
migratePlayerSpecific()
ConfigLoadEvent().postAndCatch()
}
private fun migratePlayerSpecific() {
val oldHidden = SkyHanniMod.feature.hidden
if (oldHidden.isMigrated) return
SkyHanniMod.feature.storage?.let {
it.gardenJacobFarmingContestTimes = oldHidden.gardenJacobFarmingContestTimes
}
}
private fun tryMigrateProfileSpecific() {
val oldHidden = SkyHanniMod.feature.hidden
if (oldHidden.isMigrated) return
profileSpecific?.let {
it.currentPet = oldHidden.currentPet
for ((rawLocation, minionName) in oldHidden.minionName) {
val lastClick = oldHidden.minionLastClick[rawLocation] ?: -1
val location = LorenzVec.decodeFromString(rawLocation)
val minionConfig = Storage.ProfileSpecific.MinionConfig()
minionConfig.displayName = minionName
minionConfig.lastClicked = lastClick
it.minions[location] = minionConfig
}
}
profileSpecific?.crimsonIsle?.let {
it.quests = oldHidden.crimsonIsleQuests
it.miniBossesDoneToday = oldHidden.crimsonIsleMiniBossesDoneToday
it.kuudraTiersDone = oldHidden.crimsonIsleKuudraTiersDone
}
profileSpecific?.garden?.let {
it.experience = oldHidden.gardenExp.toLong()
it.cropCounter = oldHidden.gardenCropCounter
it.cropUpgrades = oldHidden.gardenCropUpgrades
for ((crop, speed) in oldHidden.gardenCropsPerSecond) {
if (speed != -1) {
it.cropsPerSecond[crop] = speed
}
}
it.latestBlocksPerSecond = oldHidden.gardenLatestBlocksPerSecond
it.latestTrueFarmingFortune = oldHidden.gardenLatestTrueFarmingFortune
it.savedCropAccessory = oldHidden.savedCropAccessory
it.dicerRngDrops = oldHidden.gardenDicerRngDrops
it.informedAboutLowMatter = oldHidden.informedAboutLowMatter
it.informedAboutLowFuel = oldHidden.informedAboutLowFuel
it.visitorInterval = oldHidden.visitorInterval
it.nextSixthVisitorArrival = oldHidden.nextSixthVisitorArrival
it.farmArmorDrops = oldHidden.gardenFarmingArmorDrops
it.composterUpgrades = oldHidden.gardenComposterUpgrades
it.toolWithBountiful = oldHidden.gardenToolHasBountiful
it.composterCurrentOrganicMatterItem = oldHidden.gardenComposterCurrentOrganicMatterItem
it.composterCurrentFuelItem = oldHidden.gardenComposterCurrentFuelItem
}
profileSpecific?.garden?.visitorDrops?.let {
val old = oldHidden.visitorDrops
it.acceptedVisitors = old.acceptedVisitors
it.deniedVisitors = old.deniedVisitors
it.visitorRarities = old.visitorRarities
it.copper = old.copper
it.farmingExp = old.farmingExp
it.coinsSpent = old.coinsSpent
it.rewardsCount = old.rewardsCount
}
oldHidden.isMigrated = true
}
}
|