Skip to content

Commit

Permalink
Add kotlin extension (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
noyzys authored Nov 16, 2024
1 parent ce08973 commit 9ef18dd
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions honey-kt-extension/src/dev/shiza/honey/title.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import dev.shiza.honey.dispatcher.TitleMessageDispatcher
import dev.shiza.honey.dispatcher.MessageDispatcher
import dev.shiza.honey.message.Message
import net.kyori.adventure.audience.Audience
import net.kyori.adventure.text.Component

typealias TitleConfigurer = TitleMessageDispatcher<Audience, Message>.() -> Unit
typealias MessageConfigurer = MessageDispatcher<Audience, Message>.() -> Unit

fun times(fadeIn: Int, stay: Int, fadeOut: Int): Triple<Int, Int, Int> =
Triple(fadeIn, stay, fadeOut)


fun TitleMessageDispatcher.createTitle(
recipient: Audience,
titleConfig: MessageConfigurer,
subtitleConfig: MessageConfigurer,
fadeIn: Int,
stay: Int,
fadeOut: Int
): MessageDispatcher<Audience, Message> =
createTitle()
.recipient(recipient)
.title { base -> base.apply(titleConfig) }
.subtitle { base -> base.apply(subtitleConfig) }
.times(fadeIn, stay, fadeOut)

fun Audience.createTitle(
titleConfig: MessageConfigurer,
subtitleConfig: MessageConfigurer,
fadeIn: Int,
stay: Int,
fadeOut: Int
): TitleMessageDispatcher<Audience, Message> =
createTitle()
.recipient(this)
.title { base -> base.apply(titleConfig) }
.subtitle { base -> base.apply(subtitleConfig) }
.times(fadeIn, stay, fadeOut)

fun Player.createTitle(
titleConfig: MessageConfigurer,
subtitleConfig: MessageConfigurer,
fadeIn: Int,
stay: Int,
fadeOut: Int
): TitleMessageDispatcher<Audience, Message> =
createTitle()
.recipient(this)
.title { base -> base.apply(titleConfig) }
.subtitle { base -> base.apply(subtitleConfig) }
.times(fadeIn, stay, fadeOut)


fun TitleConfigurer.withFormattedTitle(messageFormatter: MessageFormatter): TitleMessageDispatcher<Audience, Message> =
this.title { base ->
base.apply { messageFormatter.format(this) }
}

fun Audience.createTitle(
messageFormatter: MessageFormatter<Component>,
titleConfig: MessageConfigurer,
subtitleConfig: MessageConfigurer,
fadeIn: Int,
stay: Int,
fadeOut: Int
): TitleMessageDispatcher<Audience, Message> =
createTitle()
.recipient(this)
.withFormattedTitle(messageFormatter)
.title { base -> base.apply(titleConfig) }
.subtitle { base -> base.apply(subtitleConfig) }
.times(fadeIn, stay, fadeOut)

0 comments on commit 9ef18dd

Please sign in to comment.