aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authornicuch <nicuch100@gmail.com>2020-01-12 21:11:10 +0200
committernicuch <nicuch100@gmail.com>2020-01-12 21:11:10 +0200
commitf7231b64f069dd810fcc32eb4a3a3f9cb20012b1 (patch)
tree6e8c0220970d4588ebf38749196f75daacc06728 /src/main/java
parent8600578d9aa4e20dab6c9d588e218f33f5dc82b1 (diff)
Added PlaceholderAPI support
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/leonardobishop/quests/Quests.java5
-rw-r--r--src/main/java/com/leonardobishop/quests/api/QuestsPlaceholders.java122
-rw-r--r--src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java2
3 files changed, 128 insertions, 1 deletions
diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java
index d99b2a87..13c7aca6 100644
--- a/src/main/java/com/leonardobishop/quests/Quests.java
+++ b/src/main/java/com/leonardobishop/quests/Quests.java
@@ -1,5 +1,6 @@
package com.leonardobishop.quests;
+import com.leonardobishop.quests.api.QuestsPlaceholders;
import com.leonardobishop.quests.bstats.Metrics;
import com.leonardobishop.quests.commands.CommandQuests;
import com.leonardobishop.quests.events.EventInventory;
@@ -108,6 +109,10 @@ public class Quests extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new EventInventory(this), this);
Bukkit.getPluginManager().registerEvents(new EventPlayerLeave(this), this);
+ if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
+ new QuestsPlaceholders(this).register();
+ }
+
Metrics metrics = new Metrics(this);
if (metrics.isEnabled()) {
this.getLogger().log(Level.INFO, "Metrics started. This can be disabled at /plugins/bStats/config.yml.");
diff --git a/src/main/java/com/leonardobishop/quests/api/QuestsPlaceholders.java b/src/main/java/com/leonardobishop/quests/api/QuestsPlaceholders.java
new file mode 100644
index 00000000..741c2008
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/api/QuestsPlaceholders.java
@@ -0,0 +1,122 @@
+package com.leonardobishop.quests.api;
+
+import com.leonardobishop.quests.Quests;
+import com.leonardobishop.quests.api.enums.QuestStartResult;
+import com.leonardobishop.quests.player.QPlayer;
+import com.leonardobishop.quests.quests.Quest;
+import me.clip.placeholderapi.expansion.PlaceholderExpansion;
+import org.bukkit.entity.Player;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class QuestsPlaceholders extends PlaceholderExpansion {
+ private final Quests plugin;
+
+ public QuestsPlaceholders(Quests plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return "quests";
+ }
+
+ @Override
+ public String getAuthor() {
+ return this.plugin.getDescription().getAuthors().toString();
+ }
+
+ @Override
+ public String getVersion() {
+ return this.plugin.getDescription().getVersion();
+ }
+
+ @Override
+ public String onPlaceholderRequest(Player player, String identifier) {
+ if (player == null)
+ return "";
+ QPlayer questPlayer = this.plugin.getPlayerManager().getPlayer(player.getUniqueId());
+ if (identifier.equals("current_quest_amount")) {
+ return String.valueOf(questPlayer.getQuestProgressFile().getStartedQuests().size());
+ }
+ if (identifier.equals("current_quest_names")) {
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ List<String> list = new ArrayList<>();
+ for (Quest currentQuests : questPlayer.getQuestProgressFile().getStartedQuests()) {
+ list.add(currentQuests.getDisplayNameStripped());
+ }
+ Collections.sort(list);
+ for (String questName : list) {
+ if (!first) {
+ sb.append("\n");
+ }
+ first = false;
+ sb.append(questName);
+ }
+ return sb.toString();
+ }
+ if (identifier.startsWith("has_current_quest_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ for (Quest currentQuests : questPlayer.getQuestProgressFile().getStartedQuests()) {
+ if (currentQuests.getId().equals(questId)) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+ if (identifier.startsWith("has_completed_quest_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ Quest quest = this.plugin.getQuestManager().getQuestById(questId);
+ if (quest != null) {
+ if (questPlayer.getQuestProgressFile().getQuestProgress(quest).isCompleted())
+ return "true";
+ }
+ return "false";
+ }
+ if (identifier.startsWith("has_completed_before_quest_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ Quest quest = this.plugin.getQuestManager().getQuestById(questId);
+ if (quest != null) {
+ if (questPlayer.getQuestProgressFile().getQuestProgress(quest).isCompletedBefore()) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+ if (identifier.startsWith("cooldown_time_remaining_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ Quest quest = this.plugin.getQuestManager().getQuestById(questId);
+ if (quest != null) {
+ if (questPlayer.getQuestProgressFile().getQuestProgress(quest).isCompleted()) {
+ return this.plugin.convertToFormat(TimeUnit.SECONDS.convert(questPlayer.getQuestProgressFile().getCooldownFor(quest), TimeUnit.MILLISECONDS));
+ }
+ }
+ return this.plugin.convertToFormat(0);
+ }
+ if (identifier.startsWith("can_accept_quest_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ Quest quest = this.plugin.getQuestManager().getQuestById(questId);
+ if (quest != null) {
+ if (questPlayer.getQuestProgressFile().canStartQuest(quest) == QuestStartResult.QUEST_SUCCESS) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+ if (identifier.startsWith("meets_requirements_")) {
+ String questId = identifier.substring(identifier.lastIndexOf("_") + 1);
+ Quest quest = this.plugin.getQuestManager().getQuestById(questId);
+ if (quest != null) {
+ if (questPlayer.getQuestProgressFile().hasMetRequirements(quest)) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+ return "";
+ }
+}
diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
index 743a3dbc..b090e7e3 100644
--- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
+++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java
@@ -147,7 +147,7 @@ public class QuestProgressFile {
case QUEST_COOLDOWN:
long cooldown = getCooldownFor(quest);
questResultMessage = Messages.QUEST_START_COOLDOWN.getMessage().replace("{time}", String.valueOf(plugin.convertToFormat(TimeUnit.SECONDS.convert
- (cooldown, TimeUnit.MINUTES))));
+ (cooldown, TimeUnit.MILLISECONDS))));
break;
case QUEST_LOCKED:
questResultMessage = Messages.QUEST_START_LOCKED.getMessage();