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 39146730a..7c6a5be0a 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 @@ -269,6 +269,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) { List startString = config.getStringList("startstring"); List startCommands = config.getStringList("startcommands"); List cancelCommands = config.getStringList("cancelcommands"); + List expiryCommands = config.getStringList("expirycommands"); boolean repeatable = config.getBoolean("options.repeatable", false); boolean cooldown = config.getBoolean("options.cooldown.enabled", false); boolean timeLimit = config.getBoolean("options.time-limit.enabled", false); @@ -300,6 +301,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) { .withStartString(startString) .withStartCommands(startCommands) .withCancelCommands(cancelCommands) + .withExpiryCommands(expiryCommands) .withPlaceholders(placeholders) .withProgressPlaceholders(progressPlaceholders) .withCooldown(cooldownTime) 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 01cc2788d..47f108b54 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 @@ -329,6 +329,14 @@ public boolean expireQuestForPlayer(QPlayer qPlayer, Quest quest) { Bukkit.getPluginManager().callEvent(questCancelEvent); // PlayerCancelQuestEvent -- end Messages.send(questCancelEvent.getQuestExpireMessage(), player); + for (String s : quest.getExpiryCommands()) { + s = s.replace("{player}", player.getName()); + if (plugin.getConfig().getBoolean("options.quests-use-placeholderapi")) { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), plugin.getPlaceholderAPIProcessor().apply(player, s)); + } else { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), 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 6af3fcf33..3e7fc1930 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 @@ -22,6 +22,7 @@ public class Quest implements Comparable { private List startString; private List startCommands; private List cancelCommands; + private List expiryCommands; private boolean repeatEnabled; private boolean cooldownEnabled; private int cooldown; @@ -172,6 +173,16 @@ public List getCancelCommands() { return Collections.unmodifiableList(cancelCommands); } + /** + * Get the expiry commands for this quest. + * The expiry commands is a list of commands to be executed upon expiring the quest. + * + * @return immutable list of commands + */ + public List getExpiryCommands() { + return Collections.unmodifiableList(expiryCommands); + } + /** * Get if this quest can be repeated after completion. * @@ -306,6 +317,7 @@ public static class Builder { private List startString = Collections.emptyList(); private List startCommands = Collections.emptyList(); private List cancelCommands = Collections.emptyList(); + private List expiryCommands = Collections.emptyList(); private boolean repeatEnabled = false; private boolean cooldownEnabled = false; private int cooldown = 0; @@ -354,6 +366,11 @@ public Builder withCancelCommands(List cancelCommands) { return this; } + public Builder withExpiryCommands(List expiryCommands) { + this.expiryCommands = expiryCommands; + return this; + } + public Builder withSortOrder(int sortOrder) { this.sortOrder = sortOrder; return this; @@ -428,6 +445,7 @@ public Quest build() { quest.startString = this.startString; quest.startCommands = this.startCommands; quest.cancelCommands = this.cancelCommands; + quest.expiryCommands = this.expiryCommands; quest.repeatEnabled = this.repeatEnabled; quest.cooldownEnabled = this.cooldownEnabled; quest.cooldown = this.cooldown; diff --git a/docs/configuration/creating-a-quest.md b/docs/configuration/creating-a-quest.md index 6b47e3e6c..eb9f18504 100644 --- a/docs/configuration/creating-a-quest.md +++ b/docs/configuration/creating-a-quest.md @@ -155,6 +155,20 @@ cancelcommands: - "broadcast {player} has cancelled a quest" ``` +## Expiry commands + + +*`expirycommands`* + +**Optional.** This is a list of commands which will be executed when the +the player's quest expires. You can use `{player}` and the player's name +will be substituted in place. + +``` yaml +expirycommands: + - "broadcast {player}'s quest has expired" +``` + ## Start string