aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2024-06-01 10:52:50 +0200
committerLeonardo Bishop <13875753+LMBishop@users.noreply.github.com>2024-06-03 18:48:22 +0100
commitb67ffadcac3c5c2b019c4bee53f9441fb7913c22 (patch)
tree2aab2b5a493889cf31a4725d8f901d52d2df5712
parent7f44beb0010e16f0f1b2463ee5392ab148f73cd2 (diff)
Add cancelstring and expirystring options
Closes https://github.com/LMBishop/Quests/issues/667
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java4
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java12
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/quest/Quest.java38
-rw-r--r--docs/configuration/creating-a-quest.md26
4 files changed, 78 insertions, 2 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
index 82c2bed8..aa5dc0db 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
@@ -270,6 +270,8 @@ public class BukkitQuestsLoader implements QuestsLoader {
List<String> requirements = config.getStringList("options.requires");
List<String> rewardString = config.getStringList("rewardstring");
List<String> startString = config.getStringList("startstring");
+ List<String> cancelString = config.getStringList("cancelstring");
+ List<String> expiryString = config.getStringList("expirystring");
List<String> startCommands = config.getStringList("startcommands");
List<String> cancelCommands = config.getStringList("cancelcommands");
List<String> expiryCommands = config.getStringList("expirycommands");
@@ -302,6 +304,8 @@ public class BukkitQuestsLoader implements QuestsLoader {
.withRequirements(requirements)
.withRewardString(rewardString)
.withStartString(startString)
+ .withCancelString(cancelString)
+ .withExpiryString(expiryString)
.withStartCommands(startCommands)
.withCancelCommands(cancelCommands)
.withExpiryCommands(expiryCommands)
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java
index 47f108b5..3af12c87 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java
@@ -302,6 +302,12 @@ public class NormalQuestController implements QuestController {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s);
}
}
+ for (String s : quest.getCancelString()) {
+ if (plugin.getConfig().getBoolean("options.quests-use-placeholderapi")) {
+ s = plugin.getPlaceholderAPIProcessor().apply(player, s);
+ }
+ player.sendMessage(Chat.legacyColor(s));
+ }
SoundUtils.playSoundForPlayer(player, plugin.getQuestsConfig().getString("options.sounds.quest-cancel"));
}
if (config.getBoolean("options.allow-quest-track")
@@ -337,6 +343,12 @@ public class NormalQuestController implements QuestController {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), s);
}
}
+ for (String s : quest.getExpiryString()) {
+ if (plugin.getConfig().getBoolean("options.quests-use-placeholderapi")) {
+ s = plugin.getPlaceholderAPIProcessor().apply(player, s);
+ }
+ player.sendMessage(Chat.legacyColor(s));
+ }
}
if (config.getBoolean("options.allow-quest-track")
&& config.getBoolean("options.quest-autotrack")
diff --git a/common/src/main/java/com/leonardobishop/quests/common/quest/Quest.java b/common/src/main/java/com/leonardobishop/quests/common/quest/Quest.java
index 3e7fc193..a3cc26f9 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/quest/Quest.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/quest/Quest.java
@@ -20,6 +20,8 @@ public class Quest implements Comparable<Quest> {
private List<String> requirements;
private List<String> rewardString;
private List<String> startString;
+ private List<String> cancelString;
+ private List<String> expiryString;
private List<String> startCommands;
private List<String> cancelCommands;
private List<String> expiryCommands;
@@ -124,6 +126,26 @@ public class Quest implements Comparable<Quest> {
}
/**
+ * Get the cancel string of the quest.
+ * The cancel string is a series of messages sent to the player upon cancelling the quest.
+ *
+ * @return immutable list of messages to send
+ */
+ public @NotNull List<String> getCancelString() {
+ return Collections.unmodifiableList(cancelString);
+ }
+
+ /**
+ * Get the expiry string of the quest.
+ * The expiry string is a series of messages sent to the player upon expiring the quest.
+ *
+ * @return immutable list of messages to send
+ */
+ public @NotNull List<String> getExpiryString() {
+ return Collections.unmodifiableList(expiryString);
+ }
+
+ /**
* Get the id of this quest.
*
* @return id
@@ -315,6 +337,8 @@ public class Quest implements Comparable<Quest> {
private List<String> requirements = Collections.emptyList();
private List<String> rewardString = Collections.emptyList();
private List<String> startString = Collections.emptyList();
+ private List<String> cancelString = Collections.emptyList();
+ private List<String> expiryString = Collections.emptyList();
private List<String> startCommands = Collections.emptyList();
private List<String> cancelCommands = Collections.emptyList();
private List<String> expiryCommands = Collections.emptyList();
@@ -356,6 +380,16 @@ public class Quest implements Comparable<Quest> {
return this;
}
+ public Builder withCancelString(List<String> cancelString) {
+ this.cancelString = cancelString;
+ return this;
+ }
+
+ public Builder withExpiryString(List<String> expiryString) {
+ this.expiryString = expiryString;
+ return this;
+ }
+
public Builder withStartCommands(List<String> startCommands) {
this.startCommands = startCommands;
return this;
@@ -443,6 +477,8 @@ public class Quest implements Comparable<Quest> {
quest.requirements = this.requirements;
quest.rewardString = this.rewardString;
quest.startString = this.startString;
+ quest.cancelString = this.cancelString;
+ quest.expiryString = this.expiryString;
quest.startCommands = this.startCommands;
quest.cancelCommands = this.cancelCommands;
quest.expiryCommands = this.expiryCommands;
@@ -459,9 +495,7 @@ public class Quest implements Comparable<Quest> {
quest.placeholders = this.placeholders;
quest.progressPlaceholders = this.progressPlaceholders;
quest.categoryid = this.categoryid;
-
return quest;
}
-
}
}
diff --git a/docs/configuration/creating-a-quest.md b/docs/configuration/creating-a-quest.md
index eb9f1850..997a63f6 100644
--- a/docs/configuration/creating-a-quest.md
+++ b/docs/configuration/creating-a-quest.md
@@ -183,6 +183,32 @@ startstring:
- " &8- &7You must break 30 blocks."
```
+## Cancel string
+
+
+*`cancelstring`*
+
+**Optional.** This is a list of messages which will be sent to the
+player when they cancel the quest.
+
+``` yaml
+cancelstring:
+ - " &8- &7You cancelled the quest to break 30 blocks."
+```
+
+## Expiry string
+
+
+*`expirystring`*
+
+**Optional.** This is a list of messages which will be sent to the
+player when their quest has expired.
+
+``` yaml
+expirystring:
+ - " &8- &7The quest to break 30 blocks just expired."
+```
+
## Reward string