Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1. package ngx.core;
  2.  
  3. import com.skionz.pingapi.PingEvent;
  4. import com.skionz.pingapi.PingListener;
  5. import com.skionz.pingapi.PingReply;
  6. import com.skionz.pingapi.ServerInfoPacket;
  7. import org.bukkit.Bukkit;
  8.  
  9. import java.util.List;
  10. import java.util.UUID;
  11.  
  12. public class animatedMOTDlistener implements PingListener {
  13.     MainClass plugin;
  14.  
  15.     public int currentline = 0;
  16.     public int maxline;
  17.     public int Duration;
  18.  
  19.     public animatedMOTDlistener(MainClass plugin) {
  20.         this.plugin = plugin;
  21.     }
  22.  
  23.     public void setupMOTDANIM() {
  24.         addMOTDMSGS();
  25.     }
  26.  
  27.     public void addMOTDMSGS() {
  28.         List<String> list = plugin.MOTD.getStringList("Messages");
  29.         for (int i = 0; i < list.size(); i++) {
  30.             String s = list.get(i);
  31.             plugin.MOTDMSGS.add(s);
  32.         }
  33.     }
  34.  
  35.     public void onPing(PingEvent event) {
  36.         final PingEvent e = event;
  37.         final UUID id = UUID.randomUUID();
  38.         Duration = plugin.MOTD.getInt("Settings.Duration");
  39.         plugin.MOTDRANDOMCooldowns.put(id, this.Duration);
  40.         e.cancelPong(true);
  41.  
  42.         final PingEvent reply = e;
  43.         reply.getReply().setProtocolVersion(-1);
  44.         reply.getReply().setProtocolName("\u00a7aPlayers online: \u00a76" + plugin.getServer().getOnlinePlayers().size());
  45.         final ServerInfoPacket packet = e.createNewPacket(e.getReply());
  46.         packet.setPingReply(e.getReply());
  47.  
  48.         if (plugin.MOTDcooldownTasks.containsKey(id)) {
  49.             int cooldownTask = plugin.MOTDcooldownTasks.remove(id);
  50.             if (plugin.getServer().getScheduler().isCurrentlyRunning(cooldownTask) || plugin.getServer().getScheduler().isQueued(cooldownTask))
  51.                 plugin.getServer().getScheduler().cancelTask(cooldownTask);
  52.         }
  53.  
  54.         plugin.MOTDcooldownTasks.put(id, Bukkit.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
  55.             public void run() {
  56.                 int timeLeft = plugin.MOTDRANDOMCooldowns.get(id);
  57.  
  58.                 maxline = plugin.MOTDMSGS.size();
  59.                 if (currentline >= maxline - 1) {
  60.                     currentline = 0;
  61.                 } else {
  62.                     currentline++;
  63.                 }
  64.                 String MOTDmsg = plugin.MOTDMSGS.get(currentline);
  65.  
  66.  
  67.                 if (timeLeft == 5) {
  68.                     reply.getReply().setMOTD(MOTDmsg + "\nPING STATUS: OPEN");
  69.                     packet.send();
  70.                 }
  71.                 if (timeLeft == 0) {
  72.                     reply.getReply().setMOTD(MOTDmsg + "\nPING STATUS: \u00a74CLOSED");
  73.                     packet.send();
  74.  
  75.                     plugin.MOTDRANDOMCooldowns.remove(id);
  76.                     int cooldownTask = plugin.MOTDcooldownTasks.remove(id);
  77.                     if (Bukkit.getServer().getScheduler().isCurrentlyRunning(cooldownTask) || Bukkit.getServer().getScheduler().isQueued(cooldownTask)) {
  78.                         Bukkit.getServer().getScheduler().cancelTask(cooldownTask);
  79.                     }
  80.                 } else {
  81.                     plugin.MOTDRANDOMCooldowns.put(id, timeLeft - 1);
  82.                 }
  83.                 plugin.getLogger().info("PacketReply: " + e.getReply());
  84.                 plugin.getLogger().info("Get Current Packet: " + packet);
  85.             }
  86.         }, 0L, 5L).getTaskId());
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement