I have a question for all programmers out there!
I'm currently working on a "stopwatch".
I want to program a stopwatch with an "action bar".
I have all commands ect. Done, I just miss the stopwatch itself: /
(In this video you can find an example, this stopwatch that is in the action bar)
.
So my question is how can I program a "stopwatch" that e.g. With a command: "starts, stops, continues, stops"?
.
I ask for your help and you can write to me on Discord (Wolfi # 4268).
I would recommend the Bukkit Scheduler (https://bukkit.gamepedia.com/Scheduler_Programming/de) which executes a certain code after a specific time and repeats itself after the specified time. You would simply have to save the current time each time and cancel the scheduler when the stopwatch is paused and restart with the saved time when "continue".
I already dealt with this yesterday, thank you, I'll give it a try ^^
I have a question, how can I send the "Actionbar" permanently? That means that it is sent every second and thus the time is updated?
Actually, you should only update the actionable in the task (bukkit scheduler) that is executed every second.
something like that!
final int timer = 20; // stopwatch in seconds
Bukkit.getScheduler (). RunTaskTimer (plugin, new Runnable () {
@Override
public void run () {
// This is done every second
String message = String.valueOf (timer); // Of course you would still have to
// in an appropriate format
// bring, e.g. 00:20
player.spigot (). SendMessage (ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText (message));
timer = timer - 1; // subtract one second from the timer
}
}, 0l, 20l) // The task is started immediately and repeated after 20 Minecraft ticks (one real-time second)