aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
index be1694a86..53cab5d02 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/GetFromSackAPI.kt
@@ -1,20 +1,20 @@
package at.hannibal2.skyhanni.api
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.data.jsonobjects.repo.SacksJson
+import at.hannibal2.skyhanni.config.ConfigManager
+import at.hannibal2.skyhanni.data.jsonobjects.other.NeuSacksJson
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
-import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.features.commands.tabcomplete.GetFromSacksTabComplete
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ChatUtils.isCommand
import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni
-import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
@@ -25,7 +25,9 @@ import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveSta
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.fromJson
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
+import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.inventory.Slot
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.Deque
@@ -222,12 +224,27 @@ object GetFromSackAPI {
}
@SubscribeEvent
- fun onRepoReload(event: RepositoryReloadEvent) {
- sackListInternalNames = event.getConstant<SacksJson>("Sacks").sackItems.toSet()
+ fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
+ val data = event.getConstant("sacks") ?: ErrorManager.skyHanniError("NEU sacks data is null.")
+ try {
+ val sacksData = ConfigManager.gson.fromJson<NeuSacksJson>(data).sacks
+ val uniqueSackItems = mutableSetOf<NEUInternalName>()
+
+ sacksData.values.forEach { sackInfo ->
+ sackInfo.contents.forEach { content ->
+ uniqueSackItems.add(content)
+ }
+ }
+
+ sackListInternalNames = uniqueSackItems.map { it.asString() }.toSet()
+ sackListNames = uniqueSackItems.map { it.itemNameWithoutColor.uppercase() }.toSet()
- DelayedRun.runNextTick {
- sackListNames = sackListInternalNames.map { it.asInternalName().itemNameWithoutColor.uppercase() }.toSet()
+ } catch (e: Exception) {
+ ErrorManager.logErrorWithData(
+ e, "Error getting NEU sacks data, make sure your neu repo is updated.",
+ "sacksJson" to data
+ )
+ Utils.showOutdatedRepoNotification()
}
- //sackListNames = event.getConstant<SacksJson>("Sacks").sackList.map { it.uppercase() }.toSet()
}
}