Advertisement
Guest User

Untitled

a guest
Apr 26th, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.goa.plugins.gunsofaurora;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.OfflinePlayer;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.scoreboard.DisplaySlot;
  8. import org.bukkit.scoreboard.Objective;
  9. import org.bukkit.scoreboard.Scoreboard;
  10.  
  11. public class TestScoreBoard {
  12.  
  13.     private final GOA plugin;
  14.     public final Scoreboard s;
  15.     public TestScoreBoard (GOA plugin) {
  16.         this.plugin = plugin;
  17.         this.s = plugin.getServer().getScoreboardManager().getMainScoreboard();
  18.         quickInit();
  19.     }
  20.    
  21.     public GOA getPlugin() {
  22.         return plugin;
  23.     }
  24.  
  25.     int sBIndex = 0;
  26.     int sLength = 1;
  27.     int sDelay = 4;
  28.     int taskid = 0;
  29.    
  30.     public void quickInit () {
  31.         for(DisplaySlot ds : DisplaySlot.values())
  32.             s.clearSlot(ds);
  33.         sideBar();
  34.     }
  35.    
  36.     public void sideBar () {
  37.         if(s.getObjective(DisplaySlot.SIDEBAR) != null)
  38.             s.getObjective(DisplaySlot.SIDEBAR).unregister();
  39.         if(s.getObjective("cool") != null)
  40.             s.getObjective("cool").unregister();
  41.         final Objective hb = s.registerNewObjective("cool", "dummy");
  42.         hb.setDisplayName(ChatColor.GRAY+"[No New Messages] ");
  43.         hb.setDisplaySlot(DisplaySlot.SIDEBAR);
  44.        
  45.         final OfflinePlayer def = Bukkit.getOfflinePlayer(ChatColor.GRAY+"Broadcaster");
  46.        
  47.         hb.getScore(def).setScore(1);
  48.        
  49.         final String mO = "                [::]New Message Incomming[::]   "+"This is a test message to all players. We are going to be restarting the server within the hour. Please take note and don't do anything extreme. Another warning will apear in about thirty minutes!" + "  ";
  50.         String authorDsip = ChatColor.BLUE+"RingOfStorms";
  51.         final OfflinePlayer author = Bukkit.getOfflinePlayer(authorDsip.substring(0, Math.min(16, authorDsip.length())));
  52.         final String color = ChatColor.GOLD.toString();
  53.        
  54.         taskid = Bukkit.getScheduler().scheduleSyncRepeatingTask(getPlugin(), new Runnable () {
  55.             public void run () {
  56.                 String m = mO.substring(sBIndex, Math.min(sBIndex+32-color.length(), mO.length()-color.length()));
  57.                 m = color+m;
  58.                 if(m.length() <= color.length()) {
  59.                     hb.setDisplayName(ChatColor.GRAY+"[No New Messages]");
  60.                     hb.getScore(def).setScore(1);
  61.                     s.resetScores(author);
  62.                     cancelTask();
  63.                 }else{
  64.                     sBIndex += sLength;
  65.                     hb.setDisplayName(m);
  66.                     hb.getScore(author).setScore(1);
  67.                     s.resetScores(def);
  68.                 }
  69.             }
  70.         }, 20L * 3, sDelay);
  71.     }
  72.    
  73.     public void cancelTask () {
  74.         Bukkit.getScheduler().cancelTask(taskid);
  75.         taskid = 0;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement