diff options
| -rw-r--r-- | pom.xml | 15 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/Quests.java | 5 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/api/QuestsPlaceholders.java | 122 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java | 2 | ||||
| -rw-r--r-- | src/main/resources/plugin.yml | 2 |
5 files changed, 144 insertions, 2 deletions
@@ -49,6 +49,12 @@ <id>mythicmobs</id> <url>http://mc.hackerzlair.org:8888/repository/public</url> </repository> + + <!-- PlaceholderAPI --> + <repository> + <id>placeholderapi</id> + <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url> + </repository> </repositories> <dependencies> @@ -93,6 +99,15 @@ <type>jar</type> <scope>provided</scope> </dependency> + + <!-- PlaceholderAPI --> + <dependency> + <groupId>me.clip</groupId> + <artifactId>placeholderapi</artifactId> + <version>2.10.4</version> + <type>jar</type> + <scope>provided</scope> + </dependency> </dependencies> <build> 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(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 23abf62f..df2ef44b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ version: %PLUGIN_VERSION% main: com.leonardobishop.quests.Quests author: LMBishop -softdepend: [ASkyBlock, uSkyBlock, Citizens] +softdepend: [ASkyBlock, uSkyBlock, Citizens, PlaceholderAPI] prefix: Quests api-version: 1.14 |
