Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
plugin
Scheduled Task
Schedule repeating tasks using HytaleServer.SCHEDULED_EXECUTOR.
Example Code
// In plugin setup():
int intervalMinutes = 5;
HytaleServer.SCHEDULED_EXECUTOR.scheduleWithFixedDelay(() -> {
try {
this.getLogger().at(Level.INFO).log("Running scheduled task...");
// Do something periodically
Universe.get().runBackup().thenAccept(v -> {
this.getLogger().at(Level.INFO).log("Backup completed!");
});
} catch (Exception e) {
this.getLogger().at(Level.SEVERE).withCause(e).log("Task failed!");
}
}, intervalMinutes, intervalMinutes, TimeUnit.MINUTES);
// One-time delayed task:
HytaleServer.SCHEDULED_EXECUTOR.schedule(() -> {
// Run once after delay
}, 30, TimeUnit.SECONDS);
Thread Safety
Scheduled tasks run on executor thread, not world thread. Use world.execute() for entity modifications.
Common Mistakes
Forgetting try-catch in scheduled task (exceptions can kill the scheduler). Blocking the executor with long operations.