How to get a Server's TPS Rate

Discussion in 'Resources' started by KeybordPiano459, Jan 1, 2013.

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

    KeybordPiano459

    I was playing around a bit today and I got a class working, and it gets the TPS rate of the server, which you can print in a command, or in the console, or wherever you want it.

    Class - http://pastebin.com/JYN6L620

    Remember to register TPS (it's a listener):
    Code:java
    1. public void onEnable() {
    2. getServer().getPluginManager().registerEvents(new TPS(this), this);
    3. }


    To get the TPS rate, just get the int tps from the class TPS.
    Code:java
    1. //define plugin variable in class constructor
    2. TPS tpsclass = new TPS(plugin);
    3. int tps = tpsclass.getServerTPS();
     
  2. Offline

    Hidendra

    just curious why do you use PluginEnableEvent? that will spring up a bunch of different tasks depending on when the plugin loads
     
  3. Offline

    KeybordPiano459

    Hidendra
    I could either use onEnable or PluginEnableEvent, because the task needs to be running at all times do that you can get it in a command at any time. I find it easier to keep different things in different classes, which is why I did that.
     
  4. Offline

    p000ison

    hm? but this code will start 30 tasks if there are 30 plugins.
     
  5. Offline

    KeybordPiano459

    I just realized that I forgot to check for the plugin :p

    p000ison
    Hidendra
    Fixed it, there's an updated pastebin link now :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    desht

    Have you actually tested this class? Because the code you posted won't even compile (you're trying to return a non-static field from a static method).
     
  7. Offline

    KeybordPiano459

    desht
    It will be up and running in a plugin that fireblast709 and I are working on, kEssentials. As a matter of fact, we have already coded the command, and it works. Check it out on my github :)
     
  8. it worked because in your implementation 'getServerTPS()' is not static. However, here it is static and won't compile as desht already mentioned.
     
  9. Offline

    KeybordPiano459

    Ah I didn't notice that =/ I'll update it in a sec...
     
  10. Offline

    joehot2000

    KeybordPiano459
    Uhhh..... comments removed, just realised i hadnt done something.

    Note to self: think before you speak.
     
    KeybordPiano459 likes this.
  11. Offline

    KeybordPiano459

    What do you mean by it couldn't resolve it?
     
  12. Offline

    KeybordPiano459

    Thanks :)

    Nice edit :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  13. Offline

    Mango

    KeybordPiano459 You shouldn't access getServerTPS() in a static way like you're doing. You're misrepresenting the purpose of a constructor for a class.
     
  14. Offline

    KeybordPiano459

    Right... :p
    I'll fix that in a bit
     
  15. Offline

    KeybordPiano459

  16. I searched for it because I recognized my code... :)

    The listener limits options and makes it harder to use, just my opinion... the other thing however is just rude. :)
     
  17. Offline

    KeybordPiano459

    What other thing? Also, I use a listener here because I am able to separate it from my main class, and that way keep it cleaner. I like keeping multi-line statements out of my onEnable and putting them in another class, but that's just my opinion :)
     
  18. I didn't say anything about onEnable(), I said about the class' constructor and avoiding to register a listener when you can just do "new Class()" and it starts the task.

    The other thing is that you claimed my code as your own, no mentioning of where you got it from... and yeah, I find that offensive :)

    And now apparently you decided to change the previous pastebin link with another code that swaps an inline condition with an if() and changes the variable names a bit... it looks like you do know what that other thing was after all... but whatever, be like that.

    The code is still unconsistent and now broken btw.
     
  19. Offline

    KeybordPiano459

    So I'm no longer allowed to update my code? I didn't steal it from you. I thought about it for a bit with a friend of mine, as we needed a /tps command for our server. We ended up thinking that it would be a good idea to schedule a repeating task that checks if 20 ticks were executed every second, and we came up with this.
     
  20. So renaming fields and changing inline condition with if() is updating...
    But I seriously doubt you came up with the exact same layout, variable names, conditions and style... while also ignoring your own data types. And you're still denying it, fine, be that guy.
     
    steaks4uce likes this.
  21. Offline

    KeybordPiano459

    Well my friend suggested to use the ternary operator originally for what I coded, (which I still partially don't understand), so I switched it to the if/else statements, which just makes more sense to me. As for the variable names, I'm changing them because I don't want to make this a big pact, as you're just going to keep accuse me for stealing your code on the basis that we have the same variable names.
     
  22. It must be really hard for you to give credits I guess. You didn't even give credits to your friend which you say made the code...

    I know it's my code, I thought of it, I wrote it, I tested it... but this isn't about the code, I didn't forbid anyone from using it but you don't just copy-paste code and re-release it as your own.

    I was subtle at first in the hope that you see the moral mistake... but I see you made it worse by chickenly trying cover it up with random code changes... but whatever, I'm not even going to start loyering around with you, it's getting childish, so I'm done here. :)
     
    steaks4uce likes this.
  23. Offline

    KeybordPiano459

    Fine--- be that way. I haven't made any moral mistakes here, you haven't either. fireblast709 and I happened to develop the same idea, and then turn it into code. That's all.
     
  24. Offline

    user_43347

    Really? You don't say!
     
Thread Status:
Not open for further replies.

Share This Page