From 75a4b944b6e8db2b432623cab91b334e3900abaa Mon Sep 17 00:00:00 2001 From: Indyuce Date: Mon, 23 May 2022 11:29:45 +0200 Subject: [PATCH] Quest module fix --- .../Indyuce/mmocore/quest/AbstractQuest.java | 1 + .../mmocore/quest/QuestModuleType.java | 11 +++----- ...estModule.java => BeautyQuestsModule.java} | 15 +++++------ .../quest/compat/BlackVeinQuestsModule.java | 14 +++-------- .../quest/compat/QuestCreatorModule.java | 25 ++++++++++--------- .../mmocore/quest/compat/QuestModule.java | 5 ++-- 6 files changed, 30 insertions(+), 41 deletions(-) rename src/main/java/net/Indyuce/mmocore/quest/compat/{BeautyQuestModule.java => BeautyQuestsModule.java} (65%) diff --git a/src/main/java/net/Indyuce/mmocore/quest/AbstractQuest.java b/src/main/java/net/Indyuce/mmocore/quest/AbstractQuest.java index 075ae470..93316ec2 100644 --- a/src/main/java/net/Indyuce/mmocore/quest/AbstractQuest.java +++ b/src/main/java/net/Indyuce/mmocore/quest/AbstractQuest.java @@ -3,5 +3,6 @@ package net.Indyuce.mmocore.quest; public interface AbstractQuest { public String getName(); + public String getId(); } diff --git a/src/main/java/net/Indyuce/mmocore/quest/QuestModuleType.java b/src/main/java/net/Indyuce/mmocore/quest/QuestModuleType.java index 7bcd4bfa..4c7e0366 100644 --- a/src/main/java/net/Indyuce/mmocore/quest/QuestModuleType.java +++ b/src/main/java/net/Indyuce/mmocore/quest/QuestModuleType.java @@ -1,7 +1,6 @@ package net.Indyuce.mmocore.quest; -import net.Indyuce.mmocore.party.PartyModule; -import net.Indyuce.mmocore.quest.compat.BeautyQuestModule; +import net.Indyuce.mmocore.quest.compat.BeautyQuestsModule; import net.Indyuce.mmocore.quest.compat.BlackVeinQuestsModule; import net.Indyuce.mmocore.quest.compat.QuestCreatorModule; import net.Indyuce.mmocore.quest.compat.QuestModule; @@ -10,12 +9,10 @@ import org.bukkit.Bukkit; import javax.inject.Provider; public enum QuestModuleType { - MMOCORE("MMOCore",MMOCoreQuestModule::new), + MMOCORE("MMOCore", MMOCoreQuestModule::new), QUESTS("Quests", BlackVeinQuestsModule::new), - BEAUTY_QUEST("Beauty Quests", BeautyQuestModule::new), - QUEST_CREATOR("Quest Creator", QuestCreatorModule::new); - - + BEAUTY_QUEST("BeautyQuests", BeautyQuestsModule::new), + QUEST_CREATOR("QuestCreator", QuestCreatorModule::new); private final String pluginName; private final Provider provider; diff --git a/src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestModule.java b/src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestsModule.java similarity index 65% rename from src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestModule.java rename to src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestsModule.java index e1e4f720..b060cad3 100644 --- a/src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestModule.java +++ b/src/main/java/net/Indyuce/mmocore/quest/compat/BeautyQuestsModule.java @@ -8,24 +8,21 @@ import fr.skytasul.quests.structure.Quest; import net.Indyuce.mmocore.quest.AbstractQuest; import org.bukkit.entity.Player; -public class BeautyQuestModule implements QuestModule { - +public class BeautyQuestsModule implements QuestModule { @Override public BeautyQuestQuest getQuestOrThrow(String questId) { - Quest quest=QuestsAPI.getQuests().getQuest(Integer.parseInt(questId)); - return quest==null?null:new BeautyQuestQuest(quest); + Quest quest = QuestsAPI.getQuests().getQuest(Integer.parseInt(questId)); + return quest == null ? null : new BeautyQuestQuest(quest); } @Override public boolean hasCompletedQuest(String questId, Player player) { - PlayerAccount account=PlayersManager.getPlayerAccount(player); - PlayerQuestDatas quest=account.getQuestDatas(QuestsAPI.getQuests().getQuest(Integer.parseInt(questId))); + PlayerAccount account = PlayersManager.getPlayerAccount(player); + PlayerQuestDatas quest = account.getQuestDatas(QuestsAPI.getQuests().getQuest(Integer.parseInt(questId))); return quest.isFinished(); } - - public class BeautyQuestQuest implements AbstractQuest { Quest quest; @@ -41,7 +38,7 @@ public class BeautyQuestModule implements QuestModule { private final Quests plugin = (Quests) Bukkit.getPluginManager().getPlugin("Quests"); - - @Override public BlackVeinQuestQuest getQuestOrThrow(String id) { Quests plugin = (Quests) Bukkit.getPluginManager().getPlugin("Quests"); - return plugin.getQuestById(id)==null?null:new BlackVeinQuestQuest(plugin.getQuestById(id)); + return plugin.getQuestById(id) == null ? null : new BlackVeinQuestQuest(plugin.getQuestById(id)); } - @Override public boolean hasCompletedQuest(String questId, Player player) { Quester quester = plugin.getQuester(player.getUniqueId()); - for(Quest quest:quester.getCompletedQuests()) { - if(quest.getId().equals(questId)) + for (Quest quest : quester.getCompletedQuests()) + if (quest.getId().equals(questId)) return true; - } + return false; } - public class BlackVeinQuestQuest implements AbstractQuest { private final Quest quest; @@ -49,5 +44,4 @@ public class BlackVeinQuestsModule implements QuestModule{ +public class QuestCreatorModule implements QuestModule { @Override public QuestCreatorQuest getQuestOrThrow(String id) { @@ -20,27 +21,27 @@ public class QuestCreatorModule implements QuestModule elements=playerData.getQuestHistory().getElements(questId, Arrays.asList(QuestEndType.SUCCESS),0); - for(QuestHistoryElement el:elements) { - if(el.getModelId().equals(questId)) + UserQC playerData = UserQC.cachedOrNull(player); + Validate.notNull(playerData, "QuestCreator User hasn't been loaded!"); + + // Gets all the quests the player has succeeded at + List elements = playerData.getQuestHistory().getElements(questId, Arrays.asList(QuestEndType.SUCCESS), 0); + for (QuestHistoryElement el : elements) + if (el.getModelId().equals(questId)) return true; - } + return false; } - /** - *QC ElementModel corresponds to our quest and their quests correspond to our Quest progress class + * QC ElementModel corresponds to our quest and their + * quests correspond to our Quest progress class */ - public class QuestCreatorQuest implements AbstractQuest { ElementModel questModel; public QuestCreatorQuest(String modelId) { - questModel=ConfigQC.models.getElement(modelId).orNull(); + questModel = ConfigQC.models.getElement(modelId).orNull(); } @Override diff --git a/src/main/java/net/Indyuce/mmocore/quest/compat/QuestModule.java b/src/main/java/net/Indyuce/mmocore/quest/compat/QuestModule.java index d4cae6b4..d569db22 100644 --- a/src/main/java/net/Indyuce/mmocore/quest/compat/QuestModule.java +++ b/src/main/java/net/Indyuce/mmocore/quest/compat/QuestModule.java @@ -6,13 +6,12 @@ import org.bukkit.entity.Player; public interface QuestModule { /** - * @return Quest with given name + * @return Quest with given identifier */ public T getQuestOrThrow(String id); /** - * @return If a specific player did a certain quest + * @return If a specific player has made a certain quest */ public boolean hasCompletedQuest(String quest, Player player); - }