Skip to content

Instantly share code, notes, and snippets.

@vemacs
Created May 21, 2015 00:00
Show Gist options
  • Save vemacs/1550cac797314a2c841f to your computer and use it in GitHub Desktop.
Save vemacs/1550cac797314a2c841f to your computer and use it in GitHub Desktop.
private static Method getHandleMethod;
private static Field pingField;
private static int getPing(Player player) {
try {
if (getHandleMethod == null) {
getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
getHandleMethod.setAccessible(true);
}
Object entityPlayer = getHandleMethod.invoke(player);
if (pingField == null) {
pingField = entityPlayer.getClass().getDeclaredField("ping");
pingField.setAccessible(true);
}
return pingField.getInt(entityPlayer);
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment