Skip to content

Implement task system#26

Merged
Relism merged 4 commits intoPixel-Services:masterfrom
Tidal-Realms:master
Apr 21, 2025
Merged

Implement task system#26
Relism merged 4 commits intoPixel-Services:masterfrom
Tidal-Realms:master

Conversation

@BitByLogics
Copy link
Copy Markdown
Contributor

✨ 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 TaskScheduler Interface

  • Defines methods for:
    • runTask(...) – run immediately
    • runTaskLater(...) – run after a delay
    • runTaskTimer(...) – run repeatedly
    • Async equivalents for all of the above
    • cancelTask(int taskId) – cancel by task ID
  • Each task is associated with a MbModule, allowing clean separation and easier debugging per module.

✅ Task Tracking

  • getTasks() returns all active ScheduledTask instances
  • getTickRate() exposes the base tick rate (useful for delay/period calculations)

💻 Command Extension

Added a new subcommand to the module command:

/module tasks <module_id>

Displays all scheduled tasks for a given module, including:

  • Total number of tasks
  • Count of async tasks
  • Count of repeating tasks

Example output:

[INFO] ModuleName Scheduled Tasks:
[INFO] Total: 4, Async: 2, Repeating: 1

🧩 Module Integration

  • Each MbModule now holds a reference to the shared TaskScheduler (getTaskScheduler())
  • Modules can easily schedule and manage their own tasks without global coupling

🛠️ Future Considerations

  • Add command to cancel tasks by ID or name
  • Add debugging tools for showing next run time or elapsed time
  • Consider priority/task queue optimization for async workers

@sieadev sieadev requested a review from Relism April 21, 2025 19:22
@sieadev sieadev self-assigned this Apr 21, 2025
@sieadev sieadev self-requested a review April 21, 2025 19:23
@sieadev sieadev linked an issue Apr 21, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@Relism Relism left a comment

Choose a reason for hiding this comment

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

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:

@BitByLogics BitByLogics requested a review from Relism April 21, 2025 20:58
Copy link
Copy Markdown
Contributor

@Relism Relism left a comment

Choose a reason for hiding this comment

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

looks good !

@Relism Relism merged commit e97fd36 into Pixel-Services:master Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(Task) Scheduler

3 participants