Skip to content

Instantly share code, notes, and snippets.

@vemacs
Last active August 28, 2016 23:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vemacs/6a345b2f9822b79a9a7f to your computer and use it in GitHub Desktop.
Save vemacs/6a345b2f9822b79a9a7f to your computer and use it in GitHub Desktop.
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};
}
@JoshHawley
Copy link

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.

@Janmm14
Copy link

Janmm14 commented Dec 5, 2015

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