diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 7f6cbbd5..7434ad21 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -17,6 +17,9 @@ public class DefaultMMOLoader extends MMOLoader { @Override public Trigger loadTrigger(MMOLineConfig config) { + if(config.getKey().equals("from")) + return new FromTrigger(config); + if (config.getKey().equals("message")) return new MessageTrigger(config); @@ -80,6 +83,9 @@ public class DefaultMMOLoader extends MMOLoader { @Override public Condition loadCondition(MMOLineConfig config) { + if(config.getKey().equals("from")) { + return new FromCondition(config); + } if (config.getKey().equals("distance")) return new DistanceCondition(config); @@ -100,6 +106,9 @@ public class DefaultMMOLoader extends MMOLoader { @Override public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + if(config.getKey().equals("from")) + return new FromExperienceSource(dispenser,config); + if (config.getKey().equals("resource")) return new ResourceExperienceSource(dispenser, config); diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/FromTrigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/FromTrigger.java new file mode 100644 index 00000000..de5813c7 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/FromTrigger.java @@ -0,0 +1,35 @@ +package net.Indyuce.mmocore.api.quest.trigger; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.ConfigFile; +import net.Indyuce.mmocore.api.player.PlayerData; +import org.apache.commons.lang.Validate; + +import java.util.ArrayList; +import java.util.List; + +public class FromTrigger extends Trigger { + private final List triggers = new ArrayList<>(); + + public FromTrigger(MMOLineConfig config) { + super(config); + + List list = new ConfigFile("triggers") + .getConfig().getStringList(config.getString("source")); + Validate.isTrue(list.size() != 0, "There is no source matching " + config.getString("key")); + list.stream() + .map(MMOLineConfig::new) + .forEach(mmoLineConfig -> + triggers.add(MMOCore.plugin.loadManager.loadTrigger(mmoLineConfig))); + + } + + /** + * Applies the effect of all the children triggers defined in triggers.yml. + */ + @Override + public void apply(PlayerData player) { + triggers.forEach(trigger -> trigger.apply(player)); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/FromExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/FromExperienceSource.java new file mode 100644 index 00000000..be513a41 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/experience/source/FromExperienceSource.java @@ -0,0 +1,55 @@ +package net.Indyuce.mmocore.experience.source; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.ConfigFile; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; +import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; +import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.ConfigurationSection; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class FromExperienceSource extends SpecificExperienceSource { + /** + * Register all the children experience sources defined in experience-source.yml. + */ + private final ArrayList experienceSources = new ArrayList<>(); + + + public FromExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { + super(dispenser, config); + List list = new ConfigFile("exp-sources") + .getConfig().getStringList(config.getString("source")); + Validate.isTrue(list.size() != 0, "There is no source matching " + config.getString("key")); + list.stream() + .map(MMOLineConfig::new) + .forEach(mmoLineConfig -> + experienceSources.add(MMOCore.plugin.loadManager.loadExperienceSource(mmoLineConfig, dispenser))); + + + } + + @Override + public ExperienceSourceManager newManager() { + return new ExperienceSourceManager() { + /** + * Used to register all the children experience sources. + */ + @Override + public void registerSource(FromExperienceSource source) { + source.experienceSources.forEach(expSource -> MMOCore.plugin.experience.registerSource(expSource)); + } + }; + } + + @Override + public boolean matchesParameter(PlayerData player, Object obj) { + return false; + } +} diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java index e877be29..cd3c7d66 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.experience.source.type; +import io.lumine.mythic.core.drops.droppables.ExperienceDrop; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import net.Indyuce.mmocore.experience.EXPSource; @@ -24,6 +25,17 @@ public abstract class SpecificExperienceSource extends ExperienceSource { amount = new RandomAmount(config.getString("amount")); } + + /** + * Used for FromExperienceSource + * @param dispenser + */ + public SpecificExperienceSource(ExperienceDispenser dispenser) { + super(dispenser); + amount=new RandomAmount(0,0); + } + + public RandomAmount getAmount() { return amount; } diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/condition/FromCondition.java b/src/main/java/net/Indyuce/mmocore/loot/chest/condition/FromCondition.java new file mode 100644 index 00000000..972c0f05 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/condition/FromCondition.java @@ -0,0 +1,32 @@ +package net.Indyuce.mmocore.loot.chest.condition; + +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.ConfigFile; +import org.apache.commons.lang.Validate; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class FromCondition extends Condition { + private final List conditions = new ArrayList<>(); + + + public FromCondition(MMOLineConfig config) { + super(config); + List list = new ConfigFile("conditions") + .getConfig().getStringList(config.getString("source")); + Validate.isTrue(list.size() != 0, "There is no source matching " + config.getString("key")); + list.stream() + .map(MMOLineConfig::new) + .forEach(mmoLineConfig -> + conditions.add(MMOCore.plugin.loadManager.loadCondition(mmoLineConfig))); + } + + + @Override + public boolean isMet(ConditionInstance entity) { + return conditions.stream().allMatch(condition -> condition.isMet(entity)); + } +}