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.11.3'
version = '8.11.4'
description = 'CommandTimer'

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

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.11.3'
version = '8.11.4'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -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
}
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.11.3'
version = '8.11.4'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -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
}
}
Expand Down
68 changes: 59 additions & 9 deletions src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<TaskTime> 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<TaskTime> 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;
}

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.11.3"
version: "8.11.4"
description: "Schedule commands like you want"
author: PlayBossWar
api-version: 1.13
Expand Down