Improved counterMessage
This commit is contained in:
@@ -4,28 +4,48 @@ package net.axay.kspigot.game
|
|||||||
|
|
||||||
import net.axay.kspigot.extensions.broadcast
|
import net.axay.kspigot.extensions.broadcast
|
||||||
import net.axay.kspigot.runnables.task
|
import net.axay.kspigot.runnables.task
|
||||||
import net.md_5.bungee.api.ChatColor
|
|
||||||
|
|
||||||
class GamePhaseSystem(vararg gamePhases: GamePhase) {
|
class GamePhaseSystem(vararg gamePhases: GamePhase) {
|
||||||
val gamePhases = gamePhases.toMutableList()
|
val gamePhases = gamePhases.toMutableList()
|
||||||
fun begin() = gamePhases.removeAt(0).startIt(gamePhases)
|
fun begin() = gamePhases.removeAt(0).startIt(gamePhases)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun counterMessage(
|
fun buildCounterMessageCallback(
|
||||||
beginning: String,
|
beforeTime: String? = null,
|
||||||
seconds: String,
|
afterTime: String? = null,
|
||||||
second: String,
|
hours: String = "h",
|
||||||
prefix: String? = null,
|
minutes: String = "m",
|
||||||
suffix: String? = null
|
seconds: String = "s"
|
||||||
): (Long) -> String {
|
): (Long) -> String = { curSeconds ->
|
||||||
|
|
||||||
val realPrefix = prefix?.plus(" ") ?: ""
|
StringBuilder().apply {
|
||||||
val realSuffix = suffix ?: ""
|
append(beforeTime)
|
||||||
|
|
||||||
return {
|
val hourTime = (curSeconds / 3600)
|
||||||
val realSeconds = if (it <= 1L) second else seconds
|
val minuteTime = ((curSeconds % 3600) / 60)
|
||||||
"$realPrefix${ChatColor.RESET}$beginning $it $realSeconds$realSuffix"
|
val secondsTime = (curSeconds % 60)
|
||||||
}
|
|
||||||
|
if (hourTime != 0L)
|
||||||
|
append("${hourTime.toString().run { if (length < 2) "0$this" else this }}:")
|
||||||
|
|
||||||
|
if ((hourTime != 0L && secondsTime != 0L) || (minuteTime != 0L && secondsTime != 0L))
|
||||||
|
append("${minuteTime.toString().run { if (length < 2) "0$this" else this }}:")
|
||||||
|
else if (minuteTime != 0L)
|
||||||
|
append(minuteTime.toString().run { if (length < 2) "0$this" else this })
|
||||||
|
|
||||||
|
if (secondsTime != 0L)
|
||||||
|
append(secondsTime.toString().run { if (length < 2) "0$this" else this })
|
||||||
|
|
||||||
|
append(" ").append(kotlin.run {
|
||||||
|
return@run when {
|
||||||
|
secondsTime != 0L -> seconds
|
||||||
|
minuteTime != 0L -> minutes
|
||||||
|
else -> hours
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
append(afterTime)
|
||||||
|
}.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,13 +32,13 @@ class GamePhaseBuilder(val length: Long) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun counterMessage(
|
fun counterMessage(
|
||||||
beginning: String,
|
beforeTime: String? = null,
|
||||||
seconds: String,
|
afterTime: String? = null,
|
||||||
second: String,
|
hours: String = "h",
|
||||||
prefix: String? = null,
|
minutes: String = "m",
|
||||||
suffix: String? = null
|
seconds: String = "s"
|
||||||
) {
|
) {
|
||||||
counterMessage = net.axay.kspigot.game.counterMessage(beginning, seconds, second, prefix, suffix)
|
counterMessage = buildCounterMessageCallback(beforeTime, afterTime, hours, minutes, seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun build() = GamePhase(length, start, end, counterMessage)
|
fun build() = GamePhase(length, start, end, counterMessage)
|
||||||
|
Reference in New Issue
Block a user