Fixed MMOloaders

This commit is contained in:
Indyuce 2022-07-29 17:08:02 +02:00
parent 83ab7ef523
commit b38fda4aa7
18 changed files with 138 additions and 231 deletions

View File

@ -52,7 +52,7 @@ public class BlockInfo {
for (String key : list) for (String key : list)
try { try {
triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + key + "' from block info '" + block.generateKey() + "': " + exception.getMessage()); "Could not load trigger '" + key + "' from block info '" + block.generateKey() + "': " + exception.getMessage());

View File

@ -1,85 +1,45 @@
package net.Indyuce.mmocore.api.load; package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.MMOCore; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.SkullBlockType;
import net.Indyuce.mmocore.api.block.VanillaBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType;
import net.Indyuce.mmocore.api.quest.objective.*;
import net.Indyuce.mmocore.api.quest.trigger.*;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.*; import net.Indyuce.mmocore.experience.source.*;
import net.Indyuce.mmocore.loot.chest.condition.*;
import org.apache.commons.math3.analysis.function.Exp;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.quest.objective.ClickonObjective; import net.Indyuce.mmocore.loot.chest.condition.*;
import net.Indyuce.mmocore.api.quest.objective.GoToObjective; import net.Indyuce.mmocore.loot.droptable.dropitem.*;
import net.Indyuce.mmocore.api.quest.objective.KillMobObjective; import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.quest.objective.MineBlockObjective;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.CommandTrigger;
import net.Indyuce.mmocore.api.quest.trigger.ExperienceTrigger;
import net.Indyuce.mmocore.api.quest.trigger.ItemTrigger;
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger;
import net.Indyuce.mmocore.api.quest.trigger.MessageTrigger;
import net.Indyuce.mmocore.api.quest.trigger.SoundTrigger;
import net.Indyuce.mmocore.api.quest.trigger.StaminaTrigger;
import net.Indyuce.mmocore.api.quest.trigger.StelliumTrigger;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.checkerframework.checker.units.qual.C;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
public class DefaultMMOLoader extends MMOLoader { public class DefaultMMOLoader extends MMOLoader {
@Override @Override
public List<Trigger> loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
if (config.getKey().equals("from")) {
String source = config.getString("source");
ConfigFile configFile = new ConfigFile("triggers");
if (!configFile.getConfig().contains(source)) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't find " + source + " in experience-sources.yml");
return null;
}
List<Trigger> list = new ArrayList<>();
for (String trigger : configFile.getConfig().getStringList(source)) {
list.addAll(loadTrigger(new MMOLineConfig(trigger)));
}
return list;
}
if (config.getKey().equals("message")) if (config.getKey().equals("message"))
return Arrays.asList(new MessageTrigger(config)); return new MessageTrigger(config);
if (config.getKey().equals("sound") || config.getKey().equals("playsound")) if (config.getKey().equals("sound") || config.getKey().equals("playsound"))
return Arrays.asList(new SoundTrigger(config)); return new SoundTrigger(config);
if (config.getKey().equals("mana")) if (config.getKey().equals("mana"))
return Arrays.asList(new ManaTrigger(config)); return new ManaTrigger(config);
if (config.getKey().equals("stamina")) if (config.getKey().equals("stamina"))
return Arrays.asList(new StaminaTrigger(config)); return new StaminaTrigger(config);
if (config.getKey().equals("stellium")) if (config.getKey().equals("stellium"))
return Arrays.asList(new StelliumTrigger(config)); return new StelliumTrigger(config);
if (config.getKey().equals("command")) if (config.getKey().equals("command"))
return Arrays.asList(new CommandTrigger(config)); return new CommandTrigger(config);
if (config.getKey().equals("item") || config.getKey().equals("vanilla")) if (config.getKey().equals("item") || config.getKey().equals("vanilla"))
return Arrays.asList(new ItemTrigger(config)); return new ItemTrigger(config);
if (config.getKey().equals("exp") || config.getKey().equals("experience")) if (config.getKey().equals("exp") || config.getKey().equals("experience"))
return Arrays.asList(new ExperienceTrigger(config)); return new ExperienceTrigger(config);
return null; return null;
} }
@ -119,111 +79,80 @@ public class DefaultMMOLoader extends MMOLoader {
} }
@Override @Override
public List<Condition> loadCondition(MMOLineConfig config) { public Condition loadCondition(MMOLineConfig config) {
if (config.getKey().equals("from")) {
String source = config.getString("source");
ConfigFile configFile = new ConfigFile("conditions");
if (!configFile.getConfig().contains(source)) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't find " + source + " in experience-sources.yml");
return null;
}
List<Condition> list = new ArrayList<>();
for (String condition : configFile.getConfig().getStringList(source)) {
list.addAll(loadCondition(new MMOLineConfig(condition)));
}
return list;
}
if (config.getKey().equals("distance")) if (config.getKey().equals("distance"))
return Arrays.asList(new DistanceCondition(config)); return new DistanceCondition(config);
if (config.getKey().equals("world")) if (config.getKey().equals("world"))
return Arrays.asList(new WorldCondition(config)); return new WorldCondition(config);
if (config.getKey().equals("biome")) if (config.getKey().equals("biome"))
return Arrays.asList(new BiomeCondition(config)); return new BiomeCondition(config);
if (config.getKey().equals("level")) if (config.getKey().equals("level"))
return Arrays.asList(new LevelCondition(config)); return new LevelCondition(config);
if (config.getKey().equals("permission")) if (config.getKey().equals("permission"))
return Arrays.asList(new PermissionCondition(config)); return new PermissionCondition(config);
return null; return null;
} }
@Override @Override
public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
if (config.getKey().equals("from")) {
String source = config.getString("source");
ConfigFile configFile = new ConfigFile("exp-sources");
if (!configFile.getConfig().contains(source)) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't find " + source + " in experience-sources.yml");
return null;
}
List<ExperienceSource<?>> list = new ArrayList<>();
for (String expSource : configFile.getConfig().getStringList(source)) {
list.addAll(loadExperienceSource(new MMOLineConfig(expSource), dispenser));
}
return list;
}
if (config.getKey().equals("resource")) if (config.getKey().equals("resource"))
return Arrays.asList(new ResourceExperienceSource(dispenser, config)); return new ResourceExperienceSource(dispenser, config);
if (config.getKey().equals("climb")) if (config.getKey().equals("climb"))
return Arrays.asList(new ClimbExperienceSource(dispenser, config)); return new ClimbExperienceSource(dispenser, config);
if (config.getKey().equals("eat")) { if (config.getKey().equals("eat"))
return Arrays.asList(new EatExperienceSource(dispenser, config)); return new EatExperienceSource(dispenser, config);
}
if (config.getKey().equals("damagedealt")) if (config.getKey().equals("damagedealt"))
return Arrays.asList(new DamageDealtExperienceSource(dispenser, config)); return new DamageDealtExperienceSource(dispenser, config);
if (config.getKey().equals("damagetaken")) if (config.getKey().equals("damagetaken"))
return Arrays.asList(new DamageTakenExperienceSource(dispenser, config)); return new DamageTakenExperienceSource(dispenser, config);
if (config.getKey().equals("move")) if (config.getKey().equals("move"))
return Arrays.asList(new MoveExperienceSource(dispenser, config)); return new MoveExperienceSource(dispenser, config);
if (config.getKey().equals("play")) if (config.getKey().equals("play"))
return Arrays.asList(new PlayExperienceSource(dispenser, config)); return new PlayExperienceSource(dispenser, config);
if (config.getKey().equals("projectile")) if (config.getKey().equals("projectile"))
return Arrays.asList(new ProjectileExperienceSource(dispenser, config)); return new ProjectileExperienceSource(dispenser, config);
if (config.getKey().equals("ride")) if (config.getKey().equals("ride"))
return Arrays.asList(new RideExperienceSource(dispenser, config)); return new RideExperienceSource(dispenser, config);
if (config.getKey().equals("tame")) if (config.getKey().equals("tame"))
return Arrays.asList(new TameExperienceSource(dispenser, config)); return new TameExperienceSource(dispenser, config);
if (config.getKey().equals("killmob")) if (config.getKey().equals("killmob"))
return Arrays.asList(new KillMobExperienceSource(dispenser, config)); return new KillMobExperienceSource(dispenser, config);
if (config.getKey().equals("mineblock")) if (config.getKey().equals("mineblock"))
return Arrays.asList(new MineBlockExperienceSource(dispenser, config)); return new MineBlockExperienceSource(dispenser, config);
if (config.getKey().equals("placeblock")) if (config.getKey().equals("placeblock"))
return Arrays.asList(new PlaceBlockExperienceSource(dispenser, config)); return new PlaceBlockExperienceSource(dispenser, config);
if (config.getKey().equals("brewpotion")) if (config.getKey().equals("brewpotion"))
return Arrays.asList(new BrewPotionExperienceSource(dispenser, config)); return new BrewPotionExperienceSource(dispenser, config);
if (config.getKey().equals("smeltitem")) if (config.getKey().equals("smeltitem"))
return Arrays.asList(new SmeltItemExperienceSource(dispenser, config)); return new SmeltItemExperienceSource(dispenser, config);
if (config.getKey().equals("enchantitem")) if (config.getKey().equals("enchantitem"))
return Arrays.asList(new EnchantItemExperienceSource(dispenser, config)); return new EnchantItemExperienceSource(dispenser, config);
if (config.getKey().equals("repairitem")) if (config.getKey().equals("repairitem"))
return Arrays.asList(new RepairItemExperienceSource(dispenser, config)); return new RepairItemExperienceSource(dispenser, config);
if (config.getKey().equals("craftitem")) if (config.getKey().equals("craftitem"))
return Arrays.asList(new CraftItemExperienceSource(dispenser, config)); return new CraftItemExperienceSource(dispenser, config);
return null; return null;
} }

View File

@ -2,16 +2,14 @@ package net.Indyuce.mmocore.api.load;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.quest.objective.Objective; import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
/** /**
* MMOLoader was initially an interface but it is now a * MMOLoader was initially an interface but it is now a
* class so devs do not have to add a new method * class so devs do not have to add a new method
@ -19,11 +17,11 @@ import java.util.List;
*/ */
public class MMOLoader { public class MMOLoader {
public List<Condition> loadCondition(MMOLineConfig config) { public Condition loadCondition(MMOLineConfig config) {
return null; return null;
} }
public List<Trigger> loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
return null; return null;
} }
@ -35,7 +33,7 @@ public class MMOLoader {
return null; return null;
} }
public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
return null; return null;
} }

View File

@ -19,7 +19,6 @@ import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.ExpCurve;
import net.Indyuce.mmocore.experience.ExperienceObject; import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle; import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.player.playerclass.ClassTrigger; import net.Indyuce.mmocore.player.playerclass.ClassTrigger;
import net.Indyuce.mmocore.player.playerclass.ClassTriggerType; import net.Indyuce.mmocore.player.playerclass.ClassTriggerType;
@ -27,7 +26,6 @@ import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
@ -159,9 +157,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
if (config.contains("main-exp-sources.yml")) { if (config.contains("main-exp-sources.yml")) {
for (String key : config.getStringList("main-exp-sources.yml")) for (String key : config.getStringList("main-exp-sources.yml"))
try { try {
List<ExperienceSource<?>> list = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this); MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
for (ExperienceSource source : list)
MMOCore.plugin.experience.registerSource(source);
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '"
+ id + "': " + exception.getMessage()); + id + "': " + exception.getMessage());

View File

@ -25,7 +25,7 @@ public class EventTrigger {
for (String format : list) for (String format : list)
try { try {
triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + format + "' from event trigger '" + event + "': " + exception.getMessage()); "Could not load trigger '" + format + "' from event trigger '" + event + "': " + exception.getMessage());

View File

@ -30,7 +30,7 @@ public abstract class Objective {
for (String key : config.getStringList("triggers")) for (String key : config.getStringList("triggers"))
try { try {
triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load trigger '" + key + "' from objective '" + id + "': " + exception.getMessage()); "Could not load trigger '" + key + "' from objective '" + id + "': " + exception.getMessage());

View File

@ -1,25 +1,22 @@
package net.Indyuce.mmocore.comp.mythicmobs; package net.Indyuce.mmocore.comp.mythicmobs;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.comp.mythicmobs.load.*;
import net.Indyuce.mmocore.api.load.MMOLoader; import net.Indyuce.mmocore.api.load.MMOLoader;
import net.Indyuce.mmocore.api.quest.objective.Objective; import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.comp.mythicmobs.load.*;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import java.util.Arrays;
import java.util.List;
public class MythicMobsMMOLoader extends MMOLoader { public class MythicMobsMMOLoader extends MMOLoader {
@Override @Override
public List<Trigger> loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill")) if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill"))
return Arrays.asList(new MythicSkillTrigger(config)); return new MythicSkillTrigger(config);
return null; return null;
} }
@ -45,12 +42,12 @@ public class MythicMobsMMOLoader extends MMOLoader {
} }
@Override @Override
public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
if (config.getKey().equalsIgnoreCase("killmythicmob")) if (config.getKey().equalsIgnoreCase("killmythicmob"))
return Arrays.asList(new KillMythicMobExperienceSource(dispenser, config)); return new KillMythicMobExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("killmythicfaction")) if (config.getKey().equalsIgnoreCase("killmythicfaction"))
return Arrays.asList(new KillMythicFactionExperienceSource(dispenser, config)); return new KillMythicFactionExperienceSource(dispenser, config);
return null; return null;
} }

View File

@ -1,19 +1,16 @@
package net.Indyuce.mmocore.comp.region; package net.Indyuce.mmocore.comp.region;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.api.load.MMOLoader;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.load.MMOLoader;
import java.util.Arrays; import net.Indyuce.mmocore.loot.chest.condition.Condition;
import java.util.List;
public class WorldGuardMMOLoader extends MMOLoader { public class WorldGuardMMOLoader extends MMOLoader {
@Override @Override
public List<Condition> loadCondition(MMOLineConfig config) { public Condition loadCondition(MMOLineConfig config) {
if (config.getKey().equals("region")) if (config.getKey().equals("region"))
return Arrays.asList(new RegionCondition(config)); return new RegionCondition(config);
return null; return null;
} }

View File

@ -1,19 +1,16 @@
package net.Indyuce.mmocore.comp.vault; package net.Indyuce.mmocore.comp.vault;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.api.load.MMOLoader;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.load.MMOLoader;
import java.util.Arrays; import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import java.util.List;
public class VaultMMOLoader extends MMOLoader { public class VaultMMOLoader extends MMOLoader {
@Override @Override
public List<Trigger> loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("money")) if (config.getKey().equalsIgnoreCase("money"))
return Arrays.asList(new MoneyTrigger(config)); return new MoneyTrigger(config);
return null; return null;
} }

View File

@ -6,7 +6,6 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -15,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
@ -69,10 +67,7 @@ public class Profession extends PostLoadObject implements ExperienceObject {
if (config.contains("exp-sources")) if (config.contains("exp-sources"))
for (String key : config.getStringList("exp-sources")) for (String key : config.getStringList("exp-sources"))
try { try {
List<ExperienceSource<?>> experienceSourceList=MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this); MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this));
for(ExperienceSource experienceSource: experienceSourceList) {
MMOCore.plugin.experience.registerSource(experienceSource);
}
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage()); "Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage());

View File

@ -63,7 +63,7 @@ public class ExperienceItem {
triggers = new ArrayList<>(); triggers = new ArrayList<>();
for (String triggerFormat : config.getStringList("triggers")) for (String triggerFormat : config.getStringList("triggers"))
triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(triggerFormat))); triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(triggerFormat)));
} }
public String getId() { public String getId() {

View File

@ -100,7 +100,7 @@ public abstract class GeneratedInventory extends PluginInventory {
return; return;
if (item instanceof TriggerItem) if (item instanceof TriggerItem)
((TriggerItem) item).getTriggers().forEach(trigger->trigger.apply(getPlayerData())); ((TriggerItem) item).getTrigger().apply(getPlayerData());
else else
whenClicked(event, item); whenClicked(event, item);
} }

View File

@ -9,7 +9,7 @@ import org.bukkit.configuration.ConfigurationSection;
import java.util.List; import java.util.List;
public class TriggerItem extends InventoryItem { public class TriggerItem extends InventoryItem {
private final List<Trigger> triggers; private final Trigger triggers;
public TriggerItem(ConfigurationSection config, String format) { public TriggerItem(ConfigurationSection config, String format) {
super(config); super(config);
@ -22,7 +22,7 @@ public class TriggerItem extends InventoryItem {
return new Placeholders(); return new Placeholders();
} }
public List<Trigger> getTriggers() { public Trigger getTrigger() {
return triggers; return triggers;
} }
} }

View File

@ -53,7 +53,7 @@ public class DropTable extends PostLoadObject {
} }
for (String key : conditionsList) for (String key : conditionsList)
try { try {
conditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage()); "Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage());

View File

@ -1,25 +1,23 @@
package net.Indyuce.mmocore.manager; package net.Indyuce.mmocore.manager;
import com.google.gson.JsonParseException;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
import net.Indyuce.mmocore.api.load.MMOLoader;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import com.google.gson.JsonParseException;
import net.Indyuce.mmocore.loot.chest.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.DefaultMMOLoader;
import net.Indyuce.mmocore.api.load.MMOLoader;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class MMOLoadManager { public class MMOLoadManager {
private final List<MMOLoader> loaders = new ArrayList<>(); private final List<MMOLoader> loaders = new ArrayList<>();
@ -33,36 +31,36 @@ public class MMOLoadManager {
loaders.add(loader); loaders.add(loader);
} }
public List<Condition> loadCondition(MMOLineConfig config) { public Condition loadCondition(MMOLineConfig config) {
return load(List.class, config, loader -> loader.loadCondition(config)); return load("condition", config, loader -> loader.loadCondition(config));
} }
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
return load(Objective.class, config, loader -> loader.loadObjective(config, section)); return load("objective", config, loader -> loader.loadObjective(config, section));
} }
/** /**
Returns a List of Experience Source as one experience source can be linked to others. * Returns a List of Experience Source as one experience source can be linked to others.
Loading one exp source can in fact oad multiples if they are linked * Loading one exp source can in fact oad multiples if they are linked
*/ */
@Deprecated @Deprecated
public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
return load(List.class, config, loader -> loader.loadExperienceSource(config, dispenser)); return load("exp source", config, loader -> loader.loadExperienceSource(config, dispenser));
} }
public List<Trigger> loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
return load(List.class, config, loader -> loader.loadTrigger(config)); return load("trigger", config, loader -> loader.loadTrigger(config));
} }
public DropItem loadDropItem(MMOLineConfig config) { public DropItem loadDropItem(MMOLineConfig config) {
return load(DropItem.class, config, loader -> loader.loadDropItem(config)); return load("drop item", config, loader -> loader.loadDropItem(config));
} }
public BlockType loadBlockType(MMOLineConfig config) { public BlockType loadBlockType(MMOLineConfig config) {
return load(BlockType.class, config, loader -> loader.loadBlockType(config)); return load("block type", config, loader -> loader.loadBlockType(config));
} }
private <T> T load(Class<T> c, MMOLineConfig config, Function<MMOLoader, T> func) { private <T> T load(String objName, MMOLineConfig config, Function<MMOLoader, T> func) {
for (MMOLoader loader : loaders) for (MMOLoader loader : loaders)
try { try {
@ -73,6 +71,6 @@ public class MMOLoadManager {
throw new IllegalArgumentException(exception.getMessage()); throw new IllegalArgumentException(exception.getMessage());
} }
throw new IllegalArgumentException("Could not match any " + c.getSimpleName() + " to '" + config.getKey() + "' in database"); throw new IllegalArgumentException("Could not match any " + objName + " to '" + config.getKey() + "' in database");
} }
} }

View File

@ -189,7 +189,7 @@ public class CustomBlockManager extends SpecificProfessionManager {
for (String key : MMOCore.plugin.getConfig().getStringList("custom-mine-conditions")) for (String key : MMOCore.plugin.getConfig().getStringList("custom-mine-conditions"))
try { try {
customMineConditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); customMineConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage());
} }

View File

@ -60,7 +60,7 @@ public class FishingManager extends SpecificProfessionManager {
for (String str : list) for (String str : list)
try { try {
conditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str))); conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage()); "Could not load condition '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage());

View File

@ -60,7 +60,7 @@ public class Waypoint extends PostLoadObject implements Unlockable {
List<String> conditions = config.getStringList("dynamic-conditions"); List<String> conditions = config.getStringList("dynamic-conditions");
for (String condition : conditions) for (String condition : conditions)
try { try {
dynamicUseConditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition))); dynamicUseConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition)));
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load condition '" + condition + "' from waypoint '" + id + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load condition '" + condition + "' from waypoint '" + id + "': " + exception.getMessage());
} }