diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-03-14 06:26:07 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-13 20:26:07 +0100 |
commit | dbd6090a3a232d2211b898df8e026eac68e5abdb (patch) | |
tree | c8e13b9109e79e97aecf9a6109667148db0c9a20 | |
parent | b3b9f855f665158b8646095c011f1ae85e05c09a (diff) | |
download | skyhanni-dbd6090a3a232d2211b898df8e026eac68e5abdb.tar.gz skyhanni-dbd6090a3a232d2211b898df8e026eac68e5abdb.tar.bz2 skyhanni-dbd6090a3a232d2211b898df8e026eac68e5abdb.zip |
Backend + Fix: Improve visitor getting (#1121)
5 files changed, 54 insertions, 46 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index b101662f2..2732d68b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -208,6 +208,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorTimer import at.hannibal2.skyhanni.features.garden.visitor.HighlightVisitorsOutsideOfGarden import at.hannibal2.skyhanni.features.garden.visitor.NPCVisitorFix +import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorListener import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern @@ -498,6 +499,7 @@ class SkyHanniMod { loadModule(BitsAPI) loadModule(MayorAPI) loadModule(SkillAPI) + loadModule(VisitorAPI) loadModule(IsFishingDetection) loadModule(LorenzUtils) loadModule(NEUItems) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index 09e02c94f..ef1077cf9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -33,8 +33,8 @@ class GardenVisitorTimer { private val config get() = GardenAPI.config.visitors.timer private val timePattern by RepoPattern.pattern( - "garden.visitor.timer.time", - "§b§lVisitors: §r§f\\((?<time>.*)\\)" + "garden.visitor.timer.time.new", + " Next Visitor: §r(?<info>.*)" ) private var display = "" @@ -95,23 +95,19 @@ class GardenVisitorTimer { var visitorInterval = visitorInterval ?: return var millis = visitorInterval var queueFull = false - for (line in TabListData.getTabList()) { - if (line == "§b§lVisitors: §r§f(§r§c§lQueue Full!§r§f)") { - queueFull = true - continue - } - if (line == "§b§lVisitors: §r§f(§r§cNot Unlocked!§r§f)") { - display = "" - return - } - + loop@ for (line in TabListData.getTabList()) { timePattern.matchMatcher(line) { - val rawTime = group("time").removeColor() - if (lastTimerValue != rawTime) { + val timeInfo = group("info").removeColor() + if (timeInfo == "Queue Full!") { + queueFull = true + break@loop + } + if (lastTimerValue != timeInfo) { lastTimerUpdate = SimpleTimeMark.now() - lastTimerValue = rawTime + lastTimerValue = timeInfo } - millis = TimeUtils.getDuration(rawTime) + millis = TimeUtils.getDuration(timeInfo) + break@loop } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index ad7c6f192..cfd32e5e0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -12,8 +12,10 @@ import at.hannibal2.skyhanni.utils.ColorUtils.withAlpha import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzLogger -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.isInt +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack object VisitorAPI { @@ -23,6 +25,16 @@ object VisitorAPI { val config get() = GardenAPI.config.visitors private val logger = LorenzLogger("garden/visitors/api") + val patternGroup = RepoPattern.group("garden.visitor.api") + private val visitorCountPattern by patternGroup.pattern( + "visitor.count", + "§b§lVisitors: §r§f\\((?<info>.*)\\)" + ) + private val visitorNamePattern by patternGroup.pattern( + "visitor.name", + " (?:§.)+(?<name>§.[^§]+).*" + ) + fun getVisitorsMap() = visitors fun getVisitors() = visitors.values fun getVisitor(id: Int) = visitors.map { it.value }.find { it.entityId == id } @@ -142,36 +154,34 @@ object VisitorAPI { } fun visitorsInTabList(tabList: List<String>): MutableList<String> { + var visitorCount = 0 var found = false + var visitorsRemaining = 0 + val visitorsInTab = mutableListOf<String>() - for (line in tabList) { - if (line.startsWith("§b§lVisitors:")) { + loop@ for (line in tabList) { + visitorCountPattern.matchMatcher(line) { found = true - continue + val countInfo = group("info") + if (countInfo.isInt()) { + visitorCount = countInfo.toInt() + } else if (countInfo == "§r§c§lQueue Full!§r§f") visitorCount = 5 + + visitorsRemaining = visitorCount + continue@loop } - if (!found) continue - if (line.isEmpty() || line.contains("Account Info") || line.contains("Next Visitor")) { + if (!found) continue + if (visitorsRemaining <= 0) { found = false continue } - val name = fromHypixelName(line) - // Hide hypixel watchdog entries - if (name.contains("§c") && !name.contains("Spaceman") && !name.contains("Grandma Wolf")) { - logger.log("Ignore wrong red name: '$name'") - continue + visitorNamePattern.matchMatcher(line) { + visitorsInTab.add(group("name").trim()) } - // hide own player name - if (name.contains(LorenzUtils.getPlayerName())) { - logger.log("Ignore wrong own name: '$name'") - continue - } - val finalName = if (name.endsWith(" §b§lNEW!")) { - name.split(" §b§lNEW!")[0] - } else name - visitorsInTab.add(finalName) + visitorsRemaining-- } return visitorsInTab } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt index 85fb441ab..f372b723e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorListener.kt @@ -14,7 +14,6 @@ import at.hannibal2.skyhanni.events.garden.visitor.VisitorRenderEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.VisitorStatus -import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.config import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -35,10 +34,11 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import org.lwjgl.input.Keyboard -private val config get() = VisitorAPI.config class VisitorListener { + private val config get() = VisitorAPI.config + private var lastClickedNpc = 0 private val logger = LorenzLogger("garden/visitors/listener") diff --git a/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt index c95e4ec03..8649ef199 100644 --- a/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt +++ b/src/test/java/at/hannibal2/skyhanni/test/garden/VisitorListenerTest.kt @@ -34,11 +34,11 @@ class VisitorListenerTest { listener.onTabListUpdate( TabListUpdateEvent( mutableListOf( - "§b§lVisitors:", - "§cSpaceman", - "§cGrandma Wolf", + "§b§lVisitors: §r§f(3)", + " §r§cSpaceman", + " §r§6Madame Eleanor Q. Goldsworth III §r§fCarrot §r§c333 C §r§3107k FXP §r§275 GXP", + " §r§fJacob", "ThePlayerName", - "Jacob", "", ) ) @@ -46,7 +46,7 @@ class VisitorListenerTest { verify { VisitorAPI.addVisitor("§fJacob") } verify { VisitorAPI.addVisitor("§cSpaceman") } - verify { VisitorAPI.addVisitor("§cGrandma Wolf") } + verify { VisitorAPI.addVisitor("§6Madame Eleanor Q. Goldsworth III") } } @Test @@ -57,7 +57,7 @@ class VisitorListenerTest { listener.onTabListUpdate( TabListUpdateEvent( - mutableListOf("§b§lVisitors:", "") + mutableListOf("§b§lVisitors: §r§f(0)", "") ) ) @@ -74,10 +74,10 @@ class VisitorListenerTest { listener.onTabListUpdate( TabListUpdateEvent( - mutableListOf("§b§lVisitors:", "") + mutableListOf("§b§lVisitors: §r§f(0)", "") ) ) verify(exactly = 0) { VisitorAPI.removeVisitor("§fJacob") } } -}
\ No newline at end of file +} |