[SPIGOT-2933] Getting the server's current tick / total ticks Created: 18/Dec/16 Updated: 16/Apr/23 |
|
| Status: | Open |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor |
| Reporter: | blablubbabc | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
With this addition it would be possible to get the server's total amount of ticks it has processed since its start. This could for example be used to check how many ticks have passed since some event or since server start (which depends on the server's dynamic ticks-per-second it can achieve). Implemented by https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/pull-requests/245/ and https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/331/ |
| Comments |
| Comment by MagmaGuy [ 27/Sep/21 ] |
|
I am aware that it's been 5 years, but I just ran into an issue where I would need this exact feature and figured I could expose how it can be useful primarily as a debug tool for developers.
Here is the scenario (not looking for a solution, just setting the scene):
I have a bit of code that I suspect is running twice per tick when it should be running once. This is a tricky bit of code, because it is a core element of the 50k line plugin I'm working on.
The plugin is large enough that outputting stack traces for edge conditions only isn't really giving me enough info to try to find a solution, and the code runs so frequently that stack tracing every code execution would be extremely hard to parse.
Already, being able to check which tick the code is running on would allow me to know if the issue is with the code running twice in a tick or with some other element of the plugin.
Further, because this is a critical part of my plugin, and it is important to me that it runs well, I have decided to add my own per-object log when in debug mode so that code execution can be easily traced back. On these logs I am putting both real time and the server tick it ran on so I can more easily understand if something is causing the same code to be executed several times within a tick, which would be the case if I messed up handling events or schedulers.
Please note that I am not saying that what I've listed isn't resolvable by other means, but this would be a great utility method for people looking to debug schedulers / events. |
| Comment by md_5 [ 19/Dec/16 ] |
|
Please avoid repeatedly editing your comments, you just sent everyone watching this ticket another 12 emails. |
| Comment by blablubbabc [ 19/Dec/16 ] |
|
>Should be getFullTime >I'm arguing it shouldn't be exposed because with the exception of one or two things, a tick is an abstract concept. It has no physical, fixed, or defined analogue in most cases. You can't define API around something that changes or can be changed arbitrarily unless it is unavoidable, and it's not unavoidable in this case. Well, then one could simply give it a 'plausible meaning', by naming it, analogue to minecraft's existing world time / age, 'Server#getTime()', returning the 'in-game time since server start' (representing some 'universe' time / age). And this time happens to be measured in ticks currently, with no guarantee that this won't be changed in the future, just like world time. |
| Comment by md_5 [ 19/Dec/16 ] |
|
>World 'age' is not accessible in the API as far as I can see currently. Only 'day time'. Should be getFullTime I'm arguing it shouldn't be exposed because with the exception of one or two things, a tick is an abstract concept. It has no physical, fixed, or defined analogue in most cases. You can't define API around something that changes or can be changed arbitrarily unless it is unavoidable, and it's not unavoidable in this case. |
| Comment by blablubbabc [ 19/Dec/16 ] |
|
>World age is persistent and has actual meaning within the game. Anyways, it's bound to a world. If I would want to find out how much 'minecraft time' has passed (regardless of any world) I would always first need to query the current world age of 'some' world (and later be able to query the age again from the same world). Even though I am not really interested in any 'world-specific' data. But the main point isn't so much about world time alone. It's just another example where minecraft counts ticks for tracking and comparing time, and that it would therefore make sense to expose the 'counted ticks since server start' to plugins as well. |
| Comment by md_5 [ 19/Dec/16 ] |
|
>Another use is the time of worlds, which is measured in ticks as well. With this addition it would be possible to get the passed time in ticks independently of any world and any possible changes to its time. For example if a plugin needs to know how much 'minecraft time' has passed since some event X. World age is persistent and has actual meaning within the game. Ticks since server start does not. |
| Comment by blablubbabc [ 19/Dec/16 ] |
|
Well, like already said, ticks are used as measure of time in minecraft and the bukkit scheduler, and therefore in plugins, right now. Plugins are specifying delays in ticks, because ticks are the finest possible scale minecraft / the bukkit scheduler can use for delayed actions. And I doubt this will change anytime soon. Another use is the time of worlds, which is measured in ticks as well. With this addition it would be possible to get the passed time in ticks independently of any world and any possible changes to its time. For example if a plugin needs to know how much 'minecraft time' has passed since some event X. So as of right now I would find this (tiny) addition useful and a valid complement to the existing and currently used API. |
| Comment by md_5 [ 19/Dec/16 ] |
|
>Regardless as to whether or not it's a good idea to use ticks in scheduling, it's already exposed. |
| Comment by pokechu22 [ 19/Dec/16 ] |
|
Regardless as to whether or not it's a good idea to use ticks in scheduling, it's already exposed. In any case, the idea of ticks is definitely needed in at least one other place - redstone. Or basically any other mechanic that is tied to redstone. While something that's user-facing or otherwise clientside should probably be wall-time, things that represent game state make sense off of ticks. If you wanted to make a plugin that acts as a variable redstone clock, then you need ticks. (Total ticks don't entirely come into play there as scheduling can be used, but such a plugin would probably have a situation where you'd need total ticks). |
| Comment by md_5 [ 18/Dec/16 ] |
|
Exposing the concept of ticks even in the scheduler in the first place is a questionable design decision because just like in your example of a cooldown, it can be elongated unexpectedly and has absolutely no reference to what the end user experiences. If I say "this sword has a cooldown of 600 ticks" that could mean anywhere from 20 seconds to 120 seconds. A better approach would be to 1) Define your cooldowns in wall time (which can easily be updated through a task running every 20 ticks. Or 2) [hardmode] write a real time scheduling analogue for Bukkit. I am opposed to exposing the concept of ticks to the API any more than is necessary and I see this change as unnecessary with suitable alternatives already possible. |
| Comment by blablubbabc [ 18/Dec/16 ] |
|
Well, this would be useful if one wants to use ticks as measure of time instead of wall time (if you mean 'actual' time by that). As far as I can tell this is not possible without the plugin counting the ticks itself currently. |
| Comment by md_5 [ 18/Dec/16 ] |
|
>Spontaneously I could think for example of 'lazy cooldowns' which are meant to last a certain amount of ticks That's what wall time is for |
| Comment by pokechu22 [ 18/Dec/16 ] |
|
I can see it being useful for situations where you want to have something last a certain amount of time, but want it to be tied to server time (ticks), and not real time (where lag could influence it). It's not something that would be needed in all situations, but I can see a number of places where it would be helpful. |
| Comment by blablubbabc [ 18/Dec/16 ] |
|
Getting the current tick allows comparing tick counts at different times. Spontaneously I could think for example of 'lazy cooldowns' which are meant to last a certain amount of ticks and which can calculate the passed ticks and remaining ticks based on some 'start tick' and 'duration ticks' or 'end tick', without having to use a scheduler task to count down remaining ticks. |
| Comment by md_5 [ 18/Dec/16 ] |
|
Why is this useful? |