diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-01-07 08:49:03 +0100 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-01-07 08:49:03 +0100 |
| commit | f038456b2af48098b5bf33464e5b8df3b0fa942c (patch) | |
| tree | e064a488ab213c36f4c0a3f50ee373be82451a59 /src/main/java/at/hannibal2/skyhanni/data | |
| parent | c463dfb645301954db6f2b4c64d685ebf0b7fb81 (diff) | |
| parent | b73026ee953306fdbe4b4aa382aa83f15a12565d (diff) | |
| download | skyhanni-f038456b2af48098b5bf33464e5b8df3b0fa942c.tar.gz skyhanni-f038456b2af48098b5bf33464e5b8df3b0fa942c.tar.bz2 skyhanni-f038456b2af48098b5bf33464e5b8df3b0fa942c.zip | |
Merge branch 'dev'
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt (renamed from src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt) | 37 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt | 2 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt (renamed from src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt) | 100 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/IslandType.kt | 22 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt | 2 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt | 11 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt | 4 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/SendTitleHelper.kt | 8 |
8 files changed, 133 insertions, 53 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt index 000d21805..bea039212 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt @@ -12,13 +12,32 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent import java.io.File import java.util.* -class ApiKeyGrabber { +class ApiDataLoader { private var currentProfileName = "" + private var nextApiCallTime = -1L + private var currentProfileId = "" + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + val thePlayer = Minecraft.getMinecraft().thePlayer ?: return + thePlayer.worldObj ?: return + + if (nextApiCallTime != -1L && System.currentTimeMillis() > nextApiCallTime) { + nextApiCallTime = System.currentTimeMillis() + 60_000 * 5 + SkyHanniMod.coroutineScope.launch { + val apiKey = SkyHanniMod.feature.hidden.apiKey + val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toDashlessUUID() + loadProfileData(apiKey, uuid, currentProfileId) + } + } + } + @SubscribeEvent fun onStatusBar(event: LorenzChatEvent) { val message = event.message @@ -38,7 +57,6 @@ class ApiKeyGrabber { updateApiData() } - private suspend fun tryUpdateProfileDataAndVerifyKey(apiKey: String): Boolean { val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toDashlessUUID() val url = "https://api.hypixel.net/player?key=$apiKey&uuid=$uuid" @@ -55,20 +73,21 @@ class ApiKeyGrabber { } val player = jsonObject["player"].asJsonObject val stats = player["stats"].asJsonObject - val skyblock = stats["SkyBlock"].asJsonObject - val profiles = skyblock["profiles"].asJsonObject + val skyBlock = stats["SkyBlock"].asJsonObject + val profiles = skyBlock["profiles"].asJsonObject for (entry in profiles.entrySet()) { val asJsonObject = entry.value.asJsonObject val name = asJsonObject["cute_name"].asString if (currentProfileName == name.lowercase()) { - val profileId = asJsonObject["profile_id"].asString - loadProfile(apiKey, uuid, profileId) + currentProfileId = asJsonObject["profile_id"].asString + loadProfileData(apiKey, uuid, currentProfileId) } } return true } private fun updateApiData() { + nextApiCallTime = -1 SkyHanniMod.coroutineScope.launch { val oldApiKey = SkyHanniMod.feature.hidden.apiKey if (oldApiKey.isNotEmpty() && tryUpdateProfileDataAndVerifyKey(oldApiKey)) { @@ -110,18 +129,18 @@ class ApiKeyGrabber { return candidates } - private suspend fun loadProfile(apiKey: String, playerUuid: String, profileId: String) { + private suspend fun loadProfileData(apiKey: String, playerUuid: String, profileId: String) { val url = "https://api.hypixel.net/skyblock/profile?key=$apiKey&profile=$profileId" val jsonObject = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) } - val profile = jsonObject["profile"]?.asJsonObject ?: return val members = profile["members"]?.asJsonObject ?: return for (entry in members.entrySet()) { if (entry.key == playerUuid) { val profileData = entry.value.asJsonObject ProfileApiDataLoadedEvent(profileData).postAndCatch() + nextApiCallTime = System.currentTimeMillis() + 60_000 * 3 } } } -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt index 2e4d13da6..30f88f48e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt @@ -25,7 +25,7 @@ class EntityMovementData { @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { - if (!LorenzUtils.inSkyblock) return + if (!LorenzUtils.inSkyBlock) return for (entity in entityLocation.keys) { if (entity.isDead) continue diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt index 53a1286d3..2bb7c7678 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt @@ -12,26 +12,29 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent import net.minecraftforge.fml.common.network.FMLNetworkEvent -class HypixelData { +class HyPixelData { companion object { var hypixel = false - var skyblock = false - var skyBlockIsland: String = "" + var skyBlock = false + var skyBlockIsland = IslandType.UNKNOWN - fun readSkyBlockArea(): String { - for (line in ScoreboardData.sidebarLinesFormatted()) { - if (line.startsWith(" §7⏣ ")) { - return line.substring(5).removeColor() - } - } + //Ironman, Stranded and Bingo + var noTrade = false - return "invalid" - } + var ironman = false + var stranded = false + var bingo = false + fun readSkyBlockArea(): String { + return ScoreboardData.sidebarLinesFormatted() + .firstOrNull { it.startsWith(" §7⏣ ") } + ?.substring(5)?.removeColor() + ?: "invalid" + } } - var loggerIslandChange = LorenzLogger("debug/island_change") + private var loggerIslandChange = LorenzLogger("debug/island_change") @SubscribeEvent fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) { @@ -43,13 +46,13 @@ class HypixelData { @SubscribeEvent fun onWorldChange(event: WorldEvent.Load) { - skyblock = false + skyBlock = false } @SubscribeEvent fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { hypixel = false - skyblock = false + skyBlock = false } @SubscribeEvent @@ -57,7 +60,6 @@ class HypixelData { if (!hypixel) return val message = event.message.removeColor().lowercase() - if (message.startsWith("your profile was changed to:")) { val stripped = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim() ProfileJoinEvent(stripped).postAndCatch() @@ -65,7 +67,6 @@ class HypixelData { if (message.startsWith("you are playing on profile:")) { val stripped = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim() ProfileJoinEvent(stripped).postAndCatch() - } } @@ -80,13 +81,42 @@ class HypixelData { if (tick % 5 != 0) return - val newState = checkScoreboard() - if (newState) { + val inSkyBlock = checkScoreboard() + if (inSkyBlock) { checkIsland() + checkSidebar() + } + + if (inSkyBlock == skyBlock) return + skyBlock = inSkyBlock + } + + private fun checkSidebar() { + ironman = false + stranded = false + bingo = false + + for (line in ScoreboardData.sidebarLinesFormatted()) { + when (line) { + " §7Ⓑ §7Bingo", // No Rank + " §bⒷ §bBingo", // Rank 1 + " §9Ⓑ §9Bingo", // Rank 2 + " §5Ⓑ §5Bingo", // Rank 3 + " §6Ⓑ §6Bingo", // Rank 4 + -> { + bingo = true + } + + // TODO implemennt stranded check + + " §7♲ §7Ironman" -> { + ironman = true + } + + } } - if (newState == skyblock) return - skyblock = newState + noTrade = ironman || stranded || bingo } private fun checkIsland() { @@ -100,14 +130,24 @@ class HypixelData { guesting = true } } - if (guesting) { - newIsland = "$newIsland guesting" + + var islandType = IslandType.getBySidebarName(newIsland) + + if (islandType == IslandType.PRIVATE_ISLAND) { + if (guesting) { + islandType = IslandType.PRIVATE_ISLAND_GUEST + } } - if (skyBlockIsland != newIsland) { - IslandChangeEvent(newIsland, skyBlockIsland).postAndCatch() - loggerIslandChange.log(newIsland) - skyBlockIsland = newIsland + if (skyBlockIsland != islandType) { + IslandChangeEvent(islandType, skyBlockIsland).postAndCatch() + if (islandType == IslandType.UNKNOWN) { + println("Unknown island detected: '$newIsland'") + loggerIslandChange.log("Unknown: '$newIsland'") + } else { + loggerIslandChange.log(islandType.name) + } + skyBlockIsland = islandType } } @@ -115,12 +155,8 @@ class HypixelData { val minecraft = Minecraft.getMinecraft() val world = minecraft.theWorld ?: return false - val sidebarObjective = world.scoreboard.getObjectiveInDisplaySlot(1) ?: return false - - val displayName = sidebarObjective.displayName - + val objective = world.scoreboard.getObjectiveInDisplaySlot(1) ?: return false + val displayName = objective.displayName return displayName.removeColor().contains("SKYBLOCK") - } - }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt new file mode 100644 index 000000000..527cce548 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -0,0 +1,22 @@ +package at.hannibal2.skyhanni.data + +enum class IslandType(val displayName: String) { + PRIVATE_ISLAND("Private Island"), + PRIVATE_ISLAND_GUEST("Private Island Guest"), + THE_END("The End"), + KUUDRA_ARENA("Instanced"), + CRIMSON_ISLE("Crimson Isle"), + + HUB("Hub"), + THE_FARMING_ISLANDS("The Farming Islands"), + + NONE(""), + UNKNOWN("???"), + ; + + companion object { + fun getBySidebarName(name: String): IslandType { + return values().firstOrNull { it.displayName == name } ?: UNKNOWN + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt index 9b25933ea..1576ff4ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt @@ -30,7 +30,7 @@ class ItemRenderBackground { @SubscribeEvent fun renderOverlayLol(event: RenderRealOverlayEvent) { val stack = event.stack - if (LorenzUtils.inSkyblock) { + if (LorenzUtils.inSkyBlock) { if (stack != null) { val color = stack.background if (color != -1) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt index 69ae9fa2d..7937ab2ae 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt @@ -5,10 +5,12 @@ import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent import at.hannibal2.skyhanni.events.RenderItemTipEvent import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer +import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName import at.hannibal2.skyhanni.utils.LorenzUtils import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.renderer.GlStateManager +import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -20,7 +22,7 @@ class ItemTipHelper { @SubscribeEvent fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) { val stack = event.stack ?: return - if (!LorenzUtils.inSkyblock || stack.stackSize != 1) return + if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return // val uuid = stacremovek.getLore().joinToString { ", " } val stackTip: String @@ -51,10 +53,12 @@ class ItemTipHelper { @SubscribeEvent(priority = EventPriority.HIGHEST) fun onRenderInventoryItemOverlayPost(event: DrawScreenAfterEvent) { - if (!LorenzUtils.inSkyblock) return + if (!LorenzUtils.inSkyBlock) return val gui = Minecraft.getMinecraft().currentScreen if (gui !is GuiChest) return + val chest = gui.inventorySlots as ContainerChest + var inventoryName = chest.getInventoryName() val guiLeft = (gui as AccessorGuiContainer).guiLeft val guiTop = (gui as AccessorGuiContainer).guiTop @@ -65,9 +69,8 @@ class ItemTipHelper { GlStateManager.disableBlend() for (slot in gui.inventorySlots.inventorySlots) { val stack = slot.stack ?: continue - if (stack.stackSize != 1) continue - val itemTipEvent = RenderInventoryItemTipEvent(stack) + val itemTipEvent = RenderInventoryItemTipEvent(inventoryName, slot, stack) itemTipEvent.postAndCatch() val stackTip = itemTipEvent.stackTip if (stackTip.isEmpty()) continue diff --git a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt index 16facaf90..f463391e3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MinecraftData.kt @@ -13,7 +13,7 @@ class MinecraftData { @SubscribeEvent(receiveCanceled = true) fun onSoundPacket(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyblock) return + if (!LorenzUtils.inSkyBlock) return val packet = event.packet if (packet !is S29PacketSoundEffect) return @@ -31,7 +31,7 @@ class MinecraftData { @SubscribeEvent(receiveCanceled = true) fun onParticlePacketReceive(event: PacketEvent.ReceiveEvent) { - if (!LorenzUtils.inSkyblock) return + if (!LorenzUtils.inSkyBlock) return val packet = event.packet if (packet !is S2APacketParticles) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/SendTitleHelper.kt b/src/main/java/at/hannibal2/skyhanni/data/SendTitleHelper.kt index eda151f97..f0abb1427 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SendTitleHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SendTitleHelper.kt @@ -10,17 +10,17 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SendTitleHelper { companion object { - private var textToRender = "" + private var display = "" private var endTime = 0L fun sendTitle(text: String, duration: Int) { - textToRender = text + display = text endTime = System.currentTimeMillis() + duration } } @SubscribeEvent - fun renderOverlay(event: RenderGameOverlayEvent.Post) { + fun onRenderOverlay(event: RenderGameOverlayEvent.Post) { if (event.type != RenderGameOverlayEvent.ElementType.ALL) return if (System.currentTimeMillis() > endTime) return @@ -36,7 +36,7 @@ class SendTitleHelper { GlStateManager.pushMatrix() GlStateManager.translate((width / 2).toFloat(), (height / 1.8).toFloat(), 0.0f) GlStateManager.scale(4.0f, 4.0f, 4.0f) - TextRenderUtils.drawStringCenteredScaledMaxWidth(textToRender, renderer, 0f, 0f, false, 75, 0) + TextRenderUtils.drawStringCenteredScaledMaxWidth(display, renderer, 0f, 0f, false, 75, 0) GlStateManager.popMatrix() } }
\ No newline at end of file |
