aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorForrick <69301168+Forrick@users.noreply.github.com>2023-01-13 05:12:07 +0100
committerGitHub <noreply@github.com>2023-01-13 05:12:07 +0100
commit0e0d560af64a5c148b26336d18bb59545a3945b9 (patch)
tree9f64a070015335d25468f73b58e665681577e34b /src/main/java/at/hannibal2/skyhanni/features
parentb5a44ec270fc10c4d74c0db9977ee0109d08134d (diff)
downloadSkyHanni-0e0d560af64a5c148b26336d18bb59545a3945b9.tar.gz
SkyHanni-0e0d560af64a5c148b26336d18bb59545a3945b9.tar.bz2
SkyHanni-0e0d560af64a5c148b26336d18bb59545a3945b9.zip
Updated to 0.14.1 and Bazaar stuff. (#8)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt45
3 files changed, 51 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
index b43cb1eb3..b4f00f248 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt
@@ -1,3 +1,3 @@
package at.hannibal2.skyhanni.features.bazaar
-data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double) \ No newline at end of file
+data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double, val buyMovingWeek: Int, val sellMovingWeek: Int) \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
index bcf1b3e48..c2f5fb5a7 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.features.bazaar
+import at.hannibal2.skyhanni.events.BazaarUpdateEvent
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
@@ -97,6 +98,8 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
continue
}
+ val sellMovingWeek = itemData["quick_status"].asJsonObject["sellMovingWeek"].asInt
+ val buyMovingWeek = itemData["quick_status"].asJsonObject["buyMovingWeek"].asInt
//parse bazaar api format into internal name format
if (apiName.startsWith("ENCHANTMENT_")) {
val split = apiName.split("_")
@@ -106,9 +109,10 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, Bazaa
apiName = text
}
- val data = BazaarData(apiName, itemName, sellPrice, buyPrice)
+ val data = BazaarData(apiName, itemName, sellPrice, buyPrice, buyMovingWeek, sellMovingWeek)
bazaarMap[itemName] = data
}
+ BazaarUpdateEvent(bazaarMap).postAndCatch()
}
private fun getItemName(apiName: String): String? {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
new file mode 100644
index 000000000..0a99f942a
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarUpdateTimer.kt
@@ -0,0 +1,45 @@
+package at.hannibal2.skyhanni.features.bazaar
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.BazaarUpdateEvent
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import net.minecraftforge.client.event.GuiScreenEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.text.DecimalFormat
+
+class BazaarUpdateTimer {
+ private var lastBazaarUpdateTime = 0L
+
+ @SubscribeEvent
+ fun onBazaarUpdate(event: BazaarUpdateEvent) {
+ if (!isEnabled()) return
+ lastBazaarUpdateTime = System.currentTimeMillis()
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) {
+ if (!isEnabled()) return
+ if (!BazaarApi.isBazaarInventory(InventoryUtils.openInventoryName())) return
+
+ val duration = System.currentTimeMillis() - lastBazaarUpdateTime
+ val durationSeconds = duration.toDouble() / 1000
+ val nextUpdateIn = 10 - durationSeconds
+ val format = if (nextUpdateIn < 0) {
+ "Updating"
+ } else {
+ DecimalFormat("0.0").format(nextUpdateIn)
+ }
+
+ val list = mutableListOf<String>()
+ list.add("Next update in:")
+ list.add(format)
+ SkyHanniMod.feature.bazaar.updateTimerPos.renderStrings(list, center = true)
+ }
+
+ private fun isEnabled(): Boolean {
+ return LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.updateTimer
+ }
+} \ No newline at end of file