diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-09-27 18:24:10 -0230 |
---|---|---|
committer | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-09-27 18:24:10 -0230 |
commit | a2c0db53800c353b3b8154964645e7d6499d17ab (patch) | |
tree | 85851b60c5e0d893982745f73d22946d65cf07cc | |
parent | f931dfbaf156aabfa3586a106a852eb9dd964bef (diff) | |
download | RewardClaim-a2c0db53800c353b3b8154964645e7d6499d17ab.tar.gz RewardClaim-a2c0db53800c353b3b8154964645e7d6499d17ab.tar.bz2 RewardClaim-a2c0db53800c353b3b8154964645e7d6499d17ab.zip |
Updated build.gradle to make built jars need the minimal amount of shadowed libs.
Added Config and a config command.
- Made it so that you can disable the confirmation popup.
Fixed some classes have the wrong names.
Added a backup plan to disable the mod via the ExternalConfiguration.
-rw-r--r-- | build.gradle | 25 | ||||
-rw-r--r-- | data.json | 4 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/Command.kt | 13 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/Config.kt | 39 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/ExternalConfiguration.kt (renamed from src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardConfiguration.kt) | 42 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardClaim.kt | 76 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardData.kt | 7 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardLanguage.kt (renamed from src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt) | 2 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/types/WebData.kt | 1 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/RewardClaimGui.kt | 48 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIReward.kt | 6 | ||||
-rw-r--r-- | src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UISelectedReward.kt | 6 |
12 files changed, 159 insertions, 110 deletions
diff --git a/build.gradle b/build.gradle index c5d186a..48fe77b 100644 --- a/build.gradle +++ b/build.gradle @@ -20,8 +20,8 @@ minecraft { } configurations { - include - implementation.extendsFrom(include) + provided + compile.extendsFrom(provided) } repositories { @@ -33,8 +33,8 @@ repositories { } dependencies { - include 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21' - include "gg.essential:loader-launchwrapper:1.1.1" + //include 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21' + provided "gg.essential:loader-launchwrapper:1.1.1" implementation "gg.essential:essential-1.8.9-forge:1457" } @@ -42,21 +42,10 @@ dependencies { * This task simply replaces the `${version}` and `${mcversion}` properties in the mcmod.info with the data from Gradle */ processResources { - // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand 'version': project.version, 'mcversion': project.minecraft.version - } - - // copy everything else, thats not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' + filesMatching("mcmod.info") { + expand "version": project.version, "mcversion": project.minecraft.version } } @@ -77,7 +66,7 @@ tasks.reobfJar.dependsOn(tasks.shadowJar) shadowJar { archiveClassifier.set('') - configurations = [project.configurations.include] + configurations = [project.configurations.provided] duplicatesStrategy DuplicatesStrategy.EXCLUDE } @@ -118,5 +118,7 @@ }, "rewardRegex": "Click the link to visit our website and claim your reward: https://rewards\\.hypixel\\.net/claim-reward/(?<id>[A-Za-z0-9]{8})", "missedRewardRegex": "We noticed you haven't claimed your free Daily Reward yet!\\nTo choose your reward you have to click the link to visit our website! As a reminder, here's your link for today: https://rewards\\.hypixel\\.net/claim-reward/(?<id>[A-Za-z0-9]{8})", - "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36" + "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36", + "disabled": false, + "disabledMessage": "Reward Claim was disabled by the mod author for an unknown reason." } diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/Command.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/Command.kt new file mode 100644 index 0000000..8ba49e0 --- /dev/null +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/Command.kt @@ -0,0 +1,13 @@ +package tech.thatgravyboat.rewardclaim + +import gg.essential.api.EssentialAPI +import gg.essential.api.commands.Command +import gg.essential.api.commands.DefaultHandler + +class Command : Command("rewardclaim") { + + @DefaultHandler + fun handle() { + EssentialAPI.getGuiUtil().openScreen(Config.gui()) + } +}
\ No newline at end of file diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/Config.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/Config.kt new file mode 100644 index 0000000..682b109 --- /dev/null +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/Config.kt @@ -0,0 +1,39 @@ +package tech.thatgravyboat.rewardclaim + +import gg.essential.universal.UDesktop +import gg.essential.vigilance.Vigilant +import gg.essential.vigilance.data.Property +import gg.essential.vigilance.data.PropertyType +import java.io.File +import java.net.URI + +@Suppress("unused") +object Config : Vigilant(File("./config/rewardclaim.toml")) { + + @Property(type = PropertyType.SWITCH, "Show Confirmation", "General", description = "Shows a confirmation before you claim an item to make sure you don't by accidently claim an reward you didn't want.") + var showConfirmation = true + + @Property(type = PropertyType.BUTTON, "Discord", "General", "Self Promotion", placeholder = "Visit") + fun discord() { + UDesktop.browse(URI("https://discord.gg/jRhkYFmpCa")) + } + + @Property(type = PropertyType.BUTTON, "Twitter", "General", "Self Promotion", placeholder = "Visit") + fun twitter() { + UDesktop.browse(URI("https://twitter.com/ThatGravyBoat")) + } + + @Property(type = PropertyType.BUTTON, "Github", "General", "Self Promotion", placeholder = "Visit") + fun github() { + UDesktop.browse(URI("https://github.com/ThatGravyBoat/RewardClaim")) + } + + @Property(type = PropertyType.BUTTON, "YouTube", "General", "Self Promotion", placeholder = "Visit") + fun rickroll() { + UDesktop.browse(URI("https://www.youtube.com/watch?v=dQw4w9WgXcQ")) + } + + init { + initialize() + } +}
\ No newline at end of file diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardConfiguration.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ExternalConfiguration.kt index 01e2af1..89ad572 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardConfiguration.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ExternalConfiguration.kt @@ -1,47 +1,35 @@ package tech.thatgravyboat.rewardclaim import com.google.gson.Gson +import gg.essential.api.utils.WebUtil import tech.thatgravyboat.rewardclaim.types.ImageType import tech.thatgravyboat.rewardclaim.types.RewardImage -import java.io.IOException -import java.net.URL -import java.util.* -import kotlin.collections.HashMap private val GSON = Gson() private val DEFAULT_IMAGE_TYPE = ImageType(142, 100, false) -object RewardConfiguration { +object ExternalConfiguration { private lateinit var imageTypes: HashMap<String, ImageType> lateinit var textures: HashMap<String, RewardImage> lateinit var rewardMessageRegex: Regex lateinit var rewardMissedMessageRegex: Regex lateinit var userAgent: String + var disabled = false + lateinit var disabledMessage: String fun getImageType(type: String?) = if (type == null) DEFAULT_IMAGE_TYPE else imageTypes.getOrDefault(type, DEFAULT_IMAGE_TYPE) fun loadData() { - val config = GSON.fromJson(readData(), JsonConfig::class.java) - textures = config.textures - imageTypes = config.imageTypes - rewardMessageRegex = Regex(config.rewardRegex) - rewardMissedMessageRegex = Regex(config.missedRewardRegex) - userAgent = config.userAgent - } - - private fun readData(): String { - try { - Scanner( - URL("https://raw.githubusercontent.com/ThatGravyBoat/RewardClaim/master/data.json").openStream(), - "UTF-8" - ).use { scanner -> - scanner.useDelimiter("\\A") - return if (scanner.hasNext()) scanner.next() else "" - } - } catch (e: IOException) { - e.printStackTrace() + WebUtil.fetchString("https://raw.githubusercontent.com/ThatGravyBoat/RewardClaim/master/data.json")?.let { + val config = GSON.fromJson(it, JsonConfig::class.java) + textures = config.textures + imageTypes = config.imageTypes + rewardMessageRegex = Regex(config.rewardRegex) + rewardMissedMessageRegex = Regex(config.missedRewardRegex) + userAgent = config.userAgent + disabled = config.disabled + disabledMessage = config.disabledMessage } - return "" } private data class JsonConfig( @@ -49,6 +37,8 @@ object RewardConfiguration { val textures: HashMap<String, RewardImage> = hashMapOf(), val rewardRegex: String = "Click the link to visit our website and claim your reward: https://rewards\\.hypixel\\.net/claim-reward/(?<id>[A-Za-z0-9]{8})", val missedRewardRegex: String = "We noticed you haven't claimed your free Daily Reward yet!\\nTo choose your reward you have to click the link to visit our website! As a reminder, here's your link for today: https://rewards\\.hypixel\\.net/claim-reward/(?<id>[A-Za-z0-9]{8})", - val userAgent: String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36" + val userAgent: String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36", + val disabled: Boolean = false, + val disabledMessage: String = "Reward Claim was disabled by the mod author for an unknown reason." ) }
\ No newline at end of file diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardClaim.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardClaim.kt index 5656692..788b6d6 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardClaim.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardClaim.kt @@ -15,46 +15,58 @@ import tech.thatgravyboat.rewardclaim.ui.RewardClaimGui name = "RewardClaim", modid = "gravyrewardclaim", version = "1.0.0", - modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter" -) -object ForgeTemplate { + modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter") +object RewardClaim { - private var rewardClaimTime: Long = 0 + private var rewardClaimTime: Long = 0 - @Mod.EventHandler - fun onFMLInitialization(event: FMLInitializationEvent?) { - MinecraftForge.EVENT_BUS.register(this) - } + @Mod.EventHandler + fun onFMLInitialization(event: FMLInitializationEvent?) { + MinecraftForge.EVENT_BUS.register(this) + EssentialAPI.getCommandRegistry().registerCommand(Command()) + } - @Mod.EventHandler - fun onPreInit(event: FMLPreInitializationEvent?) { - RewardConfiguration.loadData() - } + @Mod.EventHandler + fun onPreInit(event: FMLPreInitializationEvent?) { + ExternalConfiguration.loadData() + } - @SubscribeEvent - fun onChatMessage(event: ClientChatReceivedEvent) { - RewardConfiguration.rewardMessageRegex.matchEntire(event.message.unformattedText.trim())?.apply { + @SubscribeEvent + fun onChatMessage(event: ClientChatReceivedEvent) { + ExternalConfiguration.rewardMessageRegex.matchEntire(event.message.unformattedText.trim()) + ?.apply { + if (!ExternalConfiguration.disabled) { EssentialAPI.getGuiUtil().openScreen(RewardClaimGui(groups["id"]!!.value)) rewardClaimTime = System.currentTimeMillis() + } else { + EssentialAPI.getNotifications() + .push("Mod Disabled", ExternalConfiguration.disabledMessage) + } } - RewardConfiguration.rewardMissedMessageRegex.matchEntire(event.message.unformattedText.trim())?.apply { - EssentialAPI.getNotifications().push( - "Reward Claim Missed!", - "You missed a reward claim, click on this to open the reward claim gui to claim your reward." - ) { EssentialAPI.getGuiUtil().openScreen(RewardClaimGui(groups["id"]!!.value)) } - event.isCanceled = true + ExternalConfiguration.rewardMissedMessageRegex.matchEntire(event.message.unformattedText.trim()) + ?.apply { + EssentialAPI.getNotifications().push( + "Reward Claim Missed!", + "You missed a reward claim, click on this to open the reward claim gui to claim your reward.") { + if (!ExternalConfiguration.disabled) { + EssentialAPI.getGuiUtil().openScreen(RewardClaimGui(groups["id"]!!.value)) + } else { + EssentialAPI.getNotifications() + .push("Mod Disabled", ExternalConfiguration.disabledMessage) + } + } + event.isCanceled = true } - } + } - @SubscribeEvent - fun onScreen(event: GuiOpenEvent) { - if (EssentialAPI.getGuiUtil() - .openedScreen() is RewardClaimGui && event.gui is GuiScreenBook && System.currentTimeMillis() - rewardClaimTime <= 3000 - ) { - event.isCanceled = true - rewardClaimTime = 0 - } + @SubscribeEvent + fun onScreen(event: GuiOpenEvent) { + if (EssentialAPI.getGuiUtil().openedScreen() is RewardClaimGui && + event.gui is GuiScreenBook && + System.currentTimeMillis() - rewardClaimTime <= 3000) { + event.isCanceled = true + rewardClaimTime = 0 } - -}
\ No newline at end of file + } +} diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardData.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardData.kt index 320f0b7..b2d1b5c 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardData.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardData.kt @@ -1,8 +1,7 @@ package tech.thatgravyboat.rewardclaim.types import com.google.gson.annotations.SerializedName -import tech.thatgravyboat.rewardclaim.RewardConfiguration -import tech.thatgravyboat.rewardclaim.RewardLanguage +import tech.thatgravyboat.rewardclaim.ExternalConfiguration import java.util.* @@ -86,9 +85,9 @@ data class RewardData( rewardPackage?.let { item -> if (id == "housing_package") { val packageId = item.replace("specialoccasion_reward_card_skull_", "") - RewardConfiguration.textures[id + "_" + packageId]?.let { image -> return image } + ExternalConfiguration.textures[id + "_" + packageId]?.let { image -> return image } } } - return RewardConfiguration.textures[id] + return ExternalConfiguration.textures[id] } }
\ No newline at end of file diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardLanguage.kt index 8a9ab36..fae577d 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/RewardLanguage.kt @@ -1,4 +1,4 @@ -package tech.thatgravyboat.rewardclaim +package tech.thatgravyboat.rewardclaim.types private val TRANSLATION_LINE_REGEX = Regex("\"(?<key>.*)\": ?\"(?<text>.*)\",?") diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/WebData.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/WebData.kt index bdaafe1..ca47587 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/WebData.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/types/WebData.kt @@ -1,7 +1,6 @@ package tech.thatgravyboat.rewardclaim.types import com.google.gson.Gson -import tech.thatgravyboat.rewardclaim.RewardLanguage private val GSON = Gson() diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/RewardClaimGui.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/RewardClaimGui.kt index 0e5b054..acdc2f7 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/RewardClaimGui.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/RewardClaimGui.kt @@ -10,7 +10,8 @@ import gg.essential.universal.ChatColor import gg.essential.universal.UDesktop import gg.essential.vigilance.gui.VigilancePalette import org.apache.commons.io.IOUtils -import tech.thatgravyboat.rewardclaim.RewardConfiguration +import tech.thatgravyboat.rewardclaim.Config +import tech.thatgravyboat.rewardclaim.ExternalConfiguration import tech.thatgravyboat.rewardclaim.types.WebData import java.awt.Color import java.net.* @@ -40,7 +41,7 @@ class RewardClaimGui(private val id: String) : WindowScreen() { (url.openConnection() as HttpURLConnection).apply { requestMethod = "GET" useCaches = true - addRequestProperty("User-Agent", RewardConfiguration.userAgent) + addRequestProperty("User-Agent", ExternalConfiguration.userAgent) readTimeout = 15000 connectTimeout = 15000 doOutput = true @@ -141,7 +142,10 @@ class RewardClaimGui(private val id: String) : WindowScreen() { button.onMouseEnter { setColor(BUTTON_HOVER) } button.onMouseLeave { setColor(VigilancePalette.getAccent()) } button.onMouseClick { event -> - if (event.mouseButton == 0 && selected != -1) confirmPopup() + if (event.mouseButton == 0 && selected != -1) { + if (Config.showConfirmation) confirmPopup() + else claimReward() + } event.stopPropagation() } } @@ -239,28 +243,30 @@ class RewardClaimGui(private val id: String) : WindowScreen() { { removePopup() }, "${ChatColor.BOLD}Back", null, - { - runAsync { - try { - (URL("https://rewards.hypixel.net/claim-reward/claim?option=$selected&id=$id&activeAd=${data.activeAd}&_csrf=${data.securityToken}&watchedFallback=false").openConnection() as HttpURLConnection).apply { - requestMethod = "POST" - useCaches = true - addRequestProperty("User-Agent", RewardConfiguration.userAgent) - readTimeout = 15000 - connectTimeout = 15000 - responseCode - CookieManager.setDefault(null) - restorePreviousScreen() - } - } catch (ignored: Exception) { - //IGNORED - } - } - }, + { claimReward() }, "${ChatColor.BOLD}Continue" ) childOf this.window } + private fun claimReward() { + runAsync { + try { + (URL("https://rewards.hypixel.net/claim-reward/claim?option=$selected&id=$id&activeAd=${data.activeAd}&_csrf=${data.securityToken}&watchedFallback=false").openConnection() as HttpURLConnection).apply { + requestMethod = "POST" + useCaches = true + addRequestProperty("User-Agent", ExternalConfiguration.userAgent) + readTimeout = 15000 + connectTimeout = 15000 + responseCode + CookieManager.setDefault(null) + restorePreviousScreen() + } + } catch (ignored: Exception) { + //IGNORED + } + } + } + private fun removePopup() { Window.enqueueRenderOperation { popup?.let { diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIReward.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIReward.kt index 02408d4..ffc698a 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIReward.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIReward.kt @@ -12,9 +12,9 @@ import gg.essential.elementa.utils.withAlpha import gg.essential.universal.ChatColor import gg.essential.vigilance.gui.VigilancePalette import tech.thatgravyboat.rewardclaim.MappedImageCache -import tech.thatgravyboat.rewardclaim.RewardConfiguration -import tech.thatgravyboat.rewardclaim.RewardLanguage +import tech.thatgravyboat.rewardclaim.ExternalConfiguration import tech.thatgravyboat.rewardclaim.types.RewardData +import tech.thatgravyboat.rewardclaim.types.RewardLanguage class UIReward(xConstraint: XConstraint, yConstraint: YConstraint) : UIBlock(VigilancePalette.getHighlight().withAlpha(204)) { @@ -96,7 +96,7 @@ class UIReward(xConstraint: XConstraint, yConstraint: YConstraint) : data.image?.let { it.url?.let { url -> - val imageType = RewardConfiguration.getImageType(it.imageType) + val imageType = ExternalConfiguration.getImageType(it.imageType) UIImage.ofURL(url, MappedImageCache).constrain { width = imageType.width.percent() height = imageType.height.percent() diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UISelectedReward.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UISelectedReward.kt index 863ebc5..447c3c5 100644 --- a/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UISelectedReward.kt +++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UISelectedReward.kt @@ -12,9 +12,9 @@ import gg.essential.elementa.utils.withAlpha import gg.essential.universal.ChatColor import gg.essential.vigilance.gui.VigilancePalette import tech.thatgravyboat.rewardclaim.MappedImageCache -import tech.thatgravyboat.rewardclaim.RewardConfiguration -import tech.thatgravyboat.rewardclaim.RewardLanguage +import tech.thatgravyboat.rewardclaim.ExternalConfiguration import tech.thatgravyboat.rewardclaim.types.RewardData +import tech.thatgravyboat.rewardclaim.types.RewardLanguage class UISelectedReward(middle: XConstraint) : UIBlock(VigilancePalette.getHighlight().withAlpha(204)) { @@ -76,7 +76,7 @@ class UISelectedReward(middle: XConstraint) : UIBlock(VigilancePalette.getHighli data.image?.let { it.url?.let { url -> - val imageType = RewardConfiguration.getImageType(it.imageType) + val imageType = ExternalConfiguration.getImageType(it.imageType) image?.let(imageBackground::removeChild) image = UIImage.ofURL(url, MappedImageCache).constrain { width = imageType.width.percent() |