diff --git a/build.gradle b/build.gradle index c78ee9c4..32890742 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ java { } group = 'me.playbosswar.com' -version = '8.11.3' +version = '8.11.4' description = 'CommandTimer' repositories { @@ -70,7 +70,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer' - version = '8.11.3' + version = '8.11.4' from components.java } diff --git a/java17-build.gradle b/java17-build.gradle index 51cf26a8..79f05258 100644 --- a/java17-build.gradle +++ b/java17-build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.11.3' +version = '8.11.4' description = 'CommandTimer' repositories { @@ -63,7 +63,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer-java17' - version = '8.11.3' + version = '8.11.4' from components.java } diff --git a/java21-build.gradle b/java21-build.gradle index 92260f0c..99d977a4 100644 --- a/java21-build.gradle +++ b/java21-build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.11.3' +version = '8.11.4' description = 'CommandTimer' repositories { @@ -68,7 +68,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer-java21' - version = '8.11.3' + version = '8.11.4' from components.java } } diff --git a/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java b/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java index 2f2e6bb6..0259df0d 100644 --- a/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java +++ b/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java @@ -4,6 +4,7 @@ import me.playbosswar.com.CommandTimerPlugin; import me.playbosswar.com.utils.Tools; import me.playbosswar.com.tasks.Task; +import me.playbosswar.com.tasks.TaskTime; import me.playbosswar.com.utils.Messages; import me.playbosswar.com.utils.TaskTimeUtils; import org.bukkit.entity.Player; @@ -13,6 +14,7 @@ import org.joda.time.Interval; import java.util.*; +import java.util.stream.Collectors; public class PAPIPlaceholders extends PlaceholderExpansion { private final Plugin plugin; @@ -112,23 +114,71 @@ private String getSecondsText(Task task, String fallbackMessage, boolean format) // Get time in seconds before next task execution private long getNextExecution(Task task) { + long now = new Date().getTime(); // TODO: Take into account the days - // TODO: Take into account the hour ranges - if(!task.getTimes().isEmpty()) { - Date date = TaskTimeUtils.getSoonestTaskTime(task, task.getTimes()); + if (!task.getTimes().isEmpty()) { + List rangeTimes = task.getTimes().stream().filter(t -> t.getTime2() != null) + .collect(Collectors.toList()); - if(date == null || !task.isActive()) { - return -1; + // If there are no range times, use the single times with the standard + // calculation + Date date = TaskTimeUtils.getSoonestTaskTime(task, task.getTimes()); + if (rangeTimes.isEmpty()) { + if (date == null || !task.isActive()) { + return -1; + } + + return (date.getTime() - now) / 1000; + } else { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(now); + int currentSeconds = cal.get(Calendar.HOUR_OF_DAY) * 3600 + + cal.get(Calendar.MINUTE) * 60 + + cal.get(Calendar.SECOND); + + List applicableTimes = new ArrayList<>(); + for (TaskTime rangeTime : rangeTimes) { + int startSeconds = rangeTime.getTime1().getHour() * 3600 + + rangeTime.getTime1().getMinute() * 60 + + rangeTime.getTime1().getSecond(); + int endSeconds = rangeTime.getTime2().getHour() * 3600 + + rangeTime.getTime2().getMinute() * 60 + + rangeTime.getTime2().getSecond(); + + // Handle range spanning to next day + if (endSeconds < startSeconds) { + if (currentSeconds >= startSeconds || currentSeconds <= endSeconds) { + applicableTimes.add(rangeTime); + } + } else if (currentSeconds >= startSeconds && currentSeconds <= endSeconds) { + applicableTimes.add(rangeTime); + } + } + + if (applicableTimes.isEmpty()) { + if (date == null || !task.isActive()) { + return -1; + } + + return (date.getTime() - now) / 1000; + } + + Interval interval = new Interval(task.getLastExecuted().getTime(), now); + Duration period = interval.toDuration(); + long timeLeft = task.getInterval().toSeconds() - period.getStandardSeconds(); + if ((timeLeft < 0 || !task.isActive())) { + return -1; + } + + return timeLeft; } - - return (date.getTime() - new Date().getTime()) / 1000; } - Interval interval = new Interval(task.getLastExecuted().getTime(), new Date().getTime()); + Interval interval = new Interval(task.getLastExecuted().getTime(), now); Duration period = interval.toDuration(); long timeLeft = task.getInterval().toSeconds() - period.getStandardSeconds(); - if((timeLeft < 0 || !task.isActive())) { + if ((timeLeft < 0 || !task.isActive())) { return -1; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0581373e..7f5e30ee 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: me.playbosswar.com.CommandTimerPlugin name: "CommandTimer" -version: "8.11.3" +version: "8.11.4" description: "Schedule commands like you want" author: PlayBossWar api-version: 1.13