Spigot LagMOTD 1.2

Check the lag of your server with your server MOTD.

  1. SasukeGabe submitted a new resource:

    LagMOTD - Check the lag of your server with your server MOTD.

    Read more about this resource...
     
    #1 SasukeGabe, Sep 14, 2013
    Last edited: Sep 14, 2013
    • Agree Agree x 1
  2. joshwenke

    Wiki Team

    Screenshot?
     
  3. I'll add one soon.
     
  4. Done joshwenke

    Check the resource now uploaded a file! :)

    lagmotd.png
     
    • Like Like x 1
  5. could you send me the source beceas i would like to have my motd like this:
    SERVERNAME --------------------------------------------------------------------| Lag 0.0

    - = Space
     
    #5 GamingNL, Oct 5, 2013
    Last edited: Oct 5, 2013
    • Agree Agree x 1
  6. joehot200

    Supporter

    Im gonna modify it for you anyway.

    @SasukeGabe MAKE IT TELL THE PLAYERS AVERAGE PING!!
    @SasukeGabe MAKE IT TELL THE PLAYERS AVERAGE PING!!
    @SasukeGabe MAKE IT TELL THE PLAYERS AVERAGE PING!!
    @SasukeGabe MAKE IT TELL THE PLAYERS AVERAGE PING!!


    Soo like... "--Endcraft Survival/PVP/KitPVP-- Lag: 0.0 - Ping: 152".
     
  7. joehot200

    Supporter

    oh and make a bungee version plz :(
     
  8. Sure, I'll send it when I get home!
     
  9. Seems like a good idea! I'll add it when I get home! :)

    And

    I'll make a bungee version very soon! :)
     
    • Like Like x 1
    • Winner Winner x 1
  10. Here's the source code.
    Code (Text):

    // package name here
    // LagMOTD class
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.server.ServerListPingEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class LagMOTD extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable(){
            System.out.print("Enabled LagMOTD!");
            getServer().getPluginManager().registerEvents(this, this);

            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        public static Bukkit plugin;
       
       
        @Override
        public void onDisable(){
           
        }
       
       
        @EventHandler
        public void tps(ServerListPingEvent e){
              double tps = Lag.getTPS();
              double lag = Math.round((1.0D - tps / 20.0D) * 100.0D);
            e.setMotd("Lag is at about: " + lag);
        }
    }
     
    Code (Text):

     
    // Lag class
    public class Lag
    implements Runnable
    {
    public static int TickCount = 0;
    public static long[] Ticks = new long[600];
    public static long LastTick = 0L;

    public static double getTPS()
    {
      return getTPS(100);
    }

    public static double getTPS(int ticks)
    {
      if (TickCount < ticks) {
        return 20.0D;
      }
      int target = (TickCount - 1 - ticks) % Ticks.length;
      long elapsed = System.currentTimeMillis() - Ticks[target];

      return ticks / (elapsed / 1000.0D);
    }

    public static long getElapsed(int tickID)
    {
      if (TickCount - tickID >= Ticks.length)
      {
      }

      long time = Ticks[(tickID % Ticks.length)];
      return System.currentTimeMillis() - time;
    }

    public void run()
    {
      Ticks[(TickCount % Ticks.length)] = System.currentTimeMillis();

      TickCount += 1;
    }
    }
     
     
     
    • Like Like x 1
  11. Non tested build, use at own risk!
    I'm not sure if this will work: But give this out a try!
     

    Attached Files:

    • Like Like x 1
  12. joehot200

    Supporter

    Nope. Just shows the same every time :(
     
  13. Damn, I'll try to get another one up! Sorry for the wait!
     
  14. Here's another one, hopefully this should work! (Shows TPS too.)
     

    Attached Files:

  15. Attached Files:

    • Winner Winner x 1
  16. joehot200

    Supporter

    You forgot to use the e.setResponse() line at the bottom of the tps(ProxyPingEvent e) method - So it just shows the MOTD listed in the bungee config.
     
    • Agree Agree x 1
  17. Sorry was in a rush!
     
  18. joehot200

    Supporter

    No problem, thanks for putting in the effort for little old me :D
     
    • Like Like x 1