Modules for Quests in MMOCore.

This commit is contained in:
Guillaume 2022-05-22 14:15:13 +02:00
parent 68b309ec61
commit a2630824c9
11 changed files with 301 additions and 16 deletions

27
pom.xml
View File

@ -226,6 +226,33 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!--Quest Plugin-->
<dependency>
<groupId>me.blackvein</groupId>
<artifactId>Quests</artifactId>
<version>4.4.1-b340</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fr.skytasul.quests</groupId>
<artifactId>BeautyQuests</artifactId>
<version>0.19.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.guillaumevdn</groupId>
<artifactId>QuestCreator</artifactId>
<version>6.39.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.guillaumevdn</groupId>
<artifactId>GCore</artifactId>
<version>8.39.0</version>
<scope>provided</scope>
</dependency>
<!-- Guild plugins --> <!-- Guild plugins -->
<dependency> <dependency>
<groupId>com.massivecraft</groupId> <groupId>com.massivecraft</groupId>

View File

@ -230,6 +230,19 @@ public class MMOCore extends LuminePlugin {
DebugMode.enableActionBar(); DebugMode.enableActionBar();
} }
// Load quest module
try {
String questPluginName = UtilityMethods.enumName(getConfig().getString("quest-plugin"));
PartyModuleType moduleType = PartyModuleType.valueOf(questPluginName);
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
partyModule = moduleType.provideModule();
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not initialize quest module: " + exception.getMessage());
partyModule = new MMOCorePartyModule();
}
// Load party module // Load party module
try { try {
String partyPluginName = UtilityMethods.enumName(getConfig().getString("party-plugin")); String partyPluginName = UtilityMethods.enumName(getConfig().getString("party-plugin"));
@ -241,6 +254,7 @@ public class MMOCore extends LuminePlugin {
partyModule = new MMOCorePartyModule(); partyModule = new MMOCorePartyModule();
} }
// Skill casting // Skill casting
try { try {
SkillCastingMode mode = SkillCastingMode.valueOf(UtilityMethods.enumName(getConfig().getString("skill-casting.mode"))); SkillCastingMode mode = SkillCastingMode.valueOf(UtilityMethods.enumName(getConfig().getString("skill-casting.mode")));

View File

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

View File

@ -0,0 +1,40 @@
package net.Indyuce.mmocore.quest;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.quest.Quest;
import net.Indyuce.mmocore.quest.compat.QuestModule;
import org.bukkit.entity.Player;
public class MMOCoreQuestModule implements QuestModule {
@Override
public AbstractQuest getQuestOrThrow(String id) {
Quest quest=MMOCore.plugin.questManager.get(id);
if(quest==null)
return null;
return new MMOCoreQuest(quest);
}
@Override
public boolean hasCompletedQuest(String quest, Player player) {
return false;
}
public class MMOCoreQuest implements AbstractQuest {
Quest quest;
public MMOCoreQuest(Quest quest) {
this.quest = quest;
}
@Override
public String getName() {
return null;
}
@Override
public String getId() {
return null;
}
}
}

View File

@ -1,16 +0,0 @@
package net.Indyuce.mmocore.quest;
import net.Indyuce.mmocore.api.player.PlayerData;
public interface QuestModule<T extends AbstractQuest, U extends PlayerQuestData<T>> {
/**
* @return Quest with given name
*/
public T getQuestOrThrow(String id);
/**
* @return Info about the completed quests from a specific player
*/
public U getQuestData(PlayerData playerData);
}

View File

@ -0,0 +1,35 @@
package net.Indyuce.mmocore.quest;
import net.Indyuce.mmocore.party.PartyModule;
import net.Indyuce.mmocore.quest.compat.BeautyQuestModule;
import net.Indyuce.mmocore.quest.compat.BlackVeinQuestsModule;
import net.Indyuce.mmocore.quest.compat.QuestCreatorModule;
import net.Indyuce.mmocore.quest.compat.QuestModule;
import org.bukkit.Bukkit;
import javax.inject.Provider;
public enum QuestModuleType {
MMOCORE("MMOCore",MMOCoreQuestModule::new),
QUESTS("Quests", BlackVeinQuestsModule::new),
BEAUTY_QUEST("Beauty Quests", BeautyQuestModule::new),
QUEST_CREATOR("Quest Creator", QuestCreatorModule::new);
private final String pluginName;
private final Provider<QuestModule> provider;
QuestModuleType(String pluginName, Provider<QuestModule> provider) {
this.pluginName = pluginName;
this.provider = provider;
}
public boolean isValid() {
return Bukkit.getPluginManager().getPlugin(pluginName) != null;
}
public QuestModule provideModule() {
return provider.get();
}
}

View File

@ -0,0 +1,47 @@
package net.Indyuce.mmocore.quest.compat;
import fr.skytasul.quests.api.QuestsAPI;
import fr.skytasul.quests.players.PlayerAccount;
import fr.skytasul.quests.players.PlayerQuestDatas;
import fr.skytasul.quests.players.PlayersManager;
import fr.skytasul.quests.structure.Quest;
import net.Indyuce.mmocore.quest.AbstractQuest;
import org.bukkit.entity.Player;
public class BeautyQuestModule implements QuestModule<BeautyQuestModule.BeautyQuestQuest> {
@Override
public BeautyQuestQuest getQuestOrThrow(String questId) {
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)));
return quest.isFinished();
}
public class BeautyQuestQuest implements AbstractQuest {
Quest quest;
public BeautyQuestQuest(Quest quest) {
this.quest = quest;
}
@Override
public String getName() {
return quest.getName();
}
@Override
public String getId() {
return ""+quest.getID();
}
}
}

View File

@ -0,0 +1,53 @@
package net.Indyuce.mmocore.quest.compat;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
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));
}
@Override
public boolean hasCompletedQuest(String questId, Player player) {
Quester quester = plugin.getQuester(player.getUniqueId());
for(Quest quest:quester.getCompletedQuests()) {
if(quest.getId().equals(questId))
return true;
}
return false;
}
public class BlackVeinQuestQuest implements AbstractQuest {
private final Quest quest;
public BlackVeinQuestQuest(Quest quest) {
this.quest = quest;
}
@Override
public String getName() {
return quest.getName();
}
@Override
public String getId() {
return quest.getId();
}
}
}

View File

@ -0,0 +1,56 @@
package net.Indyuce.mmocore.quest.compat;
import com.guillaumevdn.questcreator.ConfigQC;
import com.guillaumevdn.questcreator.data.user.QuestHistoryElement;
import com.guillaumevdn.questcreator.data.user.UserQC;
import com.guillaumevdn.questcreator.lib.model.ElementModel;
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>{
@Override
public QuestCreatorQuest getQuestOrThrow(String id) {
return new QuestCreatorQuest(id);
}
@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))
return true;
}
return false;
}
/**
*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();
}
@Override
public String getName() {
return questModel.getDisplayName().getId();
}
@Override
public String getId() {
return questModel.getId();
}
}
}

View File

@ -0,0 +1,18 @@
package net.Indyuce.mmocore.quest.compat;
import net.Indyuce.mmocore.quest.AbstractQuest;
import org.bukkit.entity.Player;
public interface QuestModule<T extends AbstractQuest> {
/**
* @return Quest with given name
*/
public T getQuestOrThrow(String id);
/**
* @return If a specific player did a certain quest
*/
public boolean hasCompletedQuest(String quest, Player player);
}

View File

@ -58,6 +58,16 @@ protect-custom-mine: false
# - parties_and_friends # - parties_and_friends
party-plugin: mmocore party-plugin: mmocore
## Edit the plugin handling parties here.
## Supported values (just copy and paste):
## - mmocore
## - beauty_quest
## - quest_creator
## - quests
quest-plugin: mmocore
# Whether blocks generated with a "cobblegenerator" should # Whether blocks generated with a "cobblegenerator" should
# provide the player with experience points or not # provide the player with experience points or not
should-cobblestone-generators-give-exp: false should-cobblestone-generators-give-exp: false