aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorObsidian <108832807+Obsidianninja11@users.noreply.github.com>2024-04-01 10:56:00 -0800
committerGitHub <noreply@github.com>2024-04-01 20:56:00 +0200
commit3ca79ff57c4369e6fee5039e485e7abef1e1e3ab (patch)
tree099f9cabe74baeb58b87d1f588f638ca52106e62 /src/main/java/at
parentf82744d9e30c8692dd61a5365cd95baeeb30da0c (diff)
downloadskyhanni-3ca79ff57c4369e6fee5039e485e7abef1e1e3ab.tar.gz
skyhanni-3ca79ff57c4369e6fee5039e485e7abef1e1e3ab.tar.bz2
skyhanni-3ca79ff57c4369e6fee5039e485e7abef1e1e3ab.zip
Feature: Open Contest on elitebot.dev (#1185)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/inventory/JacobFarmingContestConfig.java7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/contest/FarmingContestAPI.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt84
4 files changed, 101 insertions, 8 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/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