From 029800349b1af9fa8f81bd394bbb887f36dcb19f Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 10 Apr 2023 20:54:58 +0200 Subject: renamed HypixelData --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 2 +- .../java/at/hannibal2/skyhanni/data/HyPixelData.kt | 172 --------------------- .../java/at/hannibal2/skyhanni/data/HypixelData.kt | 172 +++++++++++++++++++++ .../skyhanni/features/garden/EliteFarmingWeight.kt | 4 +- .../skyhanni/features/misc/PasteIntoSigns.kt | 4 +- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 14 +- 6 files changed, 184 insertions(+), 184 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index ef9e58d10..61f4315d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -103,7 +103,7 @@ public class SkyHanniMod { // utils loadModule(this); loadModule(new ChatManager()); - loadModule(new HyPixelData()); + loadModule(new HypixelData()); loadModule(new DungeonData()); loadModule(new ScoreboardData()); loadModule(new ApiDataLoader()); diff --git a/src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt deleted file mode 100644 index 2b5c3569f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/HyPixelData.kt +++ /dev/null @@ -1,172 +0,0 @@ -package at.hannibal2.skyhanni.data - -import at.hannibal2.skyhanni.events.IslandChangeEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.ProfileJoinEvent -import at.hannibal2.skyhanni.utils.LorenzLogger -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import at.hannibal2.skyhanni.utils.TabListData -import net.minecraft.client.Minecraft -import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent -import net.minecraftforge.fml.common.network.FMLNetworkEvent - -class HyPixelData { - - companion object { - var hypixel = false - var skyBlock = false - var skyBlockIsland = IslandType.UNKNOWN - - //Ironman, Stranded and Bingo - var noTrade = false - - var ironman = false - var stranded = false - var bingo = false - - var profileName = "" - - fun readSkyBlockArea(): String { - return ScoreboardData.sidebarLinesFormatted - .firstOrNull { it.startsWith(" §7⏣ ") } - ?.substring(5)?.removeColor() - ?: "invalid" - } - } - - private var loggerIslandChange = LorenzLogger("debug/island_change") - - @SubscribeEvent - fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) { - hypixel = Minecraft.getMinecraft().runCatching { - !event.isLocal && (thePlayer?.clientBrand?.lowercase()?.contains("hypixel") - ?: currentServerData?.serverIP?.lowercase()?.contains("hypixel") ?: false) - }.onFailure { it.printStackTrace() }.getOrDefault(false) - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - skyBlock = false - } - - @SubscribeEvent - fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { - hypixel = false - skyBlock = false - } - - @SubscribeEvent - fun onChatMessage(event: LorenzChatEvent) { - if (!hypixel) return - - val message = event.message.removeColor().lowercase() - if (message.startsWith("your profile was changed to:")) { - val newProfile = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim() - profileName = newProfile - ProfileJoinEvent(newProfile).postAndCatch() - } - if (message.startsWith("you are playing on profile:")) { - val newProfile = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim() - if (profileName == newProfile) return - profileName = newProfile - ProfileJoinEvent(newProfile).postAndCatch() - } - } - - var tick = 0 - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!hypixel) return - if (event.phase != TickEvent.Phase.START) return - - tick++ - - if (tick % 5 != 0) return - - 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 - " §aⒷ §aBingo", // Rank 1 - " §9Ⓑ §9Bingo", // Rank 2 - " §5Ⓑ §5Bingo", // Rank 3 - " §6Ⓑ §6Bingo", // Rank 4 - -> { - bingo = true - } - - " §7♲ §7Ironman" -> { - ironman = true - } - - " §a☀ §aStranded" -> { - stranded = true - } - } - } - - noTrade = ironman || stranded || bingo - } - - private fun checkIsland() { - var newIsland = "" - var guesting = false - for (line in TabListData.getTabList()) { - if (line.startsWith("§b§lArea: ")) { - newIsland = line.split(": ")[1].removeColor() - } - if (line == " Status: §r§9Guest") { - guesting = true - } - } - - val islandType = getIslandType(newIsland, guesting) - 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 - } - } - - private fun getIslandType(newIsland: String, guesting: Boolean): IslandType { - val islandType = IslandType.getBySidebarName(newIsland) - if (guesting) { - if (islandType == IslandType.PRIVATE_ISLAND) return IslandType.PRIVATE_ISLAND_GUEST - if (islandType == IslandType.GARDEN) return IslandType.GARDEN_GUEST - } - return islandType - } - - private fun checkScoreboard(): Boolean { - val minecraft = Minecraft.getMinecraft() - val world = minecraft.theWorld ?: return false - - val objective = world.scoreboard.getObjectiveInDisplaySlot(1) ?: return false - val displayName = objective.displayName - val scoreboardTitle = displayName.removeColor() - return scoreboardTitle.contains("SKYBLOCK") || - scoreboardTitle.contains("SKIBLOCK") // April 1st jokes are so funny - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt new file mode 100644 index 000000000..cab37ecc0 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -0,0 +1,172 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.IslandChangeEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.utils.LorenzLogger +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.TabListData +import net.minecraft.client.Minecraft +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import net.minecraftforge.fml.common.network.FMLNetworkEvent + +class HypixelData { + + companion object { + var hypixel = false + var skyBlock = false + var skyBlockIsland = IslandType.UNKNOWN + + //Ironman, Stranded and Bingo + var noTrade = false + + var ironman = false + var stranded = false + var bingo = false + + var profileName = "" + + fun readSkyBlockArea(): String { + return ScoreboardData.sidebarLinesFormatted + .firstOrNull { it.startsWith(" §7⏣ ") } + ?.substring(5)?.removeColor() + ?: "invalid" + } + } + + private var loggerIslandChange = LorenzLogger("debug/island_change") + + @SubscribeEvent + fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) { + hypixel = Minecraft.getMinecraft().runCatching { + !event.isLocal && (thePlayer?.clientBrand?.lowercase()?.contains("hypixel") + ?: currentServerData?.serverIP?.lowercase()?.contains("hypixel") ?: false) + }.onFailure { it.printStackTrace() }.getOrDefault(false) + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + skyBlock = false + } + + @SubscribeEvent + fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) { + hypixel = false + skyBlock = false + } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!hypixel) return + + val message = event.message.removeColor().lowercase() + if (message.startsWith("your profile was changed to:")) { + val newProfile = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim() + profileName = newProfile + ProfileJoinEvent(newProfile).postAndCatch() + } + if (message.startsWith("you are playing on profile:")) { + val newProfile = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim() + if (profileName == newProfile) return + profileName = newProfile + ProfileJoinEvent(newProfile).postAndCatch() + } + } + + var tick = 0 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!hypixel) return + if (event.phase != TickEvent.Phase.START) return + + tick++ + + if (tick % 5 != 0) return + + 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 + " §aⒷ §aBingo", // Rank 1 + " §9Ⓑ §9Bingo", // Rank 2 + " §5Ⓑ §5Bingo", // Rank 3 + " §6Ⓑ §6Bingo", // Rank 4 + -> { + bingo = true + } + + " §7♲ §7Ironman" -> { + ironman = true + } + + " §a☀ §aStranded" -> { + stranded = true + } + } + } + + noTrade = ironman || stranded || bingo + } + + private fun checkIsland() { + var newIsland = "" + var guesting = false + for (line in TabListData.getTabList()) { + if (line.startsWith("§b§lArea: ")) { + newIsland = line.split(": ")[1].removeColor() + } + if (line == " Status: §r§9Guest") { + guesting = true + } + } + + val islandType = getIslandType(newIsland, guesting) + 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 + } + } + + private fun getIslandType(newIsland: String, guesting: Boolean): IslandType { + val islandType = IslandType.getBySidebarName(newIsland) + if (guesting) { + if (islandType == IslandType.PRIVATE_ISLAND) return IslandType.PRIVATE_ISLAND_GUEST + if (islandType == IslandType.GARDEN) return IslandType.GARDEN_GUEST + } + return islandType + } + + private fun checkScoreboard(): Boolean { + val minecraft = Minecraft.getMinecraft() + val world = minecraft.theWorld ?: return false + + val objective = world.scoreboard.getObjectiveInDisplaySlot(1) ?: return false + val displayName = objective.displayName + val scoreboardTitle = displayName.removeColor() + return scoreboardTitle.contains("SKYBLOCK") || + scoreboardTitle.contains("SKIBLOCK") // April 1st jokes are so funny + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt index 6b94e0707..e34c99880 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.HyPixelData +import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed @@ -91,7 +91,7 @@ class EliteFarmingWeight { if (weight == -1.0) { if (!isLoadingWeight) { - val localProfile = HyPixelData.profileName + val localProfile = HypixelData.profileName if (localProfile == "") return isLoadingWeight = true diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt index e77db7969..e2572cb0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.HyPixelData +import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -12,7 +12,7 @@ class PasteIntoSigns { @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { - if (!HyPixelData.hypixel) return + if (!HypixelData.hypixel) return if (!SkyHanniMod.feature.misc.pasteIntoSigns) return if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && Keyboard.isKeyDown(Keyboard.KEY_V)) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 13701a95d..a856ae481 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.HyPixelData +import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.features.dungeon.DungeonData import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -23,29 +23,29 @@ import java.util.* object LorenzUtils { val isHyPixel: Boolean - get() = HyPixelData.hypixel && Minecraft.getMinecraft().thePlayer != null + get() = HypixelData.hypixel && Minecraft.getMinecraft().thePlayer != null val inSkyBlock: Boolean - get() = isHyPixel && HyPixelData.skyBlock + get() = isHyPixel && HypixelData.skyBlock val inDungeons: Boolean get() = inSkyBlock && DungeonData.inDungeon() val skyBlockIsland: IslandType - get() = HyPixelData.skyBlockIsland + get() = HypixelData.skyBlockIsland //TODO add cache val skyBlockArea: String - get() = HyPixelData.readSkyBlockArea() + get() = HypixelData.readSkyBlockArea() val inKuudraFight: Boolean get() = skyBlockIsland == IslandType.KUUDRA_ARENA val noTradeMode: Boolean - get() = HyPixelData.noTrade + get() = HypixelData.noTrade val isBingoProfile: Boolean - get() = inSkyBlock && HyPixelData.bingo + get() = inSkyBlock && HypixelData.bingo const val DEBUG_PREFIX = "[SkyHanni Debug] §7" private val log = LorenzLogger("chat/mod_sent") -- cgit