简体   繁体   English

如何获得经过的时间呢?

[英]How to get an elapsed time for this?

I am creating a Spigot (Performance savvy fork of Bukkit (Minecraft server software)) plugin that communicates with a Bungee (Proxy server for managing multiple spigot instances) server. 我正在创建一个Spigot(Bukkit(Minecraft服务器软件)的性能精明分支)插件,该插件与Bungee(用于管理多个插头实例的代理服务器)服务器进行通信。

I have a functionality, that when you type a command "/setbar (time-in-seconds) (message)", it will use an API (BarAPI if you are familiar) to create a bar on every server connected to the Bungee instance. 我具有一项功能,当您键入命令“ / setbar(秒)(消息)”时,它将使用API​​(如果您熟悉,则为BarAPI)在连接到Bungee实例的每台服务器上创建一个条。

The fault with this is that when a player joins one of the Spigot servers after the command was issued, the Bar is not there. 这样做的错误在于,发出命令 ,如果玩家加入其中一台Spigot服务器,则酒吧就不在那儿。 I solve this by storing the bar's information on the Proxy level and sending these values to the specific Spigot instance the player attempts to join. 我通过在代理级别上存储栏的信息并将这些值发送到玩家尝试加入的特定Spigot实例来解决此问题。

Okay, so enough background information. 好的,足够的背景信息。 The problem I'm having is that I'm storing the time the admin (or whoever issued the command) requested in a variable. 我遇到的问题是我将管理员(或发出命令的人)请求的时间存储在变量中。 When the user joins, obviously the time will have decremented slightly (or a lot.) The way I've thought of making sure the user who is joining receives the proper elapsed time, (so the BarAPI knows how large the timer graphic needs to be), was by storing the time the command was executed in a variable (currentTimeMillis / currentTimeNano) and converting that to seconds then subtracting that from the time specified in the command. 当用户加入时,显然时间会稍微减少(或减少很多)。我想确保要加入的用户接收到正确的经过时间的方式(因此BarAPI知道计时器图形需要多大的时间) be),将命令执行的时间存储在变量(currentTimeMillis / currentTimeNano)中,并将其转换为秒,然后从命令中指定的时间中减去该时间。

I know there is a flaw with my logic here, and I can't seem to work out the math. 我知道这里的逻辑存在缺陷,我似乎无法计算出数学数字。 I know this is rather simple, but any help you can provide would be extremely beneficial. 我知道这很简单,但是您可以提供的任何帮助都是极其有益的。

Thanks in advance. 提前致谢。

Postscript: Any information I have failed to provide, please let me know and I will add it to this post. 附言:我未能提供的任何信息,请让我知道,我将其添加到这篇文章中。

I realize this is a bit of a "no-end" question as there isn't an exact answer provided I didn't actually give any code. 我意识到这是一个“无止境”的问题,因为如果我实际上没有给出任何代码,就没有确切的答案。

Here is how I solved it in plain English, though: 不过,这是我用简单的英语解决的方法:

  • Store the time the command was executed the first in milliseconds. 存储该命令第一次执行的时间(以毫秒为单位)。

  • When the command is executed next, remove the first value from the new value and divide it by 1000 to receive a seconds-value. 接下来执行该命令时,请从新值中删除第一个值,然后将其除以1000以得到秒值。

  • The seconds-value is the elapsed time. 秒值是经过的时间。 Once can find how much time is remaining by then subtracting the seconds-value from the initially provided seconds-value for the bar. 通过从条形图的初始提供的秒值中减去秒值,一次可以找到剩余的时间。

  • Erase the bar for the user in question; 删除相关用户的栏; recreate same values but substitute seconds for the newly calculated seconds-value. 重新创建相同的值,但用秒替换新计算的秒值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM