From e83b811d34eee2e8dd310ee78313aaa701728e52 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 1 Oct 2023 21:44:28 +0200 Subject: [PATCH] Added a command to display remaining time --- .../fishingevent/commands/FishCommand.java | 8 ++-- .../commands/fish_subcommands/Time.java | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/alttd/fishingevent/commands/fish_subcommands/Time.java diff --git a/src/main/java/com/alttd/fishingevent/commands/FishCommand.java b/src/main/java/com/alttd/fishingevent/commands/FishCommand.java index 060fcef..e0e8c07 100644 --- a/src/main/java/com/alttd/fishingevent/commands/FishCommand.java +++ b/src/main/java/com/alttd/fishingevent/commands/FishCommand.java @@ -1,10 +1,7 @@ package com.alttd.fishingevent.commands; import com.alttd.fishingevent.FishingEvent; -import com.alttd.fishingevent.commands.fish_subcommands.End; -import com.alttd.fishingevent.commands.fish_subcommands.Leaderboard; -import com.alttd.fishingevent.commands.fish_subcommands.Points; -import com.alttd.fishingevent.commands.fish_subcommands.Start; +import com.alttd.fishingevent.commands.fish_subcommands.*; import com.alttd.fishingevent.config.Messages; import com.alttd.fishingevent.util.Logger; import org.bukkit.command.*; @@ -34,7 +31,8 @@ public class FishCommand implements CommandExecutor, TabExecutor { new Points(), new Leaderboard(), new Start(), - new End() + new End(), + new Time() ); } diff --git a/src/main/java/com/alttd/fishingevent/commands/fish_subcommands/Time.java b/src/main/java/com/alttd/fishingevent/commands/fish_subcommands/Time.java new file mode 100644 index 0000000..eb67ac7 --- /dev/null +++ b/src/main/java/com/alttd/fishingevent/commands/fish_subcommands/Time.java @@ -0,0 +1,43 @@ +package com.alttd.fishingevent.commands.fish_subcommands; + +import com.alttd.fishingevent.commands.SubCommand; +import com.alttd.fishingevent.timer.EventManager; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import org.bukkit.command.CommandSender; + +import java.time.Duration; +import java.util.List; + +public class Time extends SubCommand { + @Override + public boolean onCommand(CommandSender commandSender, String[] args) { + if (!EventManager.getInstance().isRunning()) { + commandSender.sendMiniMessage("The event is not running...", null); + return true; + } + Duration timeRemaining = EventManager.getInstance().getTimeRemaining(); + //TODO move message to config + commandSender.sendMiniMessage("There is hour(s), minute(s), and second(s) remaining.", TagResolver.resolver( + Placeholder.parsed("hour", String.valueOf(timeRemaining.toHoursPart())), + Placeholder.parsed("minute", String.valueOf(timeRemaining.toMinutesPart())), + Placeholder.parsed("second", String.valueOf(timeRemaining.toSecondsPart())) + )); + return true; + } + + @Override + public String getName() { + return "time"; + } + + @Override + public List getTabComplete(CommandSender commandSender, String[] args) { + return List.of(); + } + + @Override + public String getHelpMessage() { + return "Invalid command use"; + } +}