diff --git a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java index 394eaacd..04d444b7 100644 --- a/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java +++ b/src/main/java/net/Indyuce/mmocore/api/block/BlockInfo.java @@ -52,7 +52,7 @@ public class BlockInfo { for (String key : list) try { - triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); + triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load trigger '" + key + "' from block info '" + block.generateKey() + "': " + exception.getMessage()); 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 cd2c891d..f49b9026 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -1,85 +1,45 @@ package net.Indyuce.mmocore.api.load; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.ConfigFile; +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.SkullBlockType; 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.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.api.quest.objective.ClickonObjective; -import net.Indyuce.mmocore.api.quest.objective.GoToObjective; -import net.Indyuce.mmocore.api.quest.objective.KillMobObjective; -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; +import net.Indyuce.mmocore.loot.chest.condition.*; +import net.Indyuce.mmocore.loot.droptable.dropitem.*; +import org.bukkit.configuration.ConfigurationSection; public class DefaultMMOLoader extends MMOLoader { @Override - public List 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 list = new ArrayList<>(); - for (String trigger : configFile.getConfig().getStringList(source)) { - list.addAll(loadTrigger(new MMOLineConfig(trigger))); - } - return list; - } + public Trigger loadTrigger(MMOLineConfig config) { if (config.getKey().equals("message")) - return Arrays.asList(new MessageTrigger(config)); + return new MessageTrigger(config); if (config.getKey().equals("sound") || config.getKey().equals("playsound")) - return Arrays.asList(new SoundTrigger(config)); + return new SoundTrigger(config); if (config.getKey().equals("mana")) - return Arrays.asList(new ManaTrigger(config)); + return new ManaTrigger(config); if (config.getKey().equals("stamina")) - return Arrays.asList(new StaminaTrigger(config)); + return new StaminaTrigger(config); if (config.getKey().equals("stellium")) - return Arrays.asList(new StelliumTrigger(config)); + return new StelliumTrigger(config); if (config.getKey().equals("command")) - return Arrays.asList(new CommandTrigger(config)); + return new CommandTrigger(config); 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")) - return Arrays.asList(new ExperienceTrigger(config)); + return new ExperienceTrigger(config); return null; } @@ -119,111 +79,80 @@ public class DefaultMMOLoader extends MMOLoader { } @Override - public List 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 list = new ArrayList<>(); - for (String condition : configFile.getConfig().getStringList(source)) { - list.addAll(loadCondition(new MMOLineConfig(condition))); - } - return list; - - } - + public Condition loadCondition(MMOLineConfig config) { if (config.getKey().equals("distance")) - return Arrays.asList(new DistanceCondition(config)); + return new DistanceCondition(config); if (config.getKey().equals("world")) - return Arrays.asList(new WorldCondition(config)); + return new WorldCondition(config); if (config.getKey().equals("biome")) - return Arrays.asList(new BiomeCondition(config)); + return new BiomeCondition(config); if (config.getKey().equals("level")) - return Arrays.asList(new LevelCondition(config)); + return new LevelCondition(config); if (config.getKey().equals("permission")) - return Arrays.asList(new PermissionCondition(config)); + return new PermissionCondition(config); return null; } - @Override - public List> 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> list = new ArrayList<>(); - for (String expSource : configFile.getConfig().getStringList(source)) { - list.addAll(loadExperienceSource(new MMOLineConfig(expSource), dispenser)); - } - return list; - - } + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { if (config.getKey().equals("resource")) - return Arrays.asList(new ResourceExperienceSource(dispenser, config)); + return new ResourceExperienceSource(dispenser, config); if (config.getKey().equals("climb")) - return Arrays.asList(new ClimbExperienceSource(dispenser, config)); + return new ClimbExperienceSource(dispenser, config); - if (config.getKey().equals("eat")) { - return Arrays.asList(new EatExperienceSource(dispenser, config)); - } + if (config.getKey().equals("eat")) + return new EatExperienceSource(dispenser, config); if (config.getKey().equals("damagedealt")) - return Arrays.asList(new DamageDealtExperienceSource(dispenser, config)); + return new DamageDealtExperienceSource(dispenser, config); if (config.getKey().equals("damagetaken")) - return Arrays.asList(new DamageTakenExperienceSource(dispenser, config)); + return new DamageTakenExperienceSource(dispenser, config); if (config.getKey().equals("move")) - return Arrays.asList(new MoveExperienceSource(dispenser, config)); + return new MoveExperienceSource(dispenser, config); if (config.getKey().equals("play")) - return Arrays.asList(new PlayExperienceSource(dispenser, config)); + return new PlayExperienceSource(dispenser, config); if (config.getKey().equals("projectile")) - return Arrays.asList(new ProjectileExperienceSource(dispenser, config)); + return new ProjectileExperienceSource(dispenser, config); if (config.getKey().equals("ride")) - return Arrays.asList(new RideExperienceSource(dispenser, config)); + return new RideExperienceSource(dispenser, config); if (config.getKey().equals("tame")) - return Arrays.asList(new TameExperienceSource(dispenser, config)); + return new TameExperienceSource(dispenser, config); if (config.getKey().equals("killmob")) - return Arrays.asList(new KillMobExperienceSource(dispenser, config)); + return new KillMobExperienceSource(dispenser, config); if (config.getKey().equals("mineblock")) - return Arrays.asList(new MineBlockExperienceSource(dispenser, config)); + return new MineBlockExperienceSource(dispenser, config); if (config.getKey().equals("placeblock")) - return Arrays.asList(new PlaceBlockExperienceSource(dispenser, config)); + return new PlaceBlockExperienceSource(dispenser, config); if (config.getKey().equals("brewpotion")) - return Arrays.asList(new BrewPotionExperienceSource(dispenser, config)); + return new BrewPotionExperienceSource(dispenser, config); if (config.getKey().equals("smeltitem")) - return Arrays.asList(new SmeltItemExperienceSource(dispenser, config)); + return new SmeltItemExperienceSource(dispenser, config); if (config.getKey().equals("enchantitem")) - return Arrays.asList(new EnchantItemExperienceSource(dispenser, config)); + return new EnchantItemExperienceSource(dispenser, config); if (config.getKey().equals("repairitem")) - return Arrays.asList(new RepairItemExperienceSource(dispenser, config)); + return new RepairItemExperienceSource(dispenser, config); if (config.getKey().equals("craftitem")) - return Arrays.asList(new CraftItemExperienceSource(dispenser, config)); + return new CraftItemExperienceSource(dispenser, config); return null; } diff --git a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java index 4e83734e..a10d3d33 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -2,16 +2,14 @@ package net.Indyuce.mmocore.api.load; import io.lumine.mythic.lib.api.MMOLineConfig; 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.loot.chest.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; 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 java.util.List; - /** * MMOLoader was initially an interface but it is now a * class so devs do not have to add a new method @@ -19,11 +17,11 @@ import java.util.List; */ public class MMOLoader { - public List loadCondition(MMOLineConfig config) { + public Condition loadCondition(MMOLineConfig config) { return null; } - public List loadTrigger(MMOLineConfig config) { + public Trigger loadTrigger(MMOLineConfig config) { return null; } @@ -35,7 +33,7 @@ public class MMOLoader { return null; } - public List> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { return null; } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 54316b9a..0df81b4c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -19,7 +19,6 @@ import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.ExperienceObject; 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.player.playerclass.ClassTrigger; 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.RegisteredSkill; import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -159,9 +157,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject { if (config.contains("main-exp-sources.yml")) { for (String key : config.getStringList("main-exp-sources.yml")) try { - List> list = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this); - for (ExperienceSource source : list) - MMOCore.plugin.experience.registerSource(source); + MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this)); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java index ac223e92..fca598b2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java @@ -25,7 +25,7 @@ public class EventTrigger { for (String format : list) try { - triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); + triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load trigger '" + format + "' from event trigger '" + event + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/objective/Objective.java b/src/main/java/net/Indyuce/mmocore/api/quest/objective/Objective.java index 35305647..3f23fa9e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/objective/Objective.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/objective/Objective.java @@ -30,7 +30,7 @@ public abstract class Objective { for (String key : config.getStringList("triggers")) try { - triggers.addAll(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); + triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load trigger '" + key + "' from objective '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java index f471dcd5..8a197ee8 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java @@ -1,25 +1,22 @@ package net.Indyuce.mmocore.comp.mythicmobs; 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.quest.objective.Objective; 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.source.type.ExperienceSource; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import org.bukkit.configuration.ConfigurationSection; -import java.util.Arrays; -import java.util.List; - public class MythicMobsMMOLoader extends MMOLoader { @Override - public List loadTrigger(MMOLineConfig config) { + public Trigger loadTrigger(MMOLineConfig config) { if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill")) - return Arrays.asList(new MythicSkillTrigger(config)); + return new MythicSkillTrigger(config); return null; } @@ -45,12 +42,12 @@ public class MythicMobsMMOLoader extends MMOLoader { } @Override - public List> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { if (config.getKey().equalsIgnoreCase("killmythicmob")) - return Arrays.asList(new KillMythicMobExperienceSource(dispenser, config)); + return new KillMythicMobExperienceSource(dispenser, config); if (config.getKey().equalsIgnoreCase("killmythicfaction")) - return Arrays.asList(new KillMythicFactionExperienceSource(dispenser, config)); + return new KillMythicFactionExperienceSource(dispenser, config); return null; } diff --git a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java index 50da8a61..ce4cfa03 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java @@ -1,20 +1,17 @@ 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 java.util.Arrays; -import java.util.List; +import net.Indyuce.mmocore.api.load.MMOLoader; +import net.Indyuce.mmocore.loot.chest.condition.Condition; public class WorldGuardMMOLoader extends MMOLoader { - @Override - public List loadCondition(MMOLineConfig config) { + @Override + public Condition loadCondition(MMOLineConfig config) { - if (config.getKey().equals("region")) - return Arrays.asList(new RegionCondition(config)); + if (config.getKey().equals("region")) + return new RegionCondition(config); - return null; - } + return null; + } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java index db004558..a446e3ce 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java @@ -1,20 +1,17 @@ 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 java.util.Arrays; -import java.util.List; +import net.Indyuce.mmocore.api.load.MMOLoader; +import net.Indyuce.mmocore.api.quest.trigger.Trigger; public class VaultMMOLoader extends MMOLoader { - @Override - public List loadTrigger(MMOLineConfig config) { + @Override + public Trigger loadTrigger(MMOLineConfig config) { - if (config.getKey().equalsIgnoreCase("money")) - return Arrays.asList(new MoneyTrigger(config)); + if (config.getKey().equalsIgnoreCase("money")) + return new MoneyTrigger(config); - return null; - } + return null; + } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/Profession.java b/src/main/java/net/Indyuce/mmocore/experience/Profession.java index 03ba0db5..ac71dc28 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/Profession.java +++ b/src/main/java/net/Indyuce/mmocore/experience/Profession.java @@ -6,7 +6,6 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.experience.droptable.ExperienceTable; -import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; @@ -15,7 +14,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@ -69,10 +67,7 @@ public class Profession extends PostLoadObject implements ExperienceObject { if (config.contains("exp-sources")) for (String key : config.getStringList("exp-sources")) try { - List> experienceSourceList=MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this); - for(ExperienceSource experienceSource: experienceSourceList) { - MMOCore.plugin.experience.registerSource(experienceSource); - } + MMOCore.plugin.experience.registerSource(MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), this)); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not register exp source '" + key + "' from profession '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceItem.java b/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceItem.java index aac2dd3f..27045351 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceItem.java +++ b/src/main/java/net/Indyuce/mmocore/experience/droptable/ExperienceItem.java @@ -63,7 +63,7 @@ public class ExperienceItem { triggers = new ArrayList<>(); 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() { diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java b/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java index e7c8c71b..85be0d26 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/GeneratedInventory.java @@ -100,7 +100,7 @@ public abstract class GeneratedInventory extends PluginInventory { return; if (item instanceof TriggerItem) - ((TriggerItem) item).getTriggers().forEach(trigger->trigger.apply(getPlayerData())); + ((TriggerItem) item).getTrigger().apply(getPlayerData()); else whenClicked(event, item); } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java b/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java index 502bff75..32f13341 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/item/TriggerItem.java @@ -9,7 +9,7 @@ import org.bukkit.configuration.ConfigurationSection; import java.util.List; public class TriggerItem extends InventoryItem { - private final List triggers; + private final Trigger triggers; public TriggerItem(ConfigurationSection config, String format) { super(config); @@ -22,7 +22,7 @@ public class TriggerItem extends InventoryItem { return new Placeholders(); } - public List getTriggers() { + public Trigger getTrigger() { return triggers; } } diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java index 9b69db63..ffc90a61 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java @@ -53,7 +53,7 @@ public class DropTable extends PostLoadObject { } for (String key : conditionsList) try { - conditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); + conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index 95301573..21a6f15e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -1,78 +1,76 @@ 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.List; 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 { - private final List loaders = new ArrayList<>(); + private final List loaders = new ArrayList<>(); - public MMOLoadManager() { - loaders.add(new DefaultMMOLoader()); - } + public MMOLoadManager() { + loaders.add(new DefaultMMOLoader()); + } - public void registerLoader(MMOLoader loader) { - Validate.notNull(loader, "Loader must not be null"); + public void registerLoader(MMOLoader loader) { + Validate.notNull(loader, "Loader must not be null"); - loaders.add(loader); - } + loaders.add(loader); + } - public List loadCondition(MMOLineConfig config) { - return load(List.class, config, loader -> loader.loadCondition(config)); - } + public Condition loadCondition(MMOLineConfig config) { + return load("condition", config, loader -> loader.loadCondition(config)); + } - public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { - return load(Objective.class, config, loader -> loader.loadObjective(config, section)); - } + public Objective loadObjective(MMOLineConfig config, ConfigurationSection 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. - Loading one exp source can in fact oad multiples if they are linked - */ - @Deprecated - public List> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { - return load(List.class, config, loader -> loader.loadExperienceSource(config, dispenser)); - } + /** + * 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 + */ + @Deprecated + public ExperienceSource loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { + return load("exp source", config, loader -> loader.loadExperienceSource(config, dispenser)); + } - public List loadTrigger(MMOLineConfig config) { - return load(List.class, config, loader -> loader.loadTrigger(config)); - } + public Trigger loadTrigger(MMOLineConfig config) { + return load("trigger", config, loader -> loader.loadTrigger(config)); + } - public DropItem loadDropItem(MMOLineConfig config) { - return load(DropItem.class, config, loader -> loader.loadDropItem(config)); - } + public DropItem loadDropItem(MMOLineConfig config) { + return load("drop item", config, loader -> loader.loadDropItem(config)); + } - public BlockType loadBlockType(MMOLineConfig config) { - return load(BlockType.class, config, loader -> loader.loadBlockType(config)); - } + public BlockType loadBlockType(MMOLineConfig config) { + return load("block type", config, loader -> loader.loadBlockType(config)); + } - private T load(Class c, MMOLineConfig config, Function func) { + private T load(String objName, MMOLineConfig config, Function func) { - for (MMOLoader loader : loaders) - try { - T found = func.apply(loader); - if (found != null) - return found; - } catch (IllegalArgumentException | JsonParseException | IndexOutOfBoundsException exception) { - throw new IllegalArgumentException(exception.getMessage()); - } + for (MMOLoader loader : loaders) + try { + T found = func.apply(loader); + if (found != null) + return found; + } catch (IllegalArgumentException | JsonParseException | IndexOutOfBoundsException exception) { + 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"); + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java index f1f23f87..4f089d10 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java @@ -189,7 +189,7 @@ public class CustomBlockManager extends SpecificProfessionManager { for (String key : MMOCore.plugin.getConfig().getStringList("custom-mine-conditions")) try { - customMineConditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); + customMineConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage()); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index bd50a234..aad6403d 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -60,7 +60,7 @@ public class FishingManager extends SpecificProfessionManager { for (String str : list) try { - conditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str))); + conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load condition '" + str + "' from fishing drop table '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java index bd263ac0..93bee8ae 100644 --- a/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java +++ b/src/main/java/net/Indyuce/mmocore/waypoint/Waypoint.java @@ -60,7 +60,7 @@ public class Waypoint extends PostLoadObject implements Unlockable { List conditions = config.getStringList("dynamic-conditions"); for (String condition : conditions) try { - dynamicUseConditions.addAll(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition))); + dynamicUseConditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition))); } catch (RuntimeException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load condition '" + condition + "' from waypoint '" + id + "': " + exception.getMessage()); }