TPS not working in CraftBukkit versions, why?

Discussion in 'Spigot Plugin Development' started by Toldi, Jun 1, 2018.

Thread Status:
Not open for further replies.
  1. As in the title, why does not it work?
    Here is the source code about it:
    Code (Java):
        public static String tpsComma(double d) {
            String ds = Double.toString(d);
            if (ds.contains(".")) {
                ds = ds.substring(0, ds.indexOf(".") + 2);
            }
            return ds;
        }

        public static double getTPS() {
            try {
                Method met = Bukkit.getServer().getClass().getMethod("getServer", new Class[0]);
                Object mc = met.invoke(Bukkit.getServer(), new Object[0]);
                Field rec = mc.getClass().getField("recentTps");
                double[] recentTps = (double[])rec.get(mc);
                return recentTps[0];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 20.0D;
        }
    The basics I had to do I did.
    Somehow this is how it is used:
    Code (Java):
    p.sendMessage("§aTPS:§8 " + tpsComma(getTPS()));
    I did that if you use a CraftBukkit version, write 0, so disable it.
    But I removed this and sent a long error to the console. Issue: #15
     
  2. Can we see what the erroe is, It may help us by telling what line doesnt work/is improperly defined.
     
  3. What error or result are you getting?

    None the less;
    Code (Java):
        public static String tpsComma(double d) {
            String ds = Double.toString(d);
            if (ds.contains(".")) {
                ds = ds.substring(0, ds.indexOf(".") + 2);
            }
            return ds;
        }
    What is this code even...?
    You can check if a double has a decimal with this function:
    Code (Text):
    doubleVariable % 1 == 0
    And there are tons of ways of how to round a double to two decimals. Just give it a quick Google.
     
  4. md_5

    Administrator Developer

    Only Spigot tracks TPS like that.
    You can track your own TPS by using a scheduled task.
     
  5. This code would be that the comma "," instead of a dot "." dot.
     
  6. Yes, I know and saw it, but could not solve it?
     
Thread Status:
Not open for further replies.