forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Broodmother alerts/messages and damage indicator support (ha…
…nnibal002#2325) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
996b704
commit 4e23db7
Showing
10 changed files
with
322 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...main/java/at/hannibal2/skyhanni/config/features/combat/broodmother/BroodmotherConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package at.hannibal2.skyhanni.config.features.combat.broodmother; | ||
|
||
import at.hannibal2.skyhanni.config.FeatureToggle; | ||
import at.hannibal2.skyhanni.config.core.config.Position; | ||
import at.hannibal2.skyhanni.features.combat.BroodmotherFeatures.StageEntry; | ||
import com.google.gson.annotations.Expose; | ||
import io.github.notenoughupdates.moulconfig.annotations.Accordion; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class BroodmotherConfig { | ||
|
||
@Expose | ||
@ConfigOption(name = "Countdown", desc = "Display a countdown until the Broodmother will spawn.\n" + | ||
"§cCountdown will not show unless the time until spawn has been established, and may be off by a few seconds.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean countdown = true; | ||
|
||
@Expose | ||
@ConfigOption(name = "Spawn Alert", desc = "Send a chat message, title and sound when the Broodmother spawns.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean alertOnSpawn = false; | ||
|
||
@Expose | ||
@ConfigOption(name = "Alert Settings", desc = "") | ||
@Accordion | ||
public BroodmotherSpawnAlertConfig spawnAlert = new BroodmotherSpawnAlertConfig(); | ||
|
||
@Expose | ||
@ConfigOption(name = "Imminent Warning", desc = "Warns you when the Broodmother is 1 minute away from spawning.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean imminentWarning = false; | ||
|
||
@Expose | ||
@ConfigOption(name = "Chat Messages", desc = "Send a chat message when the Broodmother enters these stages.\n" + | ||
"§cThe 'Alive!' and 'Imminent' stages are overridden by the \"Spawn Alert\" and \"Imminent Warning\" features.") | ||
@ConfigEditorDraggableList | ||
public List<StageEntry> stages = new ArrayList<>(Arrays.asList( | ||
StageEntry.SLAIN, | ||
StageEntry.ALIVE | ||
)); | ||
|
||
@Expose | ||
@ConfigOption(name = "Stage on Server Join", desc = "Send a chat message with the Broodmother's current stage upon joining the Spider's Den.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean stageOnJoin = false; | ||
|
||
@Expose | ||
@ConfigOption(name = "Hide own kills", desc = "Disable the chat message for the §eSlain §rstage if at the Spider Mound.") | ||
@ConfigEditorBoolean | ||
@FeatureToggle | ||
public boolean hideSlainWhenNearby = false; | ||
|
||
@Expose | ||
@ConfigLink(owner = BroodmotherConfig.class, field = "countdown") | ||
public Position countdownPosition = new Position(10, 10, false, true); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...at/hannibal2/skyhanni/config/features/combat/broodmother/BroodmotherSpawnAlertConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package at.hannibal2.skyhanni.config.features.combat.broodmother; | ||
|
||
import at.hannibal2.skyhanni.features.combat.BroodmotherFeatures; | ||
import at.hannibal2.skyhanni.utils.OSUtils; | ||
import com.google.gson.annotations.Expose; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorButton; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText; | ||
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; | ||
|
||
public class BroodmotherSpawnAlertConfig { | ||
|
||
@Expose | ||
@ConfigOption(name = "Alert Sound", desc = "The sound that plays for the alert.") | ||
@ConfigEditorText | ||
public String alertSound = "note.pling"; | ||
|
||
@Expose | ||
@ConfigOption(name = "Pitch", desc = "The pitch of the alert sound.") | ||
@ConfigEditorSlider(minValue = 0.5f, maxValue = 2.0f, minStep = 0.1f) | ||
public float pitch = 1.0f; | ||
|
||
@ConfigOption(name = "Test Sound", desc = "Test current sound settings.") | ||
@ConfigEditorButton(buttonText = "Test") | ||
public Runnable testSound = BroodmotherFeatures::playTestSound; | ||
|
||
@Expose | ||
@ConfigOption(name = "Repeat Sound", desc = "How many times the sound should be repeated.") | ||
@ConfigEditorSlider(minValue = 1, maxValue = 20, minStep = 1) | ||
public int repeatSound = 20; | ||
|
||
@ConfigOption(name = "Sounds", desc = "Click to open the list of available sounds.") | ||
@ConfigEditorButton(buttonText = "OPEN") | ||
public Runnable sounds = () -> OSUtils.openBrowser("https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/mapping-and-modding-tutorials/2213619-1-8-all-playsound-sound-arguments"); | ||
|
||
@Expose | ||
@ConfigOption(name = "Text", desc = "The text with color to be displayed as the title notification.") | ||
@ConfigEditorText | ||
public String text = "&4Broodmother has spawned!"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
src/main/java/at/hannibal2/skyhanni/features/combat/BroodmotherFeatures.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package at.hannibal2.skyhanni.features.combat | ||
|
||
import at.hannibal2.skyhanni.SkyHanniMod | ||
import at.hannibal2.skyhanni.data.IslandType | ||
import at.hannibal2.skyhanni.data.model.TabWidget | ||
import at.hannibal2.skyhanni.events.GuiRenderEvent | ||
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent | ||
import at.hannibal2.skyhanni.events.SecondPassedEvent | ||
import at.hannibal2.skyhanni.events.WidgetUpdateEvent | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.ChatUtils | ||
import at.hannibal2.skyhanni.utils.HypixelCommands | ||
import at.hannibal2.skyhanni.utils.LorenzUtils | ||
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland | ||
import at.hannibal2.skyhanni.utils.RenderUtils.renderString | ||
import at.hannibal2.skyhanni.utils.SimpleTimeMark | ||
import at.hannibal2.skyhanni.utils.SoundUtils | ||
import at.hannibal2.skyhanni.utils.SoundUtils.playSound | ||
import at.hannibal2.skyhanni.utils.StringUtils | ||
import at.hannibal2.skyhanni.utils.TimeUtils.format | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
import kotlin.reflect.KMutableProperty0 | ||
import kotlin.time.Duration.Companion.minutes | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlin.time.DurationUnit | ||
|
||
@SkyHanniModule | ||
object BroodmotherFeatures { | ||
|
||
enum class StageEntry(private val str: String, val minutes: Int) { | ||
SLAIN("§eSlain", 10), | ||
DORMANT("§eDormant", 9), | ||
SOON("§6Soon", 6), | ||
AWAKENING("§6Awakening", 3), | ||
IMMINENT("§4Imminent", 1), | ||
ALIVE("§4Alive!", 0); | ||
|
||
override fun toString() = str | ||
} | ||
|
||
private val config get() = SkyHanniMod.feature.combat.broodmother | ||
private val spawnAlertConfig get() = config.spawnAlert | ||
|
||
private var lastStage: StageEntry? = null | ||
private var currentStage: StageEntry? = null | ||
private var broodmotherSpawnTime = SimpleTimeMark.farPast() | ||
private var display = "" | ||
|
||
@SubscribeEvent | ||
fun onTabListUpdate(event: WidgetUpdateEvent) { | ||
if (!event.isWidget(TabWidget.BROODMOTHER)) return | ||
val newStage = event.widget.matchMatcherFirstLine { group("stage") } ?: "" | ||
if (newStage.isNotEmpty()) { | ||
lastStage = currentStage | ||
currentStage = StageEntry.valueOf(newStage.replace("!", "").uppercase()) | ||
onStageUpdate() | ||
} | ||
} | ||
|
||
private fun onStageUpdate() { | ||
ChatUtils.debug("New Broodmother stage: $currentStage") | ||
|
||
if (lastStage == null) { | ||
if (onServerJoin()) return | ||
} | ||
|
||
// ignore Hypixel bug where the stage may temporarily revert to Imminent after the Broodmother's death | ||
if (currentStage == StageEntry.IMMINENT && lastStage == StageEntry.ALIVE) return | ||
|
||
if (currentStage == StageEntry.ALIVE) { | ||
onBroodmotherSpawn() | ||
return | ||
} | ||
|
||
val timeUntilSpawn = currentStage?.minutes?.minutes | ||
broodmotherSpawnTime = SimpleTimeMark.now() + timeUntilSpawn!! | ||
|
||
if (currentStage == StageEntry.IMMINENT && config.imminentWarning) { | ||
playImminentWarning() | ||
return | ||
} | ||
|
||
if (config.stages.contains(currentStage) && lastStage != null) { | ||
if (currentStage == StageEntry.SLAIN) { | ||
onBroodmotherSlain() | ||
} else { | ||
val pluralize = StringUtils.pluralize(timeUntilSpawn.toInt(DurationUnit.MINUTES), "minute") | ||
ChatUtils.chat( | ||
"Broodmother: $lastStage §e-> $currentStage§e. §b${timeUntilSpawn.inWholeMinutes} $pluralize §euntil it spawns!" | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun onServerJoin(): Boolean { | ||
// don't send if user has config enabled for either of the alive messages | ||
// this is so that two messages aren't immediately sent upon joining a server | ||
if (config.stageOnJoin && !(currentStage == StageEntry.ALIVE && isAliveMessageEnabled())) { | ||
val pluralize = StringUtils.pluralize(currentStage?.minutes ?: 0, "minute") | ||
var message = "The Broodmother's current stage in this server is ${currentStage.toString().replace("!", "")}§e." | ||
if (currentStage?.minutes != 0) { | ||
message += " It will spawn within §b${currentStage?.minutes} $pluralize§e." | ||
} | ||
ChatUtils.chat(message) | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
private fun onBroodmotherSpawn() { | ||
broodmotherSpawnTime = SimpleTimeMark.farPast() | ||
if (!isAliveMessageEnabled()) return | ||
val feature: KMutableProperty0<*> | ||
if (config.alertOnSpawn) { | ||
feature = config::alertOnSpawn | ||
val alertSound = SoundUtils.createSound(spawnAlertConfig.alertSound, spawnAlertConfig.pitch) | ||
SoundUtils.repeatSound(100, spawnAlertConfig.repeatSound, alertSound) | ||
LorenzUtils.sendTitle(spawnAlertConfig.text.replace("&", "§"), 3.seconds) | ||
} else { | ||
feature = config::stages | ||
} | ||
ChatUtils.clickToActionOrDisable( | ||
"The Broodmother has spawned!", | ||
feature, | ||
actionName = "warp to the Top of the Nest", | ||
action = { HypixelCommands.warp("nest") }, | ||
) | ||
} | ||
|
||
private fun playImminentWarning() { | ||
SoundUtils.repeatSound(100, 2, SoundUtils.createSound("note.pling", 0.5f)) | ||
ChatUtils.chat("The Broodmother is §4Imminent§e! It will spawn in §b60 seconds§e!") | ||
} | ||
|
||
private fun onBroodmotherSlain() { | ||
broodmotherSpawnTime = SimpleTimeMark.now() + 10.minutes | ||
if (!(config.hideSlainWhenNearby && SpidersDenAPI.isAtTopOfNest())) { | ||
ChatUtils.chat("The Broodmother was killed!") | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
fun onWorldChange(event: LorenzWorldChangeEvent) { | ||
broodmotherSpawnTime = SimpleTimeMark.farPast() | ||
lastStage = null | ||
currentStage = null | ||
display = "" | ||
} | ||
|
||
@SubscribeEvent | ||
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { | ||
if (!isCountdownEnabled()) return | ||
if (display.isEmpty()) return | ||
|
||
config.countdownPosition.renderString(display, posLabel = "Broodmother Countdown") | ||
} | ||
|
||
@SubscribeEvent | ||
fun onSecondPassed(event: SecondPassedEvent) { | ||
if (!isCountdownEnabled()) return | ||
|
||
if (broodmotherSpawnTime.isFarPast()) { | ||
if (lastStage != null) { | ||
display = "§4Broodmother spawned!" | ||
} | ||
} else { | ||
val countdown = broodmotherSpawnTime.timeUntil().format() | ||
display = "§4Broodmother spawning in §b$countdown" | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun playTestSound() { | ||
with(spawnAlertConfig) { | ||
SoundUtils.createSound(alertSound, pitch).playSound() | ||
} | ||
} | ||
|
||
private fun inSpidersDen() = IslandType.SPIDER_DEN.isInIsland() | ||
private fun isCountdownEnabled() = inSpidersDen() && config.countdown | ||
private fun isAliveMessageEnabled() = config.alertOnSpawn || config.stages.contains(StageEntry.ALIVE) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/at/hannibal2/skyhanni/features/combat/SpidersDenAPI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package at.hannibal2.skyhanni.features.combat | ||
|
||
import at.hannibal2.skyhanni.features.gui.customscoreboard.CustomScoreboard | ||
import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.RegexUtils.matches | ||
|
||
@SkyHanniModule | ||
object SpidersDenAPI { | ||
private fun getSbLines(): List<String> = CustomScoreboard.activeLines | ||
fun isAtTopOfNest(): Boolean = getSbLines().any { ScoreboardPattern.broodmotherPattern.matches(it) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.