Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ java {
}

group = 'me.playbosswar.com'
version = '8.15.0'
version = '8.15.1'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -74,7 +74,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer'
version = '8.15.0'
version = '8.15.1'

from components.java
}
Expand Down
4 changes: 2 additions & 2 deletions java17-build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java {


group = 'me.playbosswar.com'
version = '8.15.0'
version = '8.15.1'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -63,7 +63,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer-java17'
version = '8.15.0'
version = '8.15.1'

from components.java
}
Expand Down
4 changes: 2 additions & 2 deletions java21-build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ java {


group = 'me.playbosswar.com'
version = '8.15.0'
version = '8.15.1'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -67,7 +67,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer-java21'
version = '8.15.0'
version = '8.15.1'
from components.java
}
}
Expand Down
67 changes: 54 additions & 13 deletions src/main/java/me/playbosswar/com/tasks/TasksManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public void populateScheduleForTask(Task task) {
return;
}

boolean usesMinecraftTime = task.getTimes().stream().anyMatch(TaskTime::isMinecraftTime);
if (usesMinecraftTime) {
scheduledTasks.removeIf(st -> st.getTask().getId().equals(task.getId()));
}

int executionLimit = task.getExecutionLimit();
int timesExecuted = task.getTimesExecuted();
long alreadyScheduled = scheduledTasks.stream()
Expand Down Expand Up @@ -228,28 +233,56 @@ public void populateScheduleForTask(Task task) {
LocalTime startRange = taskTime.getTime1();
LocalTime endRange = taskTime.getTime2();

int i = 0;
LocalTime currentMcTime = Tools.getMinecraftTimeAt(world, ZonedDateTime.now());
boolean currentlyInWindow = isTimeInRange(currentMcTime, startRange, endRange);

int mcDay = 0;
boolean firstIteration = true;
while (maxToSchedule > 0) {
ZonedDateTime date = Tools.getNextMinecraftTime(world, startRange, i);
if (!task.getDays().contains(date.getDayOfWeek())) {
i++;
continue;
ZonedDateTime windowStart;
ZonedDateTime windowEnd;

if (firstIteration && currentlyInWindow) {
windowStart = ZonedDateTime.now();
windowEnd = Tools.getNextMinecraftTime(world, endRange, 0);
if (windowEnd.isBefore(windowStart)) {
windowEnd = Tools.getNextMinecraftTime(world, endRange, 1);
}
} else {
int dayOffset = (firstIteration && currentlyInWindow) ? 1 : mcDay;
if (firstIteration && !currentlyInWindow) {
dayOffset = 0;
}
windowStart = Tools.getNextMinecraftTime(world, startRange, dayOffset);
windowEnd = Tools.getNextMinecraftTime(world, endRange, dayOffset);
if (windowEnd.isBefore(windowStart)) {
windowEnd = Tools.getNextMinecraftTime(world, endRange, dayOffset + 1);
}
}
firstIteration = false;

LocalTime mcTimeAtExecution = Tools.getMinecraftTimeAt(world, date);
if (!(mcTimeAtExecution.isAfter(startRange) && mcTimeAtExecution.isBefore(endRange))) {
i++;
if (!task.getDays().contains(windowStart.toLocalDate().getDayOfWeek())) {
mcDay++;
continue;
}

if (date.isBefore(latestScheduledDate)) {
i++;
if (windowEnd.isBefore(latestScheduledDate)) {
mcDay++;
continue;
}

scheduledTasks.add(new ScheduledTask(task, date));
maxToSchedule--;
i++;
ZonedDateTime execTime = windowStart.isBefore(latestScheduledDate) ? latestScheduledDate : windowStart;
long intervalSeconds = task.getInterval().toSeconds();
if (intervalSeconds <= 0) intervalSeconds = 1;

while (maxToSchedule > 0 && !execTime.isAfter(windowEnd)) {
if (!execTime.isBefore(latestScheduledDate)) {
scheduledTasks.add(new ScheduledTask(task, execTime));
maxToSchedule--;
}
execTime = execTime.plusSeconds(intervalSeconds);
}
mcDay++;
}
} else {
LocalTime time = taskTime.getTime1();
Expand Down Expand Up @@ -367,6 +400,14 @@ public int getNextTaskCommandIndex(Task task) {
return selectedCommandIndex;
}

private boolean isTimeInRange(LocalTime time, LocalTime start, LocalTime end) {
if (start.isBefore(end)) {
return !time.isBefore(start) && !time.isAfter(end);
} else {
return !time.isBefore(start) || !time.isAfter(end);
}
}

public void disable() {
List<Task> tasksToStore = loadedTasks.stream().filter(Task::isActive).collect(Collectors.toList());
tasksToStore.forEach(Task::storeInstance);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/playbosswar/com/utils/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public static void sendHelpMessage(CommandSender sender) {
Messages.sendMessage(sender, "§e/cmt activate <task> - §7Activate a task");
Messages.sendMessage(sender, "§e/cmt deactivate <task> - §7Deactivate a task");
Messages.sendMessage(sender, "§e/cmt execute <task> - §7Instantly execute a task");
Messages.sendMessage(sender, "§e/cmt nextexecutions <task> - §7Show next 10 executions for a task");
Messages.sendMessage(sender, "§e/cmt schedule [-after 1h10m5s] [-gender CONSOLE] <command> - §7Schedule a one-time command");
Messages.sendMessage(sender, "§e/cmt reload - §7Reload the plugin");
Messages.sendMessage(sender, "§e/cmt migrateToDatabase - §7Migrate JSON files to database");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: me.playbosswar.com.CommandTimerPlugin
name: "CommandTimer"
version: "8.15.0"
version: "8.15.1"
description: "Schedule commands like you want"
author: PlayBossWar
api-version: 1.13
Expand Down