diff --git a/src/main/java/emu/grasscutter/task/TaskHandler.java b/src/main/java/emu/grasscutter/task/TaskHandler.java index c61f45534..ea6fe22cd 100644 --- a/src/main/java/emu/grasscutter/task/TaskHandler.java +++ b/src/main/java/emu/grasscutter/task/TaskHandler.java @@ -9,6 +9,14 @@ public class TaskHandler implements Job { execute(null); } + public void onEnable() { + + } + + public void onDisable() { + + } + @Override public void execute(JobExecutionContext context) throws JobExecutionException { // TODO Auto-generated method stub diff --git a/src/main/java/emu/grasscutter/task/TaskMap.java b/src/main/java/emu/grasscutter/task/TaskMap.java index 9e6c1efca..fe067e795 100644 --- a/src/main/java/emu/grasscutter/task/TaskMap.java +++ b/src/main/java/emu/grasscutter/task/TaskMap.java @@ -30,7 +30,7 @@ public final class TaskMap { public void resetNow() { // Unregister all tasks for (TaskHandler task : this.tasks.values()) { - unregisterTask(task.getClass().getAnnotation(Task.class).taskName()); + unregisterTask(task); } // Run all afterReset tasks @@ -51,17 +51,19 @@ public final class TaskMap { } } - public TaskMap unregisterTask(String taskName) { - this.tasks.remove(taskName); - this.annotations.remove(taskName); + public TaskMap unregisterTask(TaskHandler task) { + this.tasks.remove(task.getClass().getAnnotation(Task.class).taskName()); + this.annotations.remove(task.getClass().getAnnotation(Task.class).taskName()); try { Scheduler scheduler = schedulerFactory.getScheduler(); - scheduler.deleteJob(new JobKey(taskName)); + scheduler.deleteJob(new JobKey(task.getClass().getAnnotation(Task.class).taskName())); } catch (SchedulerException e) { e.printStackTrace(); } + task.onDisable(); + return this; } @@ -88,6 +90,7 @@ public final class TaskMap { if (annotation.executeImmediately()) { task.execute(null); } + task.onEnable(); } catch (SchedulerException e) { e.printStackTrace(); } diff --git a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java index 21ac60c97..51088f46d 100644 --- a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java +++ b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java @@ -11,6 +11,17 @@ import org.quartz.JobExecutionException; @Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") // taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) public class MoonCard extends TaskHandler { + + @Override + public void onEnable() { + Grasscutter.getLogger().info("[Task] MoonCard task enabled."); + } + + @Override + public void onDisable() { + Grasscutter.getLogger().info("[Task] MoonCard task disabled."); + } + @Override public synchronized void execute(JobExecutionContext context) throws JobExecutionException { Grasscutter.getGameServer().getPlayers().forEach((uid, player) -> {