Quest module fix

This commit is contained in:
Indyuce 2022-05-23 11:29:45 +02:00
parent 758caf747d
commit 75a4b944b6
6 changed files with 30 additions and 41 deletions

View File

@ -3,5 +3,6 @@ package net.Indyuce.mmocore.quest;
public interface AbstractQuest {
public String getName();
public String getId();
}

View File

@ -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<QuestModule> provider;

View File

@ -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<BeautyQuestModule.BeautyQuestQuest> {
public class BeautyQuestsModule implements QuestModule<BeautyQuestsModule.BeautyQuestQuest> {
@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<BeautyQuestModule.BeautyQu
@Override
public String getId() {
return ""+quest.getID();
return String.valueOf(quest.getID());
}
}
}

View File

@ -7,31 +7,26 @@ import net.Indyuce.mmocore.quest.AbstractQuest;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class BlackVeinQuestsModule implements QuestModule<BlackVeinQuestsModule.BlackVeinQuestQuest> {
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<BlackVeinQuestsModule.
return quest.getId();
}
}
}

View File

@ -8,10 +8,11 @@ import com.guillaumevdn.questcreator.lib.quest.QuestEndType;
import net.Indyuce.mmocore.quest.AbstractQuest;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
public class QuestCreatorModule implements QuestModule<QuestCreatorModule.QuestCreatorQuest>{
public class QuestCreatorModule implements QuestModule<QuestCreatorModule.QuestCreatorQuest> {
@Override
public QuestCreatorQuest getQuestOrThrow(String id) {
@ -20,27 +21,27 @@ public class QuestCreatorModule implements QuestModule<QuestCreatorModule.QuestC
@Override
public boolean hasCompletedQuest(String questId, Player player) {
UserQC playerData=UserQC.cachedOrNull(player);
Validate.notNull(playerData,"QuestCreator User hasn't been loaded!");
//Gets all the quests the player has succeeded at
List<QuestHistoryElement> 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<QuestHistoryElement> 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

View File

@ -6,13 +6,12 @@ import org.bukkit.entity.Player;
public interface QuestModule<T extends AbstractQuest> {
/**
* @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);
}