Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ngx.core;
- import com.skionz.pingapi.PingEvent;
- import com.skionz.pingapi.PingListener;
- import com.skionz.pingapi.PingReply;
- import com.skionz.pingapi.ServerInfoPacket;
- import org.bukkit.Bukkit;
- import java.util.List;
- import java.util.UUID;
- public class animatedMOTDlistener implements PingListener {
- MainClass plugin;
- public int currentline = 0;
- public int maxline;
- public int Duration;
- public animatedMOTDlistener(MainClass plugin) {
- this.plugin = plugin;
- }
- public void setupMOTDANIM() {
- addMOTDMSGS();
- }
- public void addMOTDMSGS() {
- List<String> list = plugin.MOTD.getStringList("Messages");
- for (int i = 0; i < list.size(); i++) {
- String s = list.get(i);
- plugin.MOTDMSGS.add(s);
- }
- }
- public void onPing(PingEvent event) {
- final PingEvent e = event;
- final UUID id = UUID.randomUUID();
- Duration = plugin.MOTD.getInt("Settings.Duration");
- plugin.MOTDRANDOMCooldowns.put(id, this.Duration);
- e.cancelPong(true);
- final PingEvent reply = e;
- reply.getReply().setProtocolVersion(-1);
- reply.getReply().setProtocolName("\u00a7aPlayers online: \u00a76" + plugin.getServer().getOnlinePlayers().size());
- final ServerInfoPacket packet = e.createNewPacket(e.getReply());
- packet.setPingReply(e.getReply());
- if (plugin.MOTDcooldownTasks.containsKey(id)) {
- int cooldownTask = plugin.MOTDcooldownTasks.remove(id);
- if (plugin.getServer().getScheduler().isCurrentlyRunning(cooldownTask) || plugin.getServer().getScheduler().isQueued(cooldownTask))
- plugin.getServer().getScheduler().cancelTask(cooldownTask);
- }
- plugin.MOTDcooldownTasks.put(id, Bukkit.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
- public void run() {
- int timeLeft = plugin.MOTDRANDOMCooldowns.get(id);
- maxline = plugin.MOTDMSGS.size();
- if (currentline >= maxline - 1) {
- currentline = 0;
- } else {
- currentline++;
- }
- String MOTDmsg = plugin.MOTDMSGS.get(currentline);
- if (timeLeft == 5) {
- reply.getReply().setMOTD(MOTDmsg + "\nPING STATUS: OPEN");
- packet.send();
- }
- if (timeLeft == 0) {
- reply.getReply().setMOTD(MOTDmsg + "\nPING STATUS: \u00a74CLOSED");
- packet.send();
- plugin.MOTDRANDOMCooldowns.remove(id);
- int cooldownTask = plugin.MOTDcooldownTasks.remove(id);
- if (Bukkit.getServer().getScheduler().isCurrentlyRunning(cooldownTask) || Bukkit.getServer().getScheduler().isQueued(cooldownTask)) {
- Bukkit.getServer().getScheduler().cancelTask(cooldownTask);
- }
- } else {
- plugin.MOTDRANDOMCooldowns.put(id, timeLeft - 1);
- }
- plugin.getLogger().info("PacketReply: " + e.getReply());
- plugin.getLogger().info("Get Current Packet: " + packet);
- }
- }, 0L, 5L).getTaskId());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement