mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
FromCondition, FromTrigger&FromExperienceSource implementation.
This commit is contained in:
parent
321838fd34
commit
28556182a3
@ -17,6 +17,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Trigger loadTrigger(MMOLineConfig config) {
|
public Trigger loadTrigger(MMOLineConfig config) {
|
||||||
|
if(config.getKey().equals("from"))
|
||||||
|
return new FromTrigger(config);
|
||||||
|
|
||||||
if (config.getKey().equals("message"))
|
if (config.getKey().equals("message"))
|
||||||
return new MessageTrigger(config);
|
return new MessageTrigger(config);
|
||||||
|
|
||||||
@ -80,6 +83,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Condition loadCondition(MMOLineConfig config) {
|
public Condition loadCondition(MMOLineConfig config) {
|
||||||
|
if(config.getKey().equals("from")) {
|
||||||
|
return new FromCondition(config);
|
||||||
|
}
|
||||||
if (config.getKey().equals("distance"))
|
if (config.getKey().equals("distance"))
|
||||||
return new DistanceCondition(config);
|
return new DistanceCondition(config);
|
||||||
|
|
||||||
@ -100,6 +106,9 @@ public class DefaultMMOLoader extends MMOLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
|
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
|
||||||
|
if(config.getKey().equals("from"))
|
||||||
|
return new FromExperienceSource(dispenser,config);
|
||||||
|
|
||||||
if (config.getKey().equals("resource"))
|
if (config.getKey().equals("resource"))
|
||||||
return new ResourceExperienceSource(dispenser, config);
|
return new ResourceExperienceSource(dispenser, config);
|
||||||
|
|
||||||
|
@ -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<Trigger> triggers = new ArrayList<>();
|
||||||
|
|
||||||
|
public FromTrigger(MMOLineConfig config) {
|
||||||
|
super(config);
|
||||||
|
|
||||||
|
List<String> 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));
|
||||||
|
}
|
||||||
|
}
|
@ -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<ExperienceSource> experienceSources = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public FromExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||||
|
super(dispenser, config);
|
||||||
|
List<String> 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<FromExperienceSource> newManager() {
|
||||||
|
return new ExperienceSourceManager<FromExperienceSource>() {
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package net.Indyuce.mmocore.experience.source.type;
|
package net.Indyuce.mmocore.experience.source.type;
|
||||||
|
|
||||||
|
import io.lumine.mythic.core.drops.droppables.ExperienceDrop;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
|
||||||
import net.Indyuce.mmocore.experience.EXPSource;
|
import net.Indyuce.mmocore.experience.EXPSource;
|
||||||
@ -24,6 +25,17 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
|
|||||||
amount = new RandomAmount(config.getString("amount"));
|
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() {
|
public RandomAmount getAmount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
@ -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<Condition> conditions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public FromCondition(MMOLineConfig config) {
|
||||||
|
super(config);
|
||||||
|
List<String> 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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user