Advertisement
Guest User

Untitled

a guest
Jul 19th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package pl.hugozar.tools.managers;
  2.  
  3. import java.util.Map.Entry;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.World;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8. import org.bukkit.scheduler.BukkitTask;
  9.  
  10. import pl.hugozar.tools.Tools;
  11.  
  12. public class TimerManager{
  13.    
  14.     static BukkitTask saveTimer;
  15.     static BukkitTask slowChatTimer;
  16.     static BukkitTask autoMsgTimer;
  17.    
  18.     public static void startSaveTimer(){
  19.         saveTimer = new BukkitRunnable(){
  20.             @Override
  21.             public void run(){
  22.                 Bukkit.broadcastMessage(Utils.fixColors(" &8> &9Zapisywanie servera."));
  23.                 Bukkit.savePlayers();
  24.                 for(World w : Bukkit.getWorlds()){
  25.                     w.save();
  26.                 }
  27.                 Bukkit.broadcastMessage(Utils.fixColors(" &8> &9Zapisywanie servera zakonczone."));
  28.             }
  29.         }.runTaskTimer(Tools.getInst(), 6000, 6000);
  30.     }
  31.    
  32.     public static void stopSaveTimer(){
  33.         saveTimer.cancel();
  34.     }
  35.    
  36.     public static void startSlowChatTimer(){
  37.         slowChatTimer = new BukkitRunnable(){
  38.             @Override
  39.             public void run(){
  40.                 for(Entry<String, Integer> line : Data.slowChat.entrySet()){
  41.                     Data.slowChat.put(line.getKey(), line.getValue() - 1);
  42.                     if(Data.slowChat.get(line.getKey()) <= 0){
  43.                         Data.slowChat.remove(line.getKey());
  44.                     }
  45.                 }
  46.             }
  47.         }.runTaskTimer(Tools.getInst(), 20, 20);
  48.     }
  49.    
  50.     public static void stopSlowChatTimer(){
  51.         slowChatTimer.cancel();
  52.     }
  53.    
  54.     public static void startAutoMsgTimer(){
  55.         autoMsgTimer = new BukkitRunnable(){
  56.             @Override
  57.             public void run(){
  58.                 Bukkit.broadcastMessage(Utils.fixColors(Data.getAutoMsgMessages().get(Utils.getRandInt(0, Data.getAutoMsgMessages().size() - 1))));
  59.             }
  60.         }.runTaskTimer(Tools.getInst(), 1200, 1200);
  61.     }
  62.    
  63.     public static void stopAutoMsgTimer(){
  64.         autoMsgTimer.cancel();
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement