Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Open Contest on elitebot.dev #1185

Merged
merged 9 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Online", desc = "Opens the contest on §eelitebot.dev§7 when clicking with this key held.")
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE)
public int openOnline = Keyboard.KEY_NONE;
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved

@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 @@ -5,29 +5,17 @@ import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.enums.OutsideSbFeature
import at.hannibal2.skyhanni.config.features.garden.NextJacobContestConfig.ShareContestsEntry
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.events.*
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderSingleLineWithItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.TimeUtils.format
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.Gson
Expand Down Expand Up @@ -59,11 +47,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
@@ -1,11 +1,7 @@
package at.hannibal2.skyhanni.features.garden.contest

import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.events.FarmingContestEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.*
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
Expand All @@ -25,7 +21,7 @@ import kotlin.time.Duration.Companion.minutes
object FarmingContestAPI {

private val patternGroup = RepoPattern.group("garden.farming.contest")
private val timePattern by patternGroup.pattern(
val timePattern by patternGroup.pattern(
"time",
"§a(?<month>.*) (?<day>.*)(?:rd|st|nd|th), Year (?<year>.*)"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ package at.hannibal2.skyhanni.features.garden.contest

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
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.utils.InventoryUtils
import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.events.*
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest
import at.hannibal2.skyhanni.utils.*
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.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.NumberUtil.addSuffix
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.events.SlotClickEvent
import io.github.moulberry.notenoughupdates.util.SkyBlockTime
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.net.URLEncoder
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.*

class JacobFarmingContestsInventory {

Expand Down Expand Up @@ -73,6 +74,66 @@ class JacobFarmingContestsInventory {
realTime[slot] = "$dayFormat $startTimeFormat-$endTimeFormat"
}

@SubscribeEvent
fun onSlotClick(event: SlotClickEvent) {
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
if (!config.openOnline.isKeyHeld()) return
if (!LorenzUtils.inSkyBlock) return
val invName = InventoryUtils.openInventoryName()
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
val name = event.slot.stack.name
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved

when (invName) {
"Your Contests" -> {
FarmingContestAPI.timePattern.matchMatcher(name) {
val date = getDate(group("year"), group("month"), group("day"))
OSUtils.openBrowser("https://elitebot.dev/contests/$date")
ChatUtils.chat("Opening contest in elitebot.dev")
Obsidianninja11 marked this conversation as resolved.
Show resolved Hide resolved
event.isCanceled = true
}
}
"Jacob's Farming Contests" -> {
when (name) {
"§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
}
event.isCanceled = true
}
else -> {
GardenNextJacobContest.monthPattern.matchMatcher(invName) {
if (!event.slot.stack.getLore().any { it.contains("§eJacob's Farming Contest") }) return

val day = GardenNextJacobContest.dayPattern.matchMatcher(name) { 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()) {
val date = getDate(year, month, day)
OSUtils.openBrowser("https://elitebot.dev/contests/$date")
ChatUtils.chat("Opening contest in elitebot.dev")
} else {
val highlightText = URLEncoder.encode("$month ${day.toInt().addSuffix()}, Year $year", "UTF-8").replace("+", "%20")
OSUtils.openBrowser("https://elitebot.dev/contests/upcoming#:~:text=$highlightText")
println("highlight: $highlightText")
ChatUtils.chat("Opening upcoming contests in elitebot.dev")
}
event.isCanceled = true
}
}
}
}

private fun getDate(year: String, month: String, day: String) = "$year/${LorenzUtils.getSBMonthByName(month)}/$day"

@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!LorenzUtils.inSkyBlock) return
Expand Down
Loading