summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt88
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/EventWaypointsJson.java25
2 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index 1b0b46352..8e7379365 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigManager.Companion.gson
import at.hannibal2.skyhanni.events.HypixelJoinEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
@@ -8,22 +9,34 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.features.bingo.BingoAPI
+import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
+import com.google.gson.JsonObject
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraft.client.Minecraft
+import net.minecraftforge.client.event.ClientChatReceivedEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.network.FMLNetworkEvent
+import kotlin.concurrent.thread
+
class HypixelData {
// TODO USE SH-REPO
private val tabListProfilePattern = "§e§lProfile: §r§a(?<profile>.*)".toPattern()
+ private val lobbyTypePattern = "(?<lobbyType>.*lobby)\\d+".toPattern()
+
+ private var lastLocRaw = 0L
companion object {
var hypixelLive = false
var hypixelAlpha = false
+ var inLobby = false
+ var inLimbo = false
var skyBlock = false
var skyBlockIsland = IslandType.UNKNOWN
@@ -38,13 +51,35 @@ class HypixelData {
var joinedWorld = 0L
var skyBlockArea = "?"
+
+ // Data from locraw
+ var locrawData: JsonObject? = null
+ private var locraw: MutableMap<String, String> = mutableMapOf(
+ "server" to "",
+ "gametype" to "",
+ "lobbyname" to "",
+ "lobbytype" to "",
+ "mode" to "",
+ "map" to ""
+ )
+
+ val server get() = locraw["server"] ?: ""
+ val gameType get() = locraw["gametype"] ?: ""
+ val lobbyName get() = locraw["lobbyname"] ?: ""
+ val lobbyType get() = locraw["lobbytype"] ?: ""
+ val mode get() = locraw["mode"] ?: ""
+ val map get() = locraw["map"] ?: ""
}
private var loggerIslandChange = LorenzLogger("debug/island_change")
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
+ locrawData = null
skyBlock = false
+ inLimbo = false
+ inLobby = false
+ locraw.forEach { locraw[it.key] = "" }
joinedWorld = System.currentTimeMillis()
}
@@ -53,6 +88,9 @@ class HypixelData {
hypixelLive = false
hypixelAlpha = false
skyBlock = false
+ inLobby = false
+ locraw.forEach { locraw[it.key] = "" }
+ locrawData = null
}
@SubscribeEvent
@@ -75,6 +113,26 @@ class HypixelData {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
+ if (!LorenzUtils.inSkyBlock) {
+ // Modified from NEU.
+ // NEU does not send locraw when not in SkyBlock.
+ // So, as requested by Hannibal, use locraw from
+ // NEU and have NEU send it.
+ // Remove this when NEU dependency is removed
+ val currentTime = System.currentTimeMillis()
+ if (Minecraft.getMinecraft().thePlayer != null &&
+ Minecraft.getMinecraft().theWorld != null &&
+ locrawData == null &&
+ currentTime - lastLocRaw > 15000
+ ) {
+ lastLocRaw = System.currentTimeMillis()
+ thread(start = true) {
+ Thread.sleep(1000)
+ NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw")
+ }
+ }
+ }
+
if (event.isMod(2) && LorenzUtils.inSkyBlock) {
val originalLocation = ScoreboardData.sidebarLinesFormatted
.firstOrNull { it.startsWith(" §7⏣ ") || it.startsWith(" §5ф ") }
@@ -193,4 +251,34 @@ class HypixelData {
return scoreboardTitle.contains("SKYBLOCK") ||
scoreboardTitle.contains("SKIBLOCK") // April 1st jokes are so funny
}
+
+ // This code is modified from NEU, and depends on NEU (or another mod) sending /locraw.
+ private val jsonBracketPattern = "^\\{.+}".toPattern()
+
+ @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
+ fun onChatMessage(event: ClientChatReceivedEvent) {
+ jsonBracketPattern.matchMatcher(event.message.unformattedText) {
+ try {
+ val obj: JsonObject = gson.fromJson(group(), JsonObject::class.java)
+ if (obj.has("server")) {
+ locrawData = obj
+ locraw.keys.forEach { key ->
+ locraw[key] = obj[key]?.asString ?: ""
+ }
+ inLimbo = locraw["server"] == "limbo"
+ inLobby = locraw["lobbyname"] != ""
+
+ if (inLobby) {
+ locraw["lobbyname"]?.let {
+ lobbyTypePattern.matchMatcher(it) {
+ locraw["lobbytype"] = group("lobbyType")
+ }
+ }
+ }
+ }
+ } catch (e: Exception) {
+ ErrorManager.logErrorWithData(e, "Failed to parse locraw data")
+ }
+ }
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/EventWaypointsJson.java b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/EventWaypointsJson.java
new file mode 100644
index 000000000..f59af9ffb
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/EventWaypointsJson.java
@@ -0,0 +1,25 @@
+package at.hannibal2.skyhanni.data.jsonobjects.repo;
+
+import at.hannibal2.skyhanni.utils.LorenzVec;
+import com.google.gson.annotations.Expose;
+
+import java.util.List;
+import java.util.Map;
+
+public class EventWaypointsJson {
+
+ @Expose
+ public Map<String, List<Waypoint>> presents;
+
+ @Expose
+ public Map<String, List<Waypoint>> presents_entrances;
+
+ public static class Waypoint {
+ @Expose
+ public String name;
+
+ //format: "x:y:z"
+ @Expose
+ public LorenzVec position;
+ }
+}