java-reflection

How to get player's ping in spigot 1.16.4

社会主义新天地 提交于 2021-02-17 03:32:27
问题 I tried to use java reflection in many ways to get the ping of a player. But at 100%, it returns 0ms. I've searched for a long time, so... can someone help me? Try 1 : public static int getPing(Player p) { try { Object craftPlayer = (CraftPlayer) p; return (int) craftPlayer.getClass().getField("ping").get(craftPlayer); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { throw new Error(e); } } Try2 : public static int getPing(Player p) {