How do i get the server TPS?

Discussion in 'Plugin Development' started by joehot2000, Feb 16, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    joehot2000

    How would i get the TPS of the server? i cant seem to find the code.

    thanks in advance!

    Ok....

    nobody else has posted the same question, and its in the right place.

    Is there some sort of problem?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Woops! Ignore that, I was on the wrong tab... 0.0
     
  3. There's no built-in function, you'll hav to start a task and calculate it...

    I've made this code for a similar thread a while back:
    Code:
    // fields
    private int tps = 0;
    
    // in onEnable or something
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
        long sec;
        long currentSec;
        int  ticks;
        int  delay;
        
        @Override
        public void run()
        {
            sec = (System.currentTimeMillis() / 1000);
            
            if(currentSec == sec)
            {
                // this code block triggers each tick
                
                ticks++;
            }
            else
            {
                // this code block triggers each second
                
                currentSec = sec;
                tps = (tps == 0 ? ticks : ((tps + ticks) / 2));
                ticks = 0;
                
                if((++delay % 300) == 0)
                {
                    // this code block triggers each 5 minutes
                    
                    delay = 0;
                    
                    Bukkit.broadcastMessage("Server current TPS = " + tps);
                }
            }
        }
    }, 0, 1); // do not change the "1" value, the other one is just initial delay, I recommend 0 = start instantly.
    In case you didn't read the comments, it prints the average TPS each 5 minutes.
     
  4. Offline

    DJSanderrr

    XlegitXcrazymanX
    Lol fail, i like'd the story ;D
    What thread was the actual thread it was mean for?
    (Blahh sorry for that ANTIawesome english).
     
    XlegitXcrazymanX likes this.
  5. Offline

    joehot2000

    Yay, thanks! trying it out now :)

    Oh, ok, no problem.

    In a way, you did me good, as you bumped the thread ;)

    lol,

    and, we all make mistakes, that is life.

    on "}, 0, 1);" it says syntax error on tokens, ConstructorHeaderName expected instead.

    Any idea what the problem is?

    sorry for being noobish, i have never done a public void run before.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Field goes in the fields, global variables if you may, and the code goes inside a method... like onEnable(), I've already said that in the comments.
     
  7. Offline

    Tirelessly

  8. Offline

    joehot2000

  9. You actually typed "how to find the server tick rate" on google ? You must think google has mind powers... it can't know what kind of server you're refering to... so "bukkit server tick rate" would've been more than enough.

    And on the forums you'll need to search in plugin dev section only (check the "search this forum only" box) and with minimal keywords... "server tick rate" or "server TPS", that finds alot of relevant topics.
     
  10. Offline

    joehot2000

    I do not understand, yes, i know java, but i have never encountered a delayed task like this, or anything like that.

    I tried putting it in a onBlockPlaceEvent, and that didnt work either.

    run is its own method, so i cant put it in a method.

    Google is intelligent, almost all the results were bukkit results about server TPS, because google remembers your last searches and does searches accordingly.

    But, yes, i see your point :/

    Ok, ok, i get the point, im being a noob, but i have no idea what a "constructorheadername" or whatever it is could be.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  11. So you want an infinite task to be started on each block placed ? That's not a great way at all...

    The TPS must be calculated constantly, it's just like FPS... you can't just calculate the value in a nanosecond, you need time processing, that's why it' has "per second", otherwise it will be "tick" and that makes no sense =)

    Code:
    private int tps = 0;
    
    public void onEnable()
    {
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
        long sec;
        long currentSec;
        int  ticks;
        int  delay;
       
        @Override
        public void run()
        {
            sec = (System.currentTimeMillis() / 1000);
           
            if(currentSec == sec)
            {
                ticks++;
            }
            else
            {
                currentSec = sec;
                tps = (tps == 0 ? ticks : ((tps + ticks) / 2));
                ticks = 0;
            }
        }
    }, 0, 1);
    }
    
    @EventHandler
    public void eventBlockPlace(BlockPlaceEvent event)
    {
        event.getPlayer().sendMessage("TPS = " + tps);
    }
    Wrote that inside the post and I don't really have the patence to start adding spaces for indent, use your editor's format/indent functions.
     
  12. Offline

    joehot2000

    :eek::oops::confused:

    Ok, thanks for the clarification!
     
Thread Status:
Not open for further replies.

Share This Page