Skip to content

Commit

Permalink
Feature: Open Contest on elitebot.dev (#1185)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
Obsidianninja11 and hannibal002 authored Apr 1, 2024
1 parent f82744d commit 3ca79ff
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
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
Expand All @@ -18,6 +20,11 @@ public class JacobFarmingContestConfig {
@FeatureToggle
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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>.*)"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*"
)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,6 +80,83 @@ class JacobFarmingContestsInventory {
realTime[slot] = "$dayFormat $startTimeFormat-$endTimeFormat"
}

@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
Expand Down

0 comments on commit 3ca79ff

Please sign in to comment.