From b67ffadcac3c5c2b019c4bee53f9441fb7913c22 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Sat, 1 Jun 2024 10:52:50 +0200 Subject: Add cancelstring and expirystring options Closes https://github.com/LMBishop/Quests/issues/667 --- .../quests/bukkit/config/BukkitQuestsLoader.java | 4 +++ .../questcontroller/NormalQuestController.java | 12 +++++++ .../leonardobishop/quests/common/quest/Quest.java | 38 ++++++++++++++++++++-- docs/configuration/creating-a-quest.md | 26 +++++++++++++++ 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 requirements = config.getStringList("options.requires"); List rewardString = config.getStringList("rewardstring"); List startString = config.getStringList("startstring"); + List cancelString = config.getStringList("cancelstring"); + List expiryString = config.getStringList("expirystring"); List startCommands = config.getStringList("startcommands"); List cancelCommands = config.getStringList("cancelcommands"); List 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 { private List requirements; private List rewardString; private List startString; + private List cancelString; + private List expiryString; private List startCommands; private List cancelCommands; private List expiryCommands; @@ -123,6 +125,26 @@ public class Quest implements Comparable { return Collections.unmodifiableList(startString); } + /** + * 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 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 getExpiryString() { + return Collections.unmodifiableList(expiryString); + } + /** * Get the id of this quest. * @@ -315,6 +337,8 @@ public class Quest implements Comparable { private List requirements = Collections.emptyList(); private List rewardString = Collections.emptyList(); private List startString = Collections.emptyList(); + private List cancelString = Collections.emptyList(); + private List expiryString = Collections.emptyList(); private List startCommands = Collections.emptyList(); private List cancelCommands = Collections.emptyList(); private List expiryCommands = Collections.emptyList(); @@ -356,6 +380,16 @@ public class Quest implements Comparable { return this; } + public Builder withCancelString(List cancelString) { + this.cancelString = cancelString; + return this; + } + + public Builder withExpiryString(List expiryString) { + this.expiryString = expiryString; + return this; + } + public Builder withStartCommands(List startCommands) { this.startCommands = startCommands; return this; @@ -443,6 +477,8 @@ public class Quest implements Comparable { 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.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 -- cgit v1.2.3-70-g09d2