Advertisement
Guest User

Untitled

a guest
Apr 30th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. public class CountDownTask extends TimerTask{
  2.    
  3.     private SmilekrubServerMain plugin;
  4.     public CountDownTask(SmilekrubServerMain instance){
  5.         plugin = instance;
  6.     }
  7.    
  8.     @Override
  9.     public void run() {
  10.         CountDownSystem clock = plugin.getSmilekrub().getCountDown();
  11.         float timeleftpercent = SmilekrubFunction.GetPerCentFromTime(clock.countDownRemain, clock.countDownFrom);
  12.         int left = clock.countDownRemain;      
  13.         if(left > 10 && clock.delayChangeText > 0 && !clock.message.equals("")){
  14.             for (Player player : Bukkit.getOnlinePlayers()) {
  15.                 BarAPI.setMessage(player, ChatColor.AQUA+"[Countdown] : "+ChatColor.WHITE+ChatColor.BOLD+clock.message, timeleftpercent);
  16.             }
  17.         }
  18.         else if(left > 0) {
  19.             ChatColor chatcolor = null;
  20.             if(left > 20) chatcolor = ChatColor.AQUA;
  21.             else if(left > 10) chatcolor = ChatColor.GREEN;
  22.             else if(left > 3) chatcolor = ChatColor.YELLOW;
  23.             else chatcolor = ChatColor.GOLD;
  24.             Player[] players = plugin.getServer().getOnlinePlayers();
  25.             for (Player player : players) {
  26.                 BarAPI.setMessage(player, chatcolor+"[Countdown] : "+ChatColor.BOLD+SmilekrubFunction.getTimeAsString(left)+" left!", timeleftpercent);
  27.                 if(left <= 5){
  28.                     player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, (float) (left*0.3));
  29.                 }
  30.             }
  31.         }
  32.         else if(left == 0)
  33.         {
  34.             if(clock.playSoundWhenEnd){
  35.                 Sound[] soundrand = {Sound.CHICKEN_HURT, Sound.ANVIL_LAND, Sound.WOLF_BARK, Sound.BURP, Sound.CAT_MEOW, Sound.EXPLODE, Sound.CREEPER_HISS, Sound.ENDERDRAGON_HIT, Sound.BLAZE_HIT, Sound.ENDERMAN_TELEPORT, Sound.GHAST_DEATH, Sound.GHAST_SCREAM, Sound.GHAST_SCREAM2,Sound.FALL_BIG, Sound.ZOMBIE_PIG_DEATH};
  36.                 Sound selectsound = soundrand[SmilekrubFunction.randInt(0, soundrand.length-1)];
  37.                 for (Player player : Bukkit.getOnlinePlayers()) {
  38.                     player.playSound(player.getLocation(), selectsound, 5, 1);
  39.                 }
  40.             }
  41.             if(clock.showTimeUpMessage){
  42.                 plugin.getSmilekrub().getLogblock().lbconsumer.getConsumer().queueChat("Server", "[Countdown] : Time's Up! (^^)");
  43.                 Bukkit.broadcastMessage(ChatColor.GREEN+"[Countdown] : "+ChatColor.BOLD+"Time's Up! (^^)");
  44.                 for (Player player : Bukkit.getOnlinePlayers()) {
  45.                     if(BarAPI.hasBar(player)) {
  46.                         BarAPI.setMessage(player, ChatColor.GREEN+"[Countdown] : "+ChatColor.BOLD+"Time's Up! (^^)", (float) 0.0);
  47.                     }
  48.                 }
  49.             }
  50.             if(clock.runLater != null){
  51.                 clock.runLater.run();
  52.                 clock.runLater = null;
  53.             }
  54.         }
  55.         else if(left < 0)
  56.         {
  57.             for (Player player : Bukkit.getOnlinePlayers()) {
  58.                 if(BarAPI.hasBar(player)) {
  59.                     BarAPI.removeBar(player);
  60.                 }
  61.             }
  62.             clock.countDownTask.cancel();
  63.             clock.countDownTask = null;
  64.             clock.countDownFrom = 0;
  65.             clock.countDownRemain = 0;
  66.             clock.message = "";
  67.             clock.playSoundWhenEnd = true;
  68.             clock.showTimeUpMessage = true;
  69.             return;
  70.         }
  71.         if(left > 1 && (((left < 10) || (left%5) == 0) && left < 60) || (left%30) == 0 || clock.firstCountDown == true){
  72.             String havemessage="";
  73.             if(!clock.message.equals("")) havemessage = "; "+clock.message;
  74.             plugin.getSmilekrub().getLogblock().lbconsumer.getConsumer().queueChat("Server", "[Countdown] : "+SmilekrubFunction.getTimeAsString(left)+" left!"+ChatColor.stripColor(havemessage));
  75.             plugin.getSmilekrub().getCountDown();
  76.             clock.firstCountDown = false;
  77.         }
  78.         if(clock.delayChangeText <= -5) clock.delayChangeText = 5;
  79.         else    --clock.delayChangeText;
  80.         --clock.countDownRemain;
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement