Advertisement
Guest User

Bukkit BarAPI example

a guest
Mar 22nd, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. BukkitScheduler scheduler = Bukkit.getServer().getScheduler(); //Bukkit Scheduler
  2. int countDownTimer=0; //the BukkitScheduler task id
  3. MyPlugin plugin; //the instance of your plugin
  4.  
  5. int time=60; //your time in seconds
  6.  
  7. int maxTime=60;
  8.  
  9. void countDown(final String world) { // the name of your world
  10.  
  11.     countDownTimer = scheduler.scheduleSyncRepeatingTask(plugin,
  12.             new Runnable() {
  13.                 public void run() {
  14.  
  15.                     // set the Bar
  16.                     float f = time;
  17.                     float percentage = (100 * (f / maxTime));
  18.  
  19.                     for (Player pl : Bukkit.getWorld(world).getPlayers())
  20.                         BarAPI.setMessage(pl, "Game starts in " + time, percentage);
  21.  
  22.                     if (time <= 5) {
  23.                         // You can add a "Click" sound here
  24.                     }
  25.  
  26.                     // when gets to 0
  27.                     if (time <= 0) {
  28.                         scheduler.cancelTask(countDownTimer);
  29.  
  30.                         for (Player pl : Bukkit.getWorld(world).getPlayers())
  31.                             BarAPI.removeBar(pl);
  32.  
  33.                         startGame(); // call your desired method
  34.                     }
  35.  
  36.                     time--;
  37.                 }
  38.             }, 20, 20);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement