Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the scheduling system API for future additions #5960

Open
wants to merge 15 commits into
base: dev/feature
Choose a base branch
from

Conversation

TheLimeGlass
Copy link
Collaborator

@TheLimeGlass TheLimeGlass commented Aug 31, 2023

Description

Updates the entire Task scheduling system in Skript. This API change is required to support versioning reflection of future additions like Folia https://github.com/PaperMC/Folia

I have a branch which enables Folia support for Skript and completes the Task scheduling system to adapt to Folia properly https://github.com/SkriptLang/Skript/tree/feature/folia Do note this is in experimental phase and still throws exceptions due to the following;

The main changes that are needed to that branch is replacing Bukkit.getScheduler with Skript's new Task luckily old parts of Skript accomplish this, but ever since bensku additions, the Skript project has had the habit of using Bukkit.getScheduler directly, rather than Skript's own Task. So many parts of Skript are going to need changes in that branch.

Once this is merged, i'll directly work on the Folia branch for the FoliaScheduler class.


Target Minecraft Versions: none
Requirements: none
Related Issues: #5645

@TheLimeGlass TheLimeGlass added enhancement Feature request, an issue about something that could be improved, or a PR improving something. 2.8 Targeting a 2.8.X version release labels Aug 31, 2023
@TheLimeGlass TheLimeGlass marked this pull request as draft August 31, 2023 22:52
@TheLimeGlass
Copy link
Collaborator Author

TheLimeGlass commented Aug 31, 2023

Placing under draft until I get opinions from the Core SkriptLang team and I also have all the JavaDocs to do.

@bluelhf
Copy link
Contributor

bluelhf commented Sep 1, 2023

Not core team, but Folia support would definitely be nice and fits the goals of Skript :)

Would it be possible to convert all usages of BukkitScheduler to Skript's Task on the main branch and then rebase the folia branch? We probably should've stuck to Skript's Task anyway...

Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an admirable attempt and definitely something that needs doing, however it has brought to my attention how much of the existing task timing system is [dangerous/bizarre/inefficient] and I think this would be an excellent opportunity to clean up some of the main offenders.

We could fix the problems in a separate PR (in which case I'll dismiss my change request and approve this) but we should first discuss how we want to approach this.

/**
* Class to handle the abstract versioning and to be loaded from the Skript main class.
*/
public class TaskManager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of static abuse for something that probably ought not be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's package only access. The Task class should not store which PlatformScheduler to use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to agree with Kenzie here. I don't think there's a good reason for why we can't support multiple instances for this class.

I think it should be fine to accept any plugin instance. Additionally, if the static is needed for the Task class(es), have this class be used to create/submit new tasks. Though, the methods of this class seem to just wrap the Scheduler. Why not just have users submit tasks to the scheduler directly? e.g. Skript.getScheduler()

@Moderocky Moderocky force-pushed the master branch 3 times, most recently from bd134d0 to 3f08853 Compare September 16, 2023 16:59
@TheLimeGlass TheLimeGlass changed the base branch from master to dev/feature November 23, 2023 20:30
@sovdeeth sovdeeth removed the 2.8 Targeting a 2.8.X version release label Dec 30, 2023
@sovdeeth
Copy link
Member

Closing due to inactivity.

@sovdeeth sovdeeth closed this Jul 16, 2024
@TheLimeGlass
Copy link
Collaborator Author

This is a very important future change requiring attention.

@TheLimeGlass TheLimeGlass reopened this Jul 16, 2024
@sovdeeth
Copy link
Member

This is a very important future change requiring attention.

There are requested changes still waiting from September 2023. These haven't been addressed since, hence closed for inactivity. Do you intend to address these requests?

@KIttenPixel
Copy link

I would like this.

@TheLimeGlass TheLimeGlass marked this pull request as ready for review August 31, 2024 16:43
@TheLimeGlass TheLimeGlass requested a review from Moderocky August 31, 2024 16:43
@TheLimeGlass
Copy link
Collaborator Author

I didn't realize how well I engineered this API.
I had to re-understand all of what was being done.

Copy link
Contributor

@bluelhf bluelhf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a good step toward folia support :)

Co-authored-by: Ilari Suhonen <ilari.suhonen@gmail.com>
@TheLimeGlass TheLimeGlass requested a review from bluelhf September 1, 2024 20:20
Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start.

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks really good

}

/**
* Re-schedules the task to run next after the given delay. If this task was repeating it will continue so using the same period as before.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this line mean that this method has no effect on repeating tasks? I think it should be rewritten to be a little clearer

src/main/java/org/skriptlang/skript/scheduler/Task.java Outdated Show resolved Hide resolved
import ch.njol.skript.Skript;

/**
* Class to handle the abstract versioning and to be loaded from the Skript main class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment doesn't make much sense. I would suggest instead maybe Handles the scheduling of tasks in a platform-agnostic manner. Loaded by the Skript main class.

Comment on lines +82 to +83
long delayTicks = (task.getTimeUnit().toMillis(delay) / 1000) * 20;
long periodTicks = (task.getTimeUnit().toMillis(task.getPeriod()) / 1000) * 20;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, why not / 50? Is it magic number concern?

sovdeeth and others added 2 commits October 12, 2024 19:40
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see some changes to the design so that we can move away from all of the static usage.

Comment on lines +1 to +18
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/

Fine to remove now

private long periodInTicks = -1;

public Task(long delayInTicks, long periodInTicks) {
this(Skript.getInstance(), delayInTicks, periodInTicks);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document for these methods that the Skript instance is being used

/**
* Class to handle the abstract versioning and to be loaded from the Skript main class.
*/
public class TaskManager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to agree with Kenzie here. I don't think there's a good reason for why we can't support multiple instances for this class.

I think it should be fine to accept any plugin instance. Additionally, if the static is needed for the Task class(es), have this class be used to create/submit new tasks. Though, the methods of this class seem to just wrap the Scheduler. Why not just have users submit tasks to the scheduler directly? e.g. Skript.getScheduler()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants