Skip to content

Instantly share code, notes, and snippets.

@hugo4715
Forked from vemacs/TPSUtil.java
Last active June 26, 2017 12:37
Show Gist options
  • Save hugo4715/2613ac04356d3e7f3693 to your computer and use it in GitHub Desktop.
Save hugo4715/2613ac04356d3e7f3693 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[] {-1, -1, -1};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment