> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/fr/plugins/scheduler.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Scheduler

Cette page explique comment faire tourner du travail plus tard, de façon répétée, ou hors du thread de simulation. Elle sert à celles et ceux qui écrivent un plugin.

`getServer().scheduler()` exécute du travail différé, répété ou asynchrone. L'unité de temps est le tick : 20 ticks font une seconde.

| Méthode                                              | Effet                                                                          |
| ---------------------------------------------------- | ------------------------------------------------------------------------------ |
| `runLater(owner, delayTicks, task)`                  | Exécute `task` une fois après `delayTicks`. `0` veut dire au tick suivant.     |
| `runRepeating(owner, delayTicks, periodTicks, task)` | Exécute `task` tous les `periodTicks`, après un premier délai de `delayTicks`. |
| `runAsync(owner, task)`                              | Exécute `task` une fois sur un thread worker.                                  |
| `cancelAll(owner)`                                   | Annule toutes les tâches de `owner`.                                           |

Chaque méthode renvoie un `Scheduler.Task` (sauf `cancelAll`) avec `cancel()` et `cancelled()`. Passe ton plugin (`this`) comme propriétaire. Le serveur annule les tâches d'un plugin quand il est désactivé.

```java
// toutes les 10 secondes, sur le thread de simulation
Scheduler.Task announce = getServer().scheduler().runRepeating(this, 200, 200, () ->
        getServer().broadcast("Remember to rest at a campfire."));

// plus tard
announce.cancel();
```

Les méthodes de planification peuvent être appelées depuis n'importe quel thread.

## Tâches synchrones

Les tâches `runLater` et `runRepeating` tournent sur le thread de simulation pendant la phase plugins d'un tick, dans l'ordre du tick d'échéance puis de la soumission. Elles peuvent toucher à l'état du jeu.

Une exception dans une tâche est loggée et comptée. Les autres tâches s'exécutent quand même. La tâche répétée garde son planning.

Le thread de simulation ne peut pas interrompre une tâche. Une tâche synchrone qui prend plus de 10 ms est signalée dans le log avec son propriétaire. Garde chaque tâche courte, et découpe un long travail sur plusieurs ticks.

## Tâches asynchrones

Les tâches `runAsync` tournent sur un pool de workers. Elles ne doivent ni lire ni écrire l'état du jeu. Sers-t'en pour le travail qui attend : un fichier, un appel réseau, un gros calcul. Reviens sur le thread de simulation avec `runLater` pour appliquer le résultat. Le schéma est dans [Cycle de vie et threads](https://docs.aethercube.fr/developers/fr/plugins/cycle-de-vie-et-threads.md).

Le serveur enregistre le temps CPU des événements et des tâches de chaque plugin. Voir [Performances et métriques](https://docs.aethercube.fr/developers/fr/heberger-un-serveur/performances-et-metriques.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/fr/plugins/scheduler.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
