Skip to content

Commit

Permalink
fix: pretty print for schedules list
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucky3028 committed Aug 25, 2022
1 parent 7f06bb6 commit 9e66dfd
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,26 @@ import click.seichi.regenerateworld.presenter.shared.contextualexecutor.{
ContextualExecutor,
Result
}
import click.seichi.regenerateworld.presenter.shared.exception.CommandException
import org.bukkit.ChatColor
import org.bukkit.entity.Player

object ListSchedules extends ContextualExecutor {
val help: EchoExecutor = EchoExecutor(List("/rw list", "有効な再生成予定の一覧を表示します。"))

def executionWith(context: CommandContext): Result[Unit] = {
val sender = context.sender match {
case p: Player => p
case _ => return Left(CommandException.OnlyPlayerCanExecute)
}
val formattedSchedules = for {
schedule <- GenerationScheduleUseCase.list()
formattedInterval = s"${schedule.interval.value}${schedule.interval.unit.suffix}"
formattedSchedule = s"${schedule.id}: ${schedule.worlds.mkString(", ")} | $formattedInterval | ${schedule.seedPattern.entryName} | ${schedule.nextDateTime}"
} yield formattedSchedule

val formattedSchedules = GenerationScheduleUseCase.list().map { schedule =>
s"${schedule.id}: ${schedule.worlds.toString} | ${schedule.interval.toString} | ${schedule
.seedPattern
.entryName} | ${schedule.nextDateTime.toString}"
}
val message =
if (formattedSchedules.isEmpty) s"${ChatColor.RED}再生成予定はありません。"
val messages =
if (formattedSchedules.isEmpty) Seq(s"${ChatColor.RED}再生成の設定はありません。")
else
Set("-RegenerateWorld ScheduleLists-", "UUID: ワールド | 再生成間隔 | シード値の設定 | 次回再生成予定日時")
Seq("RegenerateWorld - ScheduleLists", "UUID: ワールド | 再生成間隔 | シード値の設定 | 次回再生成予定日時")
.map { str => s"${ChatColor.WHITE}$str" }
.concat(formattedSchedules)
.mkString("¥n")

sender.sendMessage(message)
messages.foreach(context.sender.sendMessage)

Right(())
}
Expand Down

0 comments on commit 9e66dfd

Please sign in to comment.