Advertisement
Evyatar12

Colour Scroller

Apr 12th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1.     public void onEnable() {
  2.         String msg = "Golden Games";
  3.        
  4.         Runnable runnable = new Runnable() {
  5.            
  6.            
  7.             /*
  8.              *  Start (WARMUP)
  9.              *  ONCE
  10.              */
  11.             long defWaitTime1 = 20,
  12.                     waitTime1 = defWaitTime1;
  13.            
  14.             /*
  15.              * Refresh
  16.              * ONLY ON END
  17.              */
  18.             long defWaitTime2 = 20*3,
  19.                     waitTime2 = defWaitTime2,
  20.                     showTime = 0,
  21.                     shutdownTime = 15;
  22.            
  23.            
  24.             /*
  25.              *  Between
  26.              *  ONLY BETWEEN CHANGES
  27.              */
  28.             long defWaitTime3 = 20 * (3/4),
  29.                     waitTime3 = defWaitTime3;
  30.            
  31.             int index = 0;
  32.             String latest = msg,
  33.                     refresh;
  34.            
  35.             @Override
  36.             public void run() {
  37.                
  38.                 if (waitTime1 == 0) {
  39.                    
  40.                     if (waitTime2 == 0) {
  41.                         refresh = null;
  42.                        
  43.                         if (waitTime3 == 0) {
  44.                             latest = next(msg, index);
  45.                             index++;
  46.                            
  47.                             if (index > msg.length()) {
  48.                                 waitTime2 = defWaitTime2;
  49.                                 index = 0;
  50.                             }
  51.                             else {
  52.                                 waitTime3 = defWaitTime3;
  53.                             }
  54.                         }
  55.                         else {                         
  56.                             waitTime3--;
  57.                         }
  58.                     }
  59.                     else {
  60.                         long mod = waitTime2 % 20;
  61.                        
  62.                         if (mod == showTime) {
  63.                             refresh = latest;
  64.                         }
  65.                         else if (mod == shutdownTime) {
  66.                             refresh = msg;
  67.                         }
  68.                        
  69.                         waitTime2--;
  70.                     }
  71.                 }
  72.                 else {
  73.                     waitTime1--;
  74.                 }
  75.                
  76.                 String title = refresh == null ? latest : refresh;
  77.             }          
  78.         };
  79.        
  80.         Bukkit.getScheduler().scheduleSyncRepeatingTask(this, runnable, 0, 1);
  81.     }
  82.    
  83.     public String next(String str, int index) {
  84.         return next(str, index, ChatColor.YELLOW, ChatColor.GOLD, String.valueOf(ChatColor.BOLD));
  85.     }
  86.    
  87.     public String next(String str, int index, ChatColor firstColor, ChatColor secondColor, String constant) {
  88.         String newString = "";
  89.         boolean first = true;
  90.        
  91.         for (int i = 0; i < str.length(); i++) {
  92.             char ch = str.charAt(i);
  93.            
  94.             if (i == index) {
  95.                 newString +=
  96.                         firstColor;
  97.                 newString += constant;
  98.             }
  99.             else if (i == 0) {
  100.                 newString += secondColor;
  101.                 newString += constant;
  102.             }
  103.             else if (i > index){
  104.                 if (first) {
  105.                     newString += ChatColor.RESET;
  106.                     newString += constant;
  107.                     first = false;
  108.                 }
  109.             }
  110.            
  111.             newString += ch;
  112.         }
  113.        
  114.         return newString;
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement