Skip to content

Commit e94aa6c

Browse files
committed
fix: more bugs in execution engine
1 parent 3da0c05 commit e94aa6c

5 files changed

Lines changed: 34 additions & 11 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ java {
99
}
1010

1111
group = 'me.playbosswar.com'
12-
version = '8.16.2'
12+
version = '8.16.3'
1313
description = 'CommandTimer'
1414

1515
repositories {
@@ -74,7 +74,7 @@ publishing {
7474
maven(MavenPublication) {
7575
groupId = 'me.playbosswar.com'
7676
artifactId = 'commandtimer'
77-
version = '8.16.2'
77+
version = '8.16.3'
7878

7979
from components.java
8080
}

java17-build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ java {
1010

1111

1212
group = 'me.playbosswar.com'
13-
version = '8.16.2'
13+
version = '8.16.3'
1414
description = 'CommandTimer'
1515

1616
repositories {
@@ -63,7 +63,7 @@ publishing {
6363
maven(MavenPublication) {
6464
groupId = 'me.playbosswar.com'
6565
artifactId = 'commandtimer-java17'
66-
version = '8.16.2'
66+
version = '8.16.3'
6767

6868
from components.java
6969
}

java21-build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ java {
1010

1111

1212
group = 'me.playbosswar.com'
13-
version = '8.16.2'
13+
version = '8.16.3'
1414
description = 'CommandTimer'
1515

1616
repositories {
@@ -67,7 +67,7 @@ publishing {
6767
maven(MavenPublication) {
6868
groupId = 'me.playbosswar.com'
6969
artifactId = 'commandtimer-java21'
70-
version = '8.16.2'
70+
version = '8.16.3'
7171
from components.java
7272
}
7373
}

src/main/java/me/playbosswar/com/tasks/TasksManager.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,21 @@ public void populateScheduleForTask(Task task) {
210210
.filter(scheduledTask -> scheduledTask.getTask().getId().equals(task.getId()))
211211
.map(ScheduledTask::getDate).max(ZonedDateTime::compareTo).orElse(null);
212212

213+
boolean hadNoScheduledTasks = (latestScheduledDate == null);
214+
ZonedDateTime lastExecuted = task.getLastExecuted().toInstant().atZone(ZoneId.systemDefault());
215+
ZonedDateTime now = ZonedDateTime.now();
213216
if (latestScheduledDate == null) {
214-
ZonedDateTime now = ZonedDateTime.now();
215-
ZonedDateTime lastExecuted = task.getLastExecuted().toInstant().atZone(ZoneId.systemDefault());
216-
latestScheduledDate = lastExecuted.isAfter(now) ? lastExecuted : now;
217+
latestScheduledDate = lastExecuted;
217218
}
218219

219220
if (maxToSchedule <= 0) {
220221
return;
221222
}
222223

223224
if (!task.getTimes().isEmpty()) {
225+
if (latestScheduledDate.isBefore(now)) {
226+
latestScheduledDate = now;
227+
}
224228
List<TaskTime> rangeTimes = new ArrayList<>();
225229
List<TaskTime> nonRangeTimes = new ArrayList<>();
226230

@@ -383,14 +387,33 @@ public void populateScheduleForTask(Task task) {
383387
return;
384388
}
385389

390+
long intervalSeconds = task.getInterval().toSeconds();
391+
if (intervalSeconds <= 0) intervalSeconds = 1;
392+
393+
ZonedDateTime nextExpectedExecution = lastExecuted.plusSeconds(intervalSeconds);
394+
395+
if (hadNoScheduledTasks && nextExpectedExecution.isBefore(now)) {
396+
if (task.getDays().contains(nextExpectedExecution.toLocalDate().getDayOfWeek())) {
397+
scheduledTasks.add(new ScheduledTask(task, nextExpectedExecution));
398+
maxToSchedule--;
399+
}
400+
}
401+
386402
int i = 1;
403+
ZonedDateTime startDate = latestScheduledDate;
404+
387405
while (maxToSchedule > 0) {
388-
ZonedDateTime date = latestScheduledDate.plusSeconds(i * task.getInterval().toSeconds());
406+
ZonedDateTime date = startDate.plusSeconds(i * intervalSeconds);
389407
if (!task.getDays().contains(date.getDayOfWeek())) {
390408
i++;
391409
continue;
392410
}
393411

412+
if (date.isBefore(now)) {
413+
i++;
414+
continue;
415+
}
416+
394417
scheduledTasks.add(new ScheduledTask(task, date));
395418
maxToSchedule--;
396419
i++;

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
main: me.playbosswar.com.CommandTimerPlugin
22
name: "CommandTimer"
3-
version: "8.16.2"
3+
version: "8.16.3"
44
description: "Schedule commands like you want"
55
author: PlayBossWar
66
api-version: 1.13

0 commit comments

Comments
 (0)