From 6ae10141943803d662aecac402a15c2b7d0b453a Mon Sep 17 00:00:00 2001 From: Krakenied Date: Sun, 20 Jul 2025 17:05:45 +0200 Subject: Add goal placeholder Closes https://github.com/LMBishop/Quests/issues/788 --- .../quests/bukkit/hook/papi/QuestsPlaceholders.java | 8 +++++++- .../quests/bukkit/tasktype/type/PlaytimeTaskType.java | 7 +++++++ .../com/leonardobishop/quests/common/tasktype/TaskType.java | 7 +++++++ docs/tools/placeholderapi.md | 13 +++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java index 3da9db44..f4a778ea 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java @@ -11,6 +11,7 @@ import com.leonardobishop.quests.common.player.questprogressfile.QuestProgress; import com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile; import com.leonardobishop.quests.common.quest.Category; import com.leonardobishop.quests.common.quest.Quest; +import com.leonardobishop.quests.common.quest.Task; import me.clip.placeholderapi.expansion.Cacheable; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.entity.Player; @@ -76,7 +77,7 @@ public class QuestsPlaceholders extends PlaceholderExpansion implements Cacheabl if (qPlayer == null) return Messages.PLACEHOLDERAPI_DATA_NOT_LOADED.getMessageLegacyColor(); String split = args[args.length - 1]; - String result = "null"; + String result; if (!args[0].contains(":") && !args[0].equalsIgnoreCase("tracked")) { if (args.length > 1 && split.equals(args[1])) split = ","; @@ -233,6 +234,11 @@ public class QuestsPlaceholders extends PlaceholderExpansion implements Cacheabl case "c": result = String.valueOf(questProgress.getTaskProgress(t[1]).isCompleted() ? Messages.PLACEHOLDERAPI_TRUE.getMessageLegacyColor() : Messages.PLACEHOLDERAPI_FALSE.getMessageLegacyColor()); break; + case "goal": + case "g": + final Task task = quest.getTaskById(t[1]); + result = (task != null ? String.valueOf(plugin.getTaskTypeManager().getTaskType(task.getType()).getGoal(task)) : "0"); + break; default: return args[0] + "_" + args[1] + "_" + args[2] + " is not a valid placeholder"; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/PlaytimeTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/PlaytimeTaskType.java index 3ca75a16..ea6cb339 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/PlaytimeTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/PlaytimeTaskType.java @@ -14,6 +14,8 @@ import com.leonardobishop.quests.common.quest.Quest; import com.leonardobishop.quests.common.quest.Task; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; public final class PlaytimeTaskType extends BukkitTaskType { @@ -104,4 +106,9 @@ public final class PlaytimeTaskType extends BukkitTaskType { // this.poll.cancel(); // } } + + @Override + public @Nullable Object getGoal(final @NonNull Task task) { + return task.getConfigValue("minutes"); + } } diff --git a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java index 7e294c55..dd3e1058 100644 --- a/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java +++ b/common/src/main/java/com/leonardobishop/quests/common/tasktype/TaskType.java @@ -193,6 +193,13 @@ public abstract class TaskType { // Not implemented here } + /** + * Returns the goal of a task. + */ + public @Nullable Object getGoal(final Task task) { + return task.getConfigValue("amount", "-"); + } + /** * A functional interface for validating task configuration. */ diff --git a/docs/tools/placeholderapi.md b/docs/tools/placeholderapi.md index c75a9522..40f377c7 100644 --- a/docs/tools/placeholderapi.md +++ b/docs/tools/placeholderapi.md @@ -78,6 +78,7 @@ The eCloud extension called 'Quests' is not for this plugin, do not download it! | `%quests_quest:_meetsrequirements%` | Returns **true/false** on whether or not the player has completed the required quests for the quest **``**. | | `%quests_quest:_task:_progress%` | Returns the **progress** of task **`task-id`** on the quest **``**. | | `%quests_quest:_task:_completed%` | Returns **true/false** on whether or not the task **`task-id`** on the quest **``** is completed by the player. | +| `%quests_quest:_task:_goal%` | Returns the **goal** of task **`task-id`** on the quest **``**. | | `%quests_quest:_p:%` | Returns the **local quest placeholder ``** for the quest **``**. | | Placeholder | Description | @@ -108,12 +109,12 @@ The eCloud extension called 'Quests' is not for this plugin, do not download it! ### Per-category quest lists -|Placeholder|Description| -|---|---| -|`%quests_category:_all_list%`|Returns a **comma-seperated\*\* list** of quest **names** on the server.| -|`%quests_category:_completed_list%`|\* Returns a **comma-seperated\*\* list** of quest **names** in the category **``** the player has completed.| -|`%quests_category:_completedbefore_list%`|Returns a **comma-seperated\*\* list** of quest **names** in the category **``** the player has completed **at least once**.| -|`%quests_category:_started_list%`|Returns a **comma-seperated\*\* list** of quest **names** in the category **``** which are active for the player.| +| Placeholder | Description | +|--------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------| +| `%quests_category:_all_list%` | Returns a **comma-seperated\*\* list** of quest **names** on the server. | +| `%quests_category:_completed_list%` | \* Returns a **comma-seperated\*\* list** of quest **names** in the category **``** the player has completed. | +| `%quests_category:_completedbefore_list%` | Returns a **comma-seperated\*\* list** of quest **names** in the category **``** the player has completed **at least once**. | +| `%quests_category:_started_list%` | Returns a **comma-seperated\*\* list** of quest **names** in the category **``** which are active for the player. | ### Per-category quest ID lists -- cgit v1.2.3-70-g09d2