How to cancel a specific scheduler containing a UUID


#1

Hey, I currently have a scheduler being canceled by finding a task name and cancelling it.

How can I do the same but only if it is containing a certain player UUID?

Current code:
Sponge.getScheduler().getTasksByName(String.valueOf(gym3)).forEach(t -> t.cancel());

Current Issue: Cancels all tasks within that name. Which is bad for when mutliple people are in this task (it is a per player cooldown).

Looking for something close to this, but with the added if contains check within the format for the player’s UUID.

So like, get scheduler with name of task and if it contains the UUID referenced then cancel that one task instead of them all.

May be stupid or not possible, but I took a break from coding for around a year.
Thanks.


#2

EDIT: Just removed the player from the tasks instead as they always need to be running anyway.


#3

Manage the tasks yourself.

You can still use the scheduler for registering tasks, but it isn’t responsible for storing your metadata.

You should have a class of your own that has a task reference inside it that has a 1:1 relationship with these tasks, that also contains the metadata.

You could then filter them however you want, then call task.cancel yourself, and remove them from your management system or whatever.