Skip to content

Commit

Permalink
Add expiry commands option
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied authored and LMBishop committed Feb 22, 2024
1 parent 16794d9 commit 52ded1a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
List<String> startString = config.getStringList("startstring");
List<String> startCommands = config.getStringList("startcommands");
List<String> cancelCommands = config.getStringList("cancelcommands");
List<String> 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);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Quest implements Comparable<Quest> {
private List<String> startString;
private List<String> startCommands;
private List<String> cancelCommands;
private List<String> expiryCommands;
private boolean repeatEnabled;
private boolean cooldownEnabled;
private int cooldown;
Expand Down Expand Up @@ -172,6 +173,16 @@ public List<String> 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<String> getExpiryCommands() {
return Collections.unmodifiableList(expiryCommands);
}

/**
* Get if this quest can be repeated after completion.
*
Expand Down Expand Up @@ -306,6 +317,7 @@ public static class Builder {
private List<String> startString = Collections.emptyList();
private List<String> startCommands = Collections.emptyList();
private List<String> cancelCommands = Collections.emptyList();
private List<String> expiryCommands = Collections.emptyList();
private boolean repeatEnabled = false;
private boolean cooldownEnabled = false;
private int cooldown = 0;
Expand Down Expand Up @@ -354,6 +366,11 @@ public Builder withCancelCommands(List<String> cancelCommands) {
return this;
}

public Builder withExpiryCommands(List<String> expiryCommands) {
this.expiryCommands = expiryCommands;
return this;
}

public Builder withSortOrder(int sortOrder) {
this.sortOrder = sortOrder;
return this;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration/creating-a-quest.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 52ded1a

Please sign in to comment.