-
Notifications
You must be signed in to change notification settings - Fork 0
Example
Peter edited this page Jul 10, 2023
·
1 revision
Here is a small working example to create a 30 second timer with 2 bars
int time = 30 * 20; // 30 seconds in ticks
String name = "testTimer"; // Timer name
JavaPlugin plugin = this; // The plugin creating the timer
Timer timer = new Timer(time, name, this); // Create a new timer with time and name
timer.addAllPlayers(); // Show the timer to all players
timer.addBar("2", "2"); // Add a second bar with title "2"
timer.addAllPlayers("2"); // Show the second bar to all players
timer.setTitle("1"); // Set the title of the main bar to "1"
TimeRunnable done = new TimeRunnable() { // Create callback for when timer is done
public void run(Timer timer) {
Bukkit.getConsoleSender().sendMessage("Timer Done"); // Send a message to the console saying the timer is done
timer.stop(); // Stop the timer (Optional)
timer.removeAllPlayers(); // Hide the main bar from all players (It wont show up if you restart it then)
timer.removeAllPlayers("2"); // Hide the second bar from all players (It wont show up if you restart it then)
}
};
timer.addCallback(0,done); // Add the callback at 0 ticks remaining
timer.start(); // Start the timer