aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrakenied <krakenied1@gmail.com>2025-07-29 11:24:24 +0200
committerKrakenied <46192742+Krakenied@users.noreply.github.com>2025-07-29 11:48:02 +0200
commitd3536cb0528d6b441fe8b5ae34f2164036d4c532 (patch)
tree1044e2bd40cc381100a155467a30bd56e237bb79
parent1cc709b81c4faca94d3e33e02862523d3b67605f (diff)
Add internal goal placeholder
Closes https://github.com/LMBishop/Quests/issues/658
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java2
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/itemstack/QItemStack.java31
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java2
-rw-r--r--docs/configuration/creating-a-quest.md6
4 files changed, 30 insertions, 11 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 728672e9..26b78f22 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
@@ -254,7 +254,7 @@ public class QuestsPlaceholders extends PlaceholderExpansion implements Cacheabl
QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgressOrNull(quest);
assert questProgress != null;
- placeholder = QItemStack.processPlaceholders(Chat.legacyColor(placeholder), questProgress);
+ placeholder = QItemStack.processPlaceholders(plugin, Chat.legacyColor(placeholder), questProgress);
return placeholder;
} else {
return args[0] + "_" + args[1] + " is not a valid placeholder";
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/itemstack/QItemStack.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/itemstack/QItemStack.java
index 8c7d5793..cb3d29fe 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/itemstack/QItemStack.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/itemstack/QItemStack.java
@@ -9,6 +9,8 @@ import com.leonardobishop.quests.common.player.questprogressfile.QuestProgress;
import com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile;
import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
import com.leonardobishop.quests.common.quest.Quest;
+import com.leonardobishop.quests.common.quest.Task;
+import com.leonardobishop.quests.common.tasktype.TaskType;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@@ -119,7 +121,7 @@ public class QItemStack {
}
if (questProgress != null) {
for (String s : tempLore) {
- s = processPlaceholders(s, questProgress);
+ s = processPlaceholders(plugin, s, questProgress);
s = processTimeLeft(s, quest, qPlayer.getQuestProgressFile());
if (plugin.getQuestsConfig().getBoolean("options.gui-use-placeholderapi")) {
s = plugin.getPlaceholderAPIProcessor().apply(player, s);
@@ -134,11 +136,11 @@ public class QItemStack {
public static final Pattern TASK_PLACEHOLDER_PATTERN = Pattern.compile("\\{([^}]+):(progress|goal|complete|id)}");
- public static String processPlaceholders(String s, QuestProgress questProgress) {
- return processPlaceholders(s, questProgress, null);
+ public static String processPlaceholders(BukkitQuestsPlugin plugin, String s, QuestProgress questProgress) {
+ return processPlaceholders(plugin, s, questProgress, null);
}
- public static String processPlaceholders(String s, QuestProgress questProgress, TaskProgress taskProgress) {
+ public static String processPlaceholders(BukkitQuestsPlugin plugin, String s, QuestProgress questProgress, TaskProgress taskProgress) {
Matcher matcher = TASK_PLACEHOLDER_PATTERN.matcher(s);
while (matcher.find()) {
@@ -148,7 +150,7 @@ public class QItemStack {
if (taskProgress != null && taskIdPart.equals("this")) {
matchedTaskProgress = taskProgress;
} else {
- matchedTaskProgress = questProgress.getTaskProgress(taskIdPart);
+ matchedTaskProgress = questProgress.getTaskProgressOrNull(taskIdPart);
}
if (matchedTaskProgress == null) {
@@ -173,7 +175,22 @@ public class QItemStack {
}
}
- // TODO add goal
+ // goal placeholders
+ case "goal" -> {
+ Quest quest = plugin.getQuestManager().getQuestById(questProgress.getQuestId());
+ Task task = quest != null ? quest.getTaskById(matchedTaskProgress.getTaskId()) : null;
+ TaskType taskType = task != null ? plugin.getTaskTypeManager().getTaskType(task.getType()) : null;
+ Object goal = taskType != null ? taskType.getGoal(task) : null;
+ if (goal instanceof Float || goal instanceof Double || goal instanceof BigDecimal) {
+ replacement = FormatUtils.floating((Number) goal);
+ } else if (goal instanceof Integer || goal instanceof Long || goal instanceof BigInteger) {
+ replacement = FormatUtils.integral((Number) goal);
+ } else if (goal != null) {
+ replacement = String.valueOf(goal);
+ } else {
+ replacement = String.valueOf(0);
+ }
+ }
// completion placeholders
case "complete" -> {
@@ -211,4 +228,4 @@ public class QItemStack {
}
return s.replace("{timeleft}", timeLeft);
}
-} \ No newline at end of file
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java
index 02870462..5594211f 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java
@@ -221,7 +221,7 @@ public class TaskUtils {
}
QuestProgress questProgress = pendingTask.questProgress();
- title = QItemStack.processPlaceholders(title, questProgress, taskProgress);
+ title = QItemStack.processPlaceholders(plugin, title, questProgress, taskProgress);
boolean usePlaceholderAPI = plugin.getQuestsConfig().getBoolean("options.progress-use-placeholderapi", false);
if (usePlaceholderAPI) {
diff --git a/docs/configuration/creating-a-quest.md b/docs/configuration/creating-a-quest.md
index d2a91397..b9127cea 100644
--- a/docs/configuration/creating-a-quest.md
+++ b/docs/configuration/creating-a-quest.md
@@ -89,7 +89,8 @@ quest is started. This is a good place to put progression details. To
get the progression of a player in a task, write `{TASKID:progress}` and
replace `TASKID` with the ID of the task you want to get the progress
for. Alternatively, you can write `{TASKID:complete}` to get if the task
-is complete.
+is complete. There is also `{TASKID:goal}` returning the progress to be
+reached.
``` yaml
display:
@@ -244,7 +245,8 @@ vaultreward: 600.0
PlaceholderAPI. To get the progression of a player in a task, write
`{TASKID:progress}` and replace `TASKID` with the ID of the task you
want to get the progress for. Alternatively, you can write
-`{TASKID:complete}` to get if the task is complete.
+`{TASKID:complete}` to get if the task is complete. There is also
+`{TASKID:goal}` returning the progress to be reached.
``` yaml
placeholders: