Extend BukkitScheduler with new/simplified methods #11825
+504
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For quite some time, I’ve noticed various plugins implementing strange calculations for converting real time into ticks, especially when scheduling tasks at real-world dates and times. These implementations often involve a lot of complexity around time zones.
In this PR, I’ve added several methods aimed at simplifying scheduler usage. I utilized Java’s modern time API, including
Duration
,LocalDateTime
andLocalTime
Added API:
Duration
Duration
intervalLocalDateTime
. Time zone handling and potential clock adjustments are managed automatically without user interventionLocalTime
. As with the above, time zone handling does not require user intervention. This required the creation of a new class extendingCraftTask
. In the current version of this PR, I implemented this only for synchronous tasks, as doing it for asynchronous ones would be more complex. I’d like to hear your opinion on this approach first. The existing class has been coded in such a way to share most of the code if the async version was createdThis was quite challenging to implement, cause the
CraftScheduler
codebase is very inconsistent. I tried to model my methods on the existing ones in style and structure. I did not touch methods that were annotated as deprecated. I believe the scheduler’s overall design is something that should be addressed, but I refrained from making changes myself as I’m unsure if that’s something the team desires.I’ve provided proper Javadocs for all the new methods, based on the existing ones and adding some additional notes for users to consider.
I’m not entirely sure how the team prefers these methods to be implemented or which parts of the API should be designed differently. However, I think that these methods will help simplify plugin code and improve its readability. If implemented and documented correctly, these methods shouldn’t cause any issues.
I will be grateful for your feedback and happy to adapt to it