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.12.0'
version = '8.13.0'
description = 'CommandTimer'

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

from components.java
}
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ to replace `task` with your actual task name.
- `%commandtimer_ALLTASKS_nextTaskName%`: Show the name of the next task that will be executed
- `%commandtimer_task_nextExecution%`: Get the next execution time in seconds
- `%commandtimer_task_nextExecutionFormat%`: Same as previous placeholder, but formatted in `HH:mm:ss`
- `%commandtimer_task_timeFormat%`: Same as previous placeholder, but you can replace `timeFormat` with a format of your
- `%commandtimer_task_lastExecution%`: Get last execution time in seconds
- `%commandtimer_task_lastExecutionFormat%`: Same as previous placeholder, but formatted in `HH:mm:ss`
- `%commandtimer_task_timeFormat%`: Same as previous placeholders, but you can replace `timeFormat` with a format of your
choice. You can use `DD`, `HH`, `mm` and `ss` as time selectors in your placeholder. If you want to
escape certain characters you can use `'` around the character you want to escape. For a time format `12h34m03s` you
will need the placeholder `%commandtimer_task_HH'h'mm'm'ss's'%`. Depending on your configuration file, you will need
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.12.0'
version = '8.13.0'
description = 'CommandTimer'

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

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.12.0'
version = '8.13.0'
description = 'CommandTimer'

repositories {
Expand Down Expand Up @@ -68,7 +68,7 @@ publishing {
maven(MavenPublication) {
groupId = 'me.playbosswar.com'
artifactId = 'commandtimer-java21'
version = '8.12.0'
version = '8.13.0'
from components.java
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public String onPlaceholderRequest(Player player, @NotNull String identifier) {
return getNextExecutionText(task, fallbackMessage, true);
}

if(placeholder.getPlaceholderType().equalsIgnoreCase("lastExecution")) {
return getLastExecutionText(task, fallbackMessage, false);
}

if(placeholder.getPlaceholderType().equalsIgnoreCase("lastExecutionFormat")) {
return getLastExecutionText(task, fallbackMessage, true);
}

return getNextExecutionText(task, fallbackMessage, true, placeholder.getPlaceholderType());
}

Expand Down Expand Up @@ -185,6 +193,17 @@ private long getNextExecution(Task task) {
return timeLeft;
}

private long getLastExecution(Task task) {
if (task.getLastExecuted() == null || !task.isActive()) {
return -1;
}

long now = new Date().getTime();
Interval interval = new Interval(task.getLastExecuted().getTime(), now);
Duration period = interval.toDuration();
return period.getStandardSeconds();
}

private String getNextExecutionText(Task task, String fallbackMessage, boolean format, String timeFormat) {
long seconds = getNextExecution(task);

Expand All @@ -199,10 +218,28 @@ private String getNextExecutionText(Task task, String fallbackMessage, boolean f
return seconds + "";
}

private String getLastExecutionText(Task task, String fallbackMessage, boolean format, String timeFormat) {
long seconds = getLastExecution(task);

if(seconds == -1) {
return fallbackMessage != null ? fallbackMessage : "";
}

if(format) {
return Tools.getTimeString((int) seconds, timeFormat);
}

return seconds + "";
}

private String getNextExecutionText(Task task, String fallbackMessage, boolean format) {
return getNextExecutionText(task, fallbackMessage, format, "HH:mm:ss");
}

private String getLastExecutionText(Task task, String fallbackMessage, boolean format) {
return getLastExecutionText(task, fallbackMessage, format, "HH:mm:ss");
}

// Get first task that will execute
private Task getSoonestTask(List<Task> tasks) {
Map<Task, Long> timeTillExecution = new HashMap<>();
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.12.0"
version: "8.13.0"
description: "Schedule commands like you want"
author: PlayBossWar
api-version: 1.13
Expand Down