Skip to content

Instantly share code, notes, and snippets.

@hugo4715
Forked from vemacs/PingRefl.java
Created January 19, 2016 12:31
Show Gist options
  • Save hugo4715/163458c295a0644a1ebb to your computer and use it in GitHub Desktop.
Save hugo4715/163458c295a0644a1ebb 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