From 740b45d0f10c5c92de1c8b7ef9bfe3b26f96453e Mon Sep 17 00:00:00 2001 From: Tristan Vermeesch Date: Thu, 22 May 2025 18:06:34 +0200 Subject: [PATCH 1/2] add lastExecution and lastExecutionFormat placeholders --- build.gradle | 4 +- java17-build.gradle | 4 +- java21-build.gradle | 4 +- .../com/hooks/PAPIPlaceholders.java | 37 +++++++++++++++++++ src/main/resources/plugin.yml | 2 +- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index c6f0fc5..d1364cb 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ java { } group = 'me.playbosswar.com' -version = '8.12.0' +version = '8.13.0' description = 'CommandTimer' repositories { @@ -74,7 +74,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer' - version = '8.12.0' + version = '8.13.0' from components.java } diff --git a/java17-build.gradle b/java17-build.gradle index 9456a2e..9ab37e2 100644 --- a/java17-build.gradle +++ b/java17-build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.12.0' +version = '8.13.0' description = 'CommandTimer' repositories { @@ -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 } diff --git a/java21-build.gradle b/java21-build.gradle index 66dd406..e931248 100644 --- a/java21-build.gradle +++ b/java21-build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.12.0' +version = '8.13.0' description = 'CommandTimer' repositories { @@ -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 } } diff --git a/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java b/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java index 0259df0..ebf7e6d 100644 --- a/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java +++ b/src/main/java/me/playbosswar/com/hooks/PAPIPlaceholders.java @@ -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()); } @@ -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); @@ -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 tasks) { Map timeTillExecution = new HashMap<>(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f045011..e2cb1c0 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.12.0" +version: "8.13.0" description: "Schedule commands like you want" author: PlayBossWar api-version: 1.13 From 424f8350bc2832a9a351e646c8ddc9a30d692d3b Mon Sep 17 00:00:00 2001 From: Tristan Vermeesch Date: Thu, 22 May 2025 18:08:12 +0200 Subject: [PATCH 2/2] add docs --- docs/docs/placeholders.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/placeholders.md b/docs/docs/placeholders.md index 4ea658b..b4a95e7 100644 --- a/docs/docs/placeholders.md +++ b/docs/docs/placeholders.md @@ -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