|
| 1 | +import dev.shiza.honey.dispatcher.TitleMessageDispatcher |
| 2 | +import dev.shiza.honey.dispatcher.MessageDispatcher |
| 3 | +import dev.shiza.honey.message.Message |
| 4 | +import net.kyori.adventure.audience.Audience |
| 5 | +import net.kyori.adventure.text.Component |
| 6 | + |
| 7 | +typealias TitleConfigurer = TitleMessageDispatcher<Audience, Message>.() -> Unit |
| 8 | +typealias MessageConfigurer = MessageDispatcher<Audience, Message>.() -> Unit |
| 9 | + |
| 10 | +fun times(fadeIn: Int, stay: Int, fadeOut: Int): Triple<Int, Int, Int> = |
| 11 | + Triple(fadeIn, stay, fadeOut) |
| 12 | + |
| 13 | + |
| 14 | +fun TitleMessageDispatcher.createTitle( |
| 15 | + recipient: Audience, |
| 16 | + titleConfig: MessageConfigurer, |
| 17 | + subtitleConfig: MessageConfigurer, |
| 18 | + fadeIn: Int, |
| 19 | + stay: Int, |
| 20 | + fadeOut: Int |
| 21 | +): MessageDispatcher<Audience, Message> = |
| 22 | + createTitle() |
| 23 | + .recipient(recipient) |
| 24 | + .title { base -> base.apply(titleConfig) } |
| 25 | + .subtitle { base -> base.apply(subtitleConfig) } |
| 26 | + .times(fadeIn, stay, fadeOut) |
| 27 | + |
| 28 | +fun Audience.createTitle( |
| 29 | + titleConfig: MessageConfigurer, |
| 30 | + subtitleConfig: MessageConfigurer, |
| 31 | + fadeIn: Int, |
| 32 | + stay: Int, |
| 33 | + fadeOut: Int |
| 34 | +): TitleMessageDispatcher<Audience, Message> = |
| 35 | + createTitle() |
| 36 | + .recipient(this) |
| 37 | + .title { base -> base.apply(titleConfig) } |
| 38 | + .subtitle { base -> base.apply(subtitleConfig) } |
| 39 | + .times(fadeIn, stay, fadeOut) |
| 40 | + |
| 41 | +fun Player.createTitle( |
| 42 | + titleConfig: MessageConfigurer, |
| 43 | + subtitleConfig: MessageConfigurer, |
| 44 | + fadeIn: Int, |
| 45 | + stay: Int, |
| 46 | + fadeOut: Int |
| 47 | +): TitleMessageDispatcher<Audience, Message> = |
| 48 | + createTitle() |
| 49 | + .recipient(this) |
| 50 | + .title { base -> base.apply(titleConfig) } |
| 51 | + .subtitle { base -> base.apply(subtitleConfig) } |
| 52 | + .times(fadeIn, stay, fadeOut) |
| 53 | + |
| 54 | + |
| 55 | +fun TitleConfigurer.withFormattedTitle(messageFormatter: MessageFormatter): TitleMessageDispatcher<Audience, Message> = |
| 56 | + this.title { base -> |
| 57 | + base.apply { messageFormatter.format(this) } |
| 58 | + } |
| 59 | + |
| 60 | +fun Audience.createTitle( |
| 61 | + messageFormatter: MessageFormatter<Component>, |
| 62 | + titleConfig: MessageConfigurer, |
| 63 | + subtitleConfig: MessageConfigurer, |
| 64 | + fadeIn: Int, |
| 65 | + stay: Int, |
| 66 | + fadeOut: Int |
| 67 | +): TitleMessageDispatcher<Audience, Message> = |
| 68 | + createTitle() |
| 69 | + .recipient(this) |
| 70 | + .withFormattedTitle(messageFormatter) |
| 71 | + .title { base -> base.apply(titleConfig) } |
| 72 | + .subtitle { base -> base.apply(subtitleConfig) } |
| 73 | + .times(fadeIn, stay, fadeOut) |
0 commit comments