Last active
August 28, 2016 23:34
-
-
Save vemacs/6a345b2f9822b79a9a7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Object minecraftServer; | |
private static Field recentTps; | |
public static double[] getRecentTps() { | |
try { | |
if (minecraftServer == null) { | |
Server server = Bukkit.getServer(); | |
Field consoleField = server.getClass().getDeclaredField("console"); | |
consoleField.setAccessible(true); | |
minecraftServer = consoleField.get(server); | |
} | |
if (recentTps == null) { | |
recentTps = minecraftServer.getClass().getSuperclass().getDeclaredField("recentTps"); | |
recentTps.setAccessible(true); | |
} | |
return (double[]) recentTps.get(minecraftServer); | |
} catch (IllegalAccessException | NoSuchFieldException ignored) { | |
} | |
return new double[] {20, 20, 20}; | |
} |
What information does that array include exactly?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you return {20,20,20} when the only way to get to that code is if there is an error? Shouldn't you return {-1,-1,-1} or just let the exception go? Returning {20,20,20} would indicate to the caller that the server is running optimally, when in fact we have no idea.