Implement task system#26
Merged
Relism merged 4 commits intoPixel-Services:masterfrom Apr 21, 2025
Merged
Conversation
Closed
Relism
requested changes
Apr 21, 2025
Contributor
Relism
left a comment
There was a problem hiding this comment.
Great idea overall, and we thank you for your contribution! However, I'd recommend removing and decoupling the TPS system from the scheduler.
Since MoBot is built around Discord API interactions, it doesn't have real-time world simulation requirements like Bukkit's entities or player inputs. TPS-style ticking is unnecessary here and could introduce unneeded complexity or confusion.
Let’s keep the scheduling logic but make it time-based (e.g., using ScheduledExecutorService, Timer, or similar) rather than tick-based.
Let me know if you'd like help adjusting the implementation, and thank you again c:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
✨ Add Custom Task Scheduler API
Summary
This PR introduces a modular and extensible task scheduling system inspired by the Bukkit Scheduler, enabling modules to run tasks synchronously or asynchronously, with support for delayed and repeating execution.
📦 What’s Included
✅ New
TaskSchedulerInterfacerunTask(...)– run immediatelyrunTaskLater(...)– run after a delayrunTaskTimer(...)– run repeatedlycancelTask(int taskId)– cancel by task IDMbModule, allowing clean separation and easier debugging per module.✅ Task Tracking
getTasks()returns all activeScheduledTaskinstancesgetTickRate()exposes the base tick rate (useful for delay/period calculations)💻 Command Extension
Added a new subcommand to the module command:
Displays all scheduled tasks for a given module, including:
Example output:
🧩 Module Integration
MbModulenow holds a reference to the sharedTaskScheduler(getTaskScheduler())🛠️ Future Considerations