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: Bits Gained Chat Message #1487

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ class SkyHanniMod {
loadModule(CraftMaterialsFromBazaar())
loadModule(DungeonShadowAssassinNotification())
loadModule(PestProfitTracker)
loadModule(NoBitsWarning())
loadModule(NoBitsWarning)
loadModule(ColdOverlay())
loadModule(QuiverDisplay())
loadModule(QuiverWarning())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 39
const val CONFIG_VERSION = 40
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package at.hannibal2.skyhanni.config.features.misc;

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class BitsConfig {
@Expose
@ConfigOption(name = "Enable No Bits Warning", desc = "Alerts you when you have no bits available.")
@ConfigEditorBoolean
@FeatureToggle
public boolean enableWarning = true;

@Expose
@ConfigOption(name = "Notification Sound", desc = "Plays a notification sound when you get a warning.")
@ConfigEditorBoolean
public boolean notificationSound = true;

@Expose
@ConfigOption(name = "Bits Gain Chat Message", desc = "Shows a chat message when you gain bits.")
@ConfigEditorBoolean
@FeatureToggle
public boolean bitsGainChatMessage = true;

@Expose
@ConfigOption(name = "Threshold", desc = "The amount of bits you need to have to not get a warning.")
@ConfigEditorSlider(minValue = 0, maxValue = 1000, minStep = 1)
public int threshold = 400;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public class MiscConfig {
public PetCandyDisplayConfig petCandy = new PetCandyDisplayConfig();

@Expose
@ConfigOption(name = "No Bits Warning", desc = "")
@ConfigOption(name = "Bits Features", desc = "")
@Accordion
public NoBitsWarningConfig noBitsWarning = new NoBitsWarningConfig();
public BitsConfig bits = new BitsConfig();

@Expose
@ConfigOption(name = "Patcher Coords Waypoints", desc = "")
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import at.hannibal2.skyhanni.events.BitsUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ScoreboardChangeEvent
import at.hannibal2.skyhanni.features.misc.NoBitsWarning.displayBitsGainChatMessage
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
Expand Down Expand Up @@ -154,7 +154,7 @@ object BitsAPI {

if (amount > bits) {
bitsAvailable -= amount - bits
ChatUtils.debug("You have gained §3${amount - bits} Bits §7according to the scoreboard!")
displayBitsGainChatMessage(amount - bits)
bits = amount
sendBitsGainEvent()
} else {
Expand Down Expand Up @@ -228,7 +228,7 @@ object BitsAPI {

val difference = bits - bitsAvailable
if (difference > 0) {
ChatUtils.debug("You have gained §3${difference} Bits §7according to the menu!")
displayBitsGainChatMessage(difference)
bits += difference
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/features/misc/NoBitsWarning.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.BitsUpdateEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.SoundUtils.createSound
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

class NoBitsWarning {
object NoBitsWarning {

private val config get() = SkyHanniMod.feature.misc.noBitsWarning
private val config get() = SkyHanniMod.feature.misc.bits

fun displayBitsGainChatMessage(bits: Int) {
j10a1n15 marked this conversation as resolved.
Show resolved Hide resolved
if (!isChatMessageEnabled()) return
if (bits < config.threshold) return
ChatUtils.chat("You have gained §b${bits.addSeparators()} §eBits.")
}

@SubscribeEvent
fun onBitsGain(event: BitsUpdateEvent.BitsGain) {
if (!isEnabled()) return
if (!isWarningEnabled()) return
if (event.bitsAvailable != 0) return

ChatUtils.clickableChat(
Expand All @@ -30,7 +37,10 @@ class NoBitsWarning {
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(35, "misc.noBitsWarning", "misc.noBitsWarning.enabled")
event.move(40, "misc.noBitsWarning.enabled", "misc.bits.enableWarning")
event.move(40, "misc.noBitsWarning.notificationSound", "misc.bits.notificationSound")
}

private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
private fun isChatMessageEnabled() = LorenzUtils.inSkyBlock && config.bitsGainChatMessage
private fun isWarningEnabled() = LorenzUtils.inSkyBlock && config.enableWarning
}
Loading