
walkmc.Notification.kt Maven / Gradle / Ivy
package walkmc
import kotlinx.serialization.*
import org.bukkit.entity.*
import walkmc.extensions.*
import walkmc.extensions.collections.*
import walkmc.extensions.strings.*
import walkmc.placeholder.*
import walkmc.serializer.serial.*
/**
* Represents a notification, this is, a serializable message that can be serialized
* in configurations and used to send them to a player.
*/
@Serializable
sealed class Notification(var notificate: Boolean = true) {
/**
* Sends the notification to the player.
*/
abstract fun log(player: Player)
}
/**
* A notification that is sended to the player in the chat.
*/
@Serializable
@SerialName("CHAT")
open class Chat(@Serializable(StringListSerializer::class) var message: List) : Notification() {
constructor(vararg message: String) : this(message.toList())
override fun log(player: Player) {
if (!notificate) return
player.log(message.process(PlayerPlaceholder, player))
}
}
/**
* A notification that is sended to the player action bar.
*/
@Serializable
@SerialName("ACTION_BAR")
open class ActionBar(var message: String) : Notification() {
override fun log(player: Player) {
if (!notificate) return
player.action(message.process(PlayerPlaceholder, player))
}
}
/**
* A notification that is sended to the player title.
*/
@Serializable
@SerialName("TITLE")
open class Title(
var title: String,
var subtitle: String,
var fadeIn: Int = 20,
var stay: Int = 40,
var fadeOut: Int = 20,
) : Notification() {
override fun log(player: Player) {
if (!notificate) return
player.title(
title.process(PlayerPlaceholder, player),
subtitle.process(PlayerPlaceholder, player),
fadeIn, stay, fadeOut
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy