diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-04-01 20:58:04 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-04-01 20:58:04 +0200 |
commit | 60c5f9c351a7f59622a09cc10a5047c5dca279fa (patch) | |
tree | f9e32e3e1acd5a1e04ad9c2288a6db3f239564bf /src/main/java | |
parent | 7773977c6f328c4f7e187b2a53557b7a8d5bfed8 (diff) | |
parent | 526f1a3e5eb364d240894847f50fcab006688d4d (diff) | |
download | skyhanni-60c5f9c351a7f59622a09cc10a5047c5dca279fa.tar.gz skyhanni-60c5f9c351a7f59622a09cc10a5047c5dca279fa.tar.bz2 skyhanni-60c5f9c351a7f59622a09cc10a5047c5dca279fa.zip |
Merge remote-tracking branch 'origin/beta' into beta
Diffstat (limited to 'src/main/java')
5 files changed, 145 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/JacobFarmingContestConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/JacobFarmingContestConfig.java index dc18bd29d..81d52fcbd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/inventory/JacobFarmingContestConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/inventory/JacobFarmingContestConfig.java @@ -3,7 +3,9 @@ package at.hannibal2.skyhanni.config.features.inventory; import at.hannibal2.skyhanni.config.FeatureToggle; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; import io.github.moulberry.moulconfig.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; public class JacobFarmingContestConfig { @Expose @@ -19,6 +21,11 @@ public class JacobFarmingContestConfig { public boolean realTime = true; @Expose + @ConfigOption(name = "Open On Elite", desc = "Opens the contest on §eelitebot.dev§7 when pressing this key in Jacob's menu or the calendar.") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + public int openOnElite = Keyboard.KEY_NONE; + + @Expose @ConfigOption(name = "Medal Icon", desc = "Adds a symbol that shows what medal you received in this Contest. " + "§eIf you use a texture pack this may cause conflicting icons.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index b4f6050dd..86ccb243c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -26,6 +26,7 @@ import net.minecraft.network.play.server.S02PacketChat import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Matcher import kotlin.time.Duration.Companion.seconds object InquisitorWaypointShare { @@ -33,9 +34,21 @@ object InquisitorWaypointShare { private val config get() = SkyHanniMod.feature.event.diana.inquisitorSharing private val patternGroup = RepoPattern.group("diana.waypoints") + /** + * REGEX-TEST: §9Party §8> User Name§f: §rx: 2.3, y: 4.5, z: 6.7 + */ private val partyPattern by patternGroup.pattern( "party", - "§9Party §8> (?<playerName>.*)§f: §rx: (?<x>-?[0-9]{1,4}), y: (?<y>-?[0-9]{1,4}), z: (?<z>-?[0-9]{1,4})\\b" + "§9Party §8> (?<playerName>.+)§f: §rx: (?<x>[^ ]+),? y: (?<y>[^ ]+),? z: (?<z>[^ ]+)" + ) + + //Support for https://www.chattriggers.com/modules/v/inquisitorchecker + /** + * REGEX-TEST: §9Party §8> UserName§f: §rA MINOS INQUISITOR has spawned near [Foraging Island ] at Coords 1 2 3 + */ + private val inquisitorCheckerPattern by patternGroup.pattern( + "party.inquisitorchecker", + "§9Party §8> (?<playerName>.+)§f: §rA MINOS INQUISITOR has spawned near \\[(?<area>.*)] at Coords (?<x>[^ ]+) (?<y>[^ ]+) (?<z>[^ ]+)" ) private val diedPattern by patternGroup.pattern( "died", @@ -233,27 +246,16 @@ object InquisitorWaypointShare { val message = LorenzUtils.stripVanillaMessage(messageComponent.formattedText) if (packet.type.toInt() != 0) return - partyPattern.matchMatcher(message) { - val rawName = group("playerName") - val x = group("x").trim().toInt() - val y = group("y").trim().toInt() - val z = group("z").trim().toInt() - val location = LorenzVec(x, y, z) - - val name = rawName.cleanPlayerName() - val displayName = rawName.cleanPlayerName(displayName = true) - if (!waypoints.containsKey(name)) { - ChatUtils.chat("$displayName §l§efound an inquisitor at §l§c$x $y $z!") - if (name != LorenzUtils.getPlayerName()) { - LorenzUtils.sendTitle("§dINQUISITOR §efrom §b$displayName", 5.seconds) - SoundUtils.playBeepSound() - } + inquisitorCheckerPattern.matchMatcher(message) { + if (detectFromChat()) { + event.isCanceled = true } - val inquis = SharedInquisitor(name, displayName, location, SimpleTimeMark.now()) - waypoints = waypoints.editCopy { this[name] = inquis } - GriffinBurrowHelper.update() + } - event.isCanceled = true + partyPattern.matchMatcher(message) { + if (detectFromChat()) { + event.isCanceled = true + } } diedPattern.matchMatcher(message) { val rawName = group("playerName") @@ -265,6 +267,28 @@ object InquisitorWaypointShare { } } + private fun Matcher.detectFromChat(): Boolean { + val rawName = group("playerName") + val x = group("x").trim().toDoubleOrNull() ?: return false + val y = group("y").trim().toDoubleOrNull() ?: return false + val z = group("z").trim().toDoubleOrNull() ?: return false + val location = LorenzVec(x, y, z) + + val name = rawName.cleanPlayerName() + val displayName = rawName.cleanPlayerName(displayName = true) + if (!waypoints.containsKey(name)) { + ChatUtils.chat("$displayName §l§efound an inquisitor at §l§c${x.toInt()} ${y.toInt()} ${z.toInt()}!") + if (name != LorenzUtils.getPlayerName()) { + LorenzUtils.sendTitle("§dINQUISITOR §efrom §b$displayName", 5.seconds) + SoundUtils.playBeepSound() + } + } + val inquis = SharedInquisitor(name, displayName, location, SimpleTimeMark.now()) + waypoints = waypoints.editCopy { this[name] = inquis } + GriffinBurrowHelper.update() + return true + } + private fun isEnabled() = DianaAPI.isDoingDiana() && config.enabled fun maybeRemove(inquis: SharedInquisitor) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt index 22eabf10e..9e7a2b6ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -59,11 +59,11 @@ object GardenNextJacobContest { private var inCalendar = false private val patternGroup = RepoPattern.group("garden.nextcontest") - private val dayPattern by patternGroup.pattern( + val dayPattern by patternGroup.pattern( "day", "§aDay (?<day>.*)" ) - private val monthPattern by patternGroup.pattern( + val monthPattern by patternGroup.pattern( "month", "(?<month>.*), Year (?<year>.*)" ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt index f9999fe2c..1e133f8e5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt @@ -33,7 +33,7 @@ object FarmingContestAPI { "crop", "§8(?<crop>.*) Contest" ) - val sidebarCropPattern by patternGroup.pattern( + private val sidebarCropPattern by patternGroup.pattern( "sidebarcrop", "(?:§e○|§6☘) §f(?<crop>.*) §a.*" ) @@ -110,13 +110,15 @@ object FarmingContestAPI { inInventory = false } - fun getSbTimeFor(text: String) = timePattern.matchMatcher(text) { - val month = group("month") + fun getSbDateFromItemName(text: String): List<String>? = timePattern.matchMatcher(text) { + listOf(group("year"), group("month"), group("day")) + } + + fun getSbTimeFor(text: String): Long? { + val (year, month, day) = getSbDateFromItemName(text) ?: return null val monthNr = LorenzUtils.getSBMonthByName(month) - val year = group("year").toInt() - val day = group("day").toInt() - SkyBlockTime(year, monthNr, day).toMillis() + return SkyBlockTime(year.toInt(), monthNr, day.toInt()).toMillis() } fun addContest(time: Long, item: ItemStack) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt index c361c1888..80f068c2a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt @@ -2,24 +2,31 @@ package at.hannibal2.skyhanni.features.garden.contest import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryUpdatedEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.InventoryUtils.getUpperItems import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawSlotText import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest +import net.minecraft.inventory.Slot import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.text.SimpleDateFormat import java.util.Locale @@ -74,6 +81,83 @@ class JacobFarmingContestsInventory { } @SubscribeEvent + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + if (!config.openOnElite.isKeyHeld()) return + if (!LorenzUtils.inSkyBlock) return + + val slot = event.slot ?: return + val itemName = slot.stack.name + + when (val chestName = InventoryUtils.openInventoryName()) { + "Your Contests" -> { + val (year, month, day) = FarmingContestAPI.getSbDateFromItemName(itemName) ?: return + openContest(year, month, day) + event.isCanceled = true + } + + "Jacob's Farming Contests" -> { + openFromJacobMenu(itemName) + event.isCanceled = true + } + + else -> { + openFromCalendar(chestName, itemName, event, slot) + } + } + } + + private fun openContest(year: String, month: String, day: String) { + val date = "$year/${LorenzUtils.getSBMonthByName(month)}/$day" + OSUtils.openBrowser("https://elitebot.dev/contests/$date") + ChatUtils.chat("Opening contest in elitebot.dev") + } + + private fun openFromJacobMenu(itemName: String) { + when (itemName) { + "§6Upcoming Contests" -> { + OSUtils.openBrowser("https://elitebot.dev/contests/upcoming") + ChatUtils.chat("Opening upcoming contests in elitebot.dev") + } + + "§bClaim your rewards!" -> { + OSUtils.openBrowser("https://elitebot.dev/@${LorenzUtils.getPlayerName()}/${HypixelData.profileName}/contests") + ChatUtils.chat("Opening your contests in elitebot.dev") + } + + "§aWhat is this?" -> { + OSUtils.openBrowser("https://elitebot.dev/contests") + ChatUtils.chat("Opening contest page in elitebot.dev") + } + + else -> return + } + } + + private fun openFromCalendar( + chestName: String, + itemName: String, + event: GuiContainerEvent.SlotClickEvent, + slot: Slot, + ) { + GardenNextJacobContest.monthPattern.matchMatcher(chestName) { + if (!slot.stack.getLore().any { it.contains("§eJacob's Farming Contest") }) return + + val day = GardenNextJacobContest.dayPattern.matchMatcher(itemName) { group("day") } ?: return + val year = group("year") + val month = group("month") + val time = SkyBlockTime(year.toInt(), LorenzUtils.getSBMonthByName(month), day.toInt()).toMillis() + if (time < SkyBlockTime.now().toMillis()) { + openContest(year, month, day) + } else { + val timestamp = time / 1000 + OSUtils.openBrowser("https://elitebot.dev/contests/upcoming#$timestamp") + ChatUtils.chat("Opening upcoming contests in elitebot.dev") + } + event.isCanceled = true + } + } + + @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { if (!LorenzUtils.inSkyBlock) return if (!InventoryUtils.openInventoryName().contains("Your Contests")) return |