Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

481
Vistas
How to get player's ping in spigot 1.16.4

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) {

       EntityPlayer player = ((CraftPlayer) p).getHandle();
       return player.ping;

    }
    

Try 3 :

    int ping = 0;
    Class<?>[] parameterTypes = null;
        
    Class<CraftPlayer> metadata = CraftPlayer.class;
    Method[] methods = metadata.getDeclaredMethods();
    for(Method method : methods) {  
        if(method.getName().equalsIgnoreCase("getHandle")) {
            parameterTypes = method.getParameterTypes();
        }
    }
        
    try {

        Object entityPlayer = p.getClass().getDeclaredMethod("getHandle", 
        parameterTypes).invoke((CraftPlayer) p);
        ping = (int) entityPlayer.getClass().getDeclaredField("ping").get(entityPlayer);

    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
                | NoSuchMethodException | SecurityException | NoSuchFieldException e) {
            e.printStackTrace();
        }

Try 4 :

        int ping = 0;
        
        try {

            Object entityPlayer = p.getClass().getMethod("getHandle").invoke(p);
            ping = entityPlayer.getClass().getField("ping").getInt(entityPlayer);

        } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | 
        SecurityException e) {
            e.printStackTrace();
        }

And 3 more... (Similar to this or definitively not good for usage)

I'm testing my plugin on a VPS-Hosted 1.16.4 PaperMC server.

Maybe it will be different on a dedicated machine.

I tried to use "compact" code like this :

int ping = ((CraftPlayer) p).getHandle().ping;

... but it returns 0ms again.

Please note that I'm a real Java novice. I'm practicing to improve my level.

I'm not searching the final solution, but just an answer if my aproach is OK. If not, a good way to do this.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Finally, it works.

The problem is my FAI : A few days ago, I opened 25565 ports for UDP/TCP and I also change other parameters.

Since I turn off all these options, my ping was magically back to 8-12 ms.

Thanks kahveci for your edit suggestion and sorry for the inconvenience.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda