-
Notifications
You must be signed in to change notification settings - Fork 10
Add: Invincibility Timer #95
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
Draft
raaaaaven
wants to merge
14
commits into
main
Choose a base branch
from
invincibility-timer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
739c04f
add invincibility timer
raaaaaven 9e479a6
reset on WorldChangeEvent
raaaaaven d743293
oops
raaaaaven 1f0f5de
Merge branch 'refs/heads/main' into invincibility-timer
raaaaaven fc4cb6f
thank you dave
raaaaaven b14746b
Update src/main/kotlin/at/raven/ravenAddons/config/ravenAddonsConfig.kt
raaaaaven c2c89f7
Merge remote-tracking branch 'origin/invincibility-timer' into invinc…
raaaaaven 05ac974
thank you dave
raaaaaven 7a0dd7b
thank you dave
raaaaaven 54b0681
thank you jordo
raaaaaven 1e86f18
create invincibilityJob
raaaaaven d2eaf0d
remove invincibilityActive
raaaaaven 73ae044
push changes
raaaaaven cd531e9
push remaining changes
raaaaaven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/at/raven/ravenAddons/features/skyblock/InvincibilityTimer.kt
This file contains hidden or 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,82 @@ | ||
|
|
||
| import at.raven.ravenAddons.config.ravenAddonsConfig | ||
| import at.raven.ravenAddons.data.HypixelGame | ||
| import at.raven.ravenAddons.event.WorldChangeEvent | ||
| import at.raven.ravenAddons.event.chat.ChatReceivedEvent | ||
| import at.raven.ravenAddons.loadmodule.LoadModule | ||
| import at.raven.ravenAddons.ravenAddons | ||
| import at.raven.ravenAddons.utils.ChatUtils | ||
| import at.raven.ravenAddons.utils.RegexUtils.matches | ||
| import at.raven.ravenAddons.utils.ServerTimeMark | ||
| import at.raven.ravenAddons.utils.TitleManager | ||
| import kotlinx.coroutines.CancellationException | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.delay | ||
| import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
| import java.util.regex.Pattern | ||
| import kotlin.time.Duration | ||
| import kotlin.time.Duration.Companion.seconds | ||
|
|
||
| @LoadModule | ||
| object InvincibilityTimer { | ||
| private var invincibilityJob: Job? = null | ||
|
|
||
| enum class Invincibility( | ||
| val pattern: Pattern, | ||
| val cooldown: Duration, | ||
| ) { | ||
| BONZO("^Your (?:. )?Bonzo's Mask saved your life!".toPattern(), 3.seconds), | ||
| PHOENIX("^Your Phoenix Pet saved you from certain death!".toPattern(), 4.seconds), | ||
| SPIRIT("^Second Wind Activated! Your Spirit Mask saved your life!".toPattern(), 3.seconds), | ||
| ; | ||
|
|
||
| companion object { | ||
| fun match(message: String): Invincibility? = entries.find { it.pattern.matches(message) } | ||
| } | ||
| } | ||
|
|
||
| @SubscribeEvent | ||
| fun onChat(event: ChatReceivedEvent) { | ||
| if (!HypixelGame.inSkyBlock || !ravenAddonsConfig.invincibilityTimer) return | ||
|
|
||
| val invincibility = Invincibility.match(event.cleanMessage) ?: return | ||
| invincibilityJob?.cancel() | ||
| invincibilityJob = | ||
| ravenAddons.launchCoroutine { | ||
| try { | ||
| val timer = ServerTimeMark.now() + invincibility.cooldown | ||
| while (timer.isInFuture()) { | ||
| val timeUntil = timer.timeUntil() | ||
| val formattedTime = timeUntil.inWholeMilliseconds / 1000f | ||
| val color = | ||
| when { | ||
| timeUntil > 2.seconds -> "§a" | ||
| timeUntil > 1.seconds -> "§e" | ||
| else -> "§c" | ||
| } | ||
| TitleManager.setTitle( | ||
| "$color%.3f".format(formattedTime), | ||
| "", | ||
| 1.seconds, | ||
| 0.seconds, | ||
| 0.seconds, | ||
| ) | ||
| delay(50) | ||
| } | ||
| } catch (e: CancellationException) { | ||
| ChatUtils.debug("Invincibility Timer: Invincibility Job cancelled: ${e.message}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @SubscribeEvent | ||
| fun onWorldLoad(event: WorldChangeEvent) { | ||
| if (!HypixelGame.inSkyBlock || !ravenAddonsConfig.invincibilityTimer) return | ||
| invincibilityJob?.let { | ||
| if (it.isActive) { | ||
| it.cancel() | ||
| } | ||
| invincibilityJob = null | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavidArthurCole hates you for this