Question

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.

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.

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. 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.

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.

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.

Was it helpful?

Solution

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.

  • 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top