Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

474
Views
Cómo obtener el ping del jugador en spigot 1.16.4

Traté de usar el reflejo de Java de muchas maneras para obtener el ping de un jugador. Pero al 100%, devuelve 0ms.

He buscado durante mucho tiempo, así que... ¿alguien puede ayudarme?

Prueba 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); } }

Prueba 2:

 public static int getPing(Player p) { EntityPlayer player = ((CraftPlayer) p).getHandle(); return player.ping; }

Prueba 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(); }

Prueba 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(); }

Y 3 más... (Similar a este o definitivamente no es bueno para su uso)

Estoy probando mi complemento en un servidor PaperMC 1.16.4 alojado en VPS.

Tal vez sea diferente en una máquina dedicada.

Traté de usar un código "compacto" como este:

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

... pero devuelve 0ms de nuevo.

Tenga en cuenta que soy un verdadero novato de Java. Estoy practicando para mejorar mi nivel.

No estoy buscando la solución final, sino solo una respuesta si mi enfoque está bien. Si no, una buena manera de hacer esto.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Finalmente, funciona.

El problema es mi FAI: Hace unos días abrí 25565 puertos para UDP/TCP y también cambio otros parámetros.

Como desactivé todas estas opciones, mi ping volvió mágicamente a 8-12 ms.

Gracias kahveci por su sugerencia de edición y disculpe las molestias.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!