2016-04-04 7 views
1

反応テストのためにプレイヤーの正確なpingを知る必要があります。 私はこのためのハンドラを使用します。pingが一つの方法であるかどうかを知る片方向または背面のピン番号

public int pingPlayer(Player p) { 
    try { 
     String bukkitversion = Bukkit.getServer().getClass().getPackage().getName().substring(23); 
     Class<?> craftPlayer = Class.forName("org.bukkit.craftbukkit." + bukkitversion + ".entity.CraftPlayer"); 
     Object handle = craftPlayer.getMethod("getHandle").invoke(p); 
     Integer ping = (Integer) handle.getClass().getDeclaredField("ping").get(handle); 
     return ping.intValue(); 
    } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | NoSuchFieldException e) { 
     return -1; 
    } 
} 

しかし、今、私はいけない[サーバー] - > [プレーヤー]または二つの方法[サーバー - >プレーヤー - >サーバー]

誰かが知っていますか?これはどのように機能しますか?

+0

ピングは、それがbukkitで同じであることを往復 – Michael

+0

よろしいですか? –

+0

@NicolaUetzどのようにpingが動作するのですか?それは往復にかかった時間を数える(このようなものは私にXDを引用しない)。 'int ping =((CraftPlayer)p).getHandle()。playerConnection.player.ping;'ここではリフレクションの必要はありません。 – Lightspeed360

答えて

0

反応テストをお探しの場合は、現在時刻をSystem.getCurrentTimeMillis();に保存してみてください。それから、ランダムな時間の後に何かが起こるようにしてください(おそらくサーバーをフリーズさせないようにしてください)。アクションを実行するときには、同じ方法を使用して別の方法を使用してください。 2つの数値を減算し、1000で除して差(秒)を求めます。

例:

// stuff before reaction test Long timeStart = System.getCurrentTimeMillis(); // first time // runnable, action, etc. (what you are testing the reaction time for) Long timeEnd = System.getCurrentTimeMillis(); // second time Long timeDifference = timeEnd - timeStart; // difference in time Integer timeInSeconds = timeDifference/1000; // difference in time (in seconds) player.sendMessage("Your time was " + timeInSeconds.toString() + " seconds!"); // send message to player

関連する問題