gpt4 book ai didi

java - 单向或向后ping

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:13 25 4
gpt4 key购买 nike

我必须知道玩家的确切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;
}
}


但是现在我不知道ping是一种方法[服务器->播放器]还是两种方法[服务器->播放器->服务器]

有人知道,这是如何工作的吗?

最佳答案

如果您正在寻找反应测试,请尝试将当前时间存储在System.getCurrentTimeMillis();中。然后,经过一段随机的时间(最有可能在Runnable中保持冻结服务器的状态)后发生了某些事情,当他们执行该操作时,请使用相同的方法来获得不同的方法。将两个数字相减,除以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

关于java - 单向或向后ping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36402822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com