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 04d444b7..394eaacd 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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); + triggers.addAll(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 4820c112..e9c5a623 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -43,30 +43,43 @@ import java.util.logging.Level; public class DefaultMMOLoader extends MMOLoader { @Override - public Trigger loadTrigger(MMOLineConfig config) { + 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; + } if (config.getKey().equals("message")) - return new MessageTrigger(config); + return Arrays.asList(new MessageTrigger(config)); if (config.getKey().equals("sound") || config.getKey().equals("playsound")) - return new SoundTrigger(config); + return Arrays.asList(new SoundTrigger(config)); if (config.getKey().equals("mana")) - return new ManaTrigger(config); + return Arrays.asList(new ManaTrigger(config)); if (config.getKey().equals("stamina")) - return new StaminaTrigger(config); + return Arrays.asList(new StaminaTrigger(config)); if (config.getKey().equals("stellium")) - return new StelliumTrigger(config); + return Arrays.asList(new StelliumTrigger(config)); if (config.getKey().equals("command")) - return new CommandTrigger(config); + return Arrays.asList(new CommandTrigger(config)); if (config.getKey().equals("item") || config.getKey().equals("vanilla")) - return new ItemTrigger(config); + return Arrays.asList(new ItemTrigger(config)); if (config.getKey().equals("exp") || config.getKey().equals("experience")) - return new ExperienceTrigger(config); + return Arrays.asList(new ExperienceTrigger(config)); return null; } @@ -126,19 +139,18 @@ public class DefaultMMOLoader extends MMOLoader { } - @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"); + 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)); + List> list = new ArrayList<>(); + for (String expSource : configFile.getConfig().getStringList(source)) { + list.addAll(loadExperienceSource(new MMOLineConfig(expSource), dispenser)); } return list; 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 38333482..42cf0453 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -23,7 +23,7 @@ public class MMOLoader { return null; } - public Trigger loadTrigger(MMOLineConfig config) { + public List loadTrigger(MMOLineConfig config) { return null; } 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 fca598b2..ac223e92 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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); + triggers.addAll(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 3f23fa9e..35305647 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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); + triggers.addAll(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 7a4b38fa..f471dcd5 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/MythicMobsMMOLoader.java @@ -16,10 +16,10 @@ import java.util.List; public class MythicMobsMMOLoader extends MMOLoader { @Override - public Trigger loadTrigger(MMOLineConfig config) { + public List loadTrigger(MMOLineConfig config) { if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill")) - return new MythicSkillTrigger(config); + return Arrays.asList(new MythicSkillTrigger(config)); 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 1cadefc0..db004558 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/vault/VaultMMOLoader.java @@ -4,13 +4,16 @@ 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; + public class VaultMMOLoader extends MMOLoader { @Override - public Trigger loadTrigger(MMOLineConfig config) { + public List loadTrigger(MMOLineConfig config) { if (config.getKey().equalsIgnoreCase("money")) - return new MoneyTrigger(config); + return Arrays.asList(new MoneyTrigger(config)); return null; } 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 27045351..aac2dd3f 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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(triggerFormat))); + triggers.addAll(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 85be0d26..e7c8c71b 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).getTrigger().apply(getPlayerData()); + ((TriggerItem) item).getTriggers().forEach(trigger->trigger.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 78f0c65d..502bff75 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 @@ -6,13 +6,15 @@ import net.Indyuce.mmocore.api.quest.trigger.Trigger; import net.Indyuce.mmocore.gui.api.GeneratedInventory; import org.bukkit.configuration.ConfigurationSection; +import java.util.List; + public class TriggerItem extends InventoryItem { - private final Trigger trigger; + private final List triggers; public TriggerItem(ConfigurationSection config, String format) { super(config); - trigger = MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format)); + triggers = MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format)); } @Override @@ -20,7 +22,7 @@ public class TriggerItem extends InventoryItem { return new Placeholders(); } - public Trigger getTrigger() { - return trigger; + public List getTriggers() { + return triggers; } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 2234376a..72c94f91 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -88,6 +88,7 @@ public class ConfigManager { loadDefaultFile("commands.yml"); loadDefaultFile("exp-tables.yml"); loadDefaultFile("exp-sources.yml"); + loadDefaultFile("triggers.yml"); loadDefaultFile("guilds.yml"); commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose")); diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index a448882f..157deaaf 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -50,8 +50,8 @@ public class MMOLoadManager { return load(List.class, config, loader -> loader.loadExperienceSource(config, dispenser)); } - public Trigger loadTrigger(MMOLineConfig config) { - return load(Trigger.class, config, loader -> loader.loadTrigger(config)); + public List loadTrigger(MMOLineConfig config) { + return load(List.class, config, loader -> loader.loadTrigger(config)); } public DropItem loadDropItem(MMOLineConfig config) { diff --git a/src/main/resources/default/exp-sources.yml b/src/main/resources/default/exp-sources.yml index e69de29b..fd768fe7 100644 --- a/src/main/resources/default/exp-sources.yml +++ b/src/main/resources/default/exp-sources.yml @@ -0,0 +1,8 @@ +#A list of experience source that can be loaded using 'from{source="test-exp-source"}' +test-exp-source: + - 'damagedealt{type=physical;amount=250}' + - 'move{type=WALK;amount=300}' + - 'from{source=test2}' + +test2: + - 'eat{type=CARROT;amount="50"}' \ No newline at end of file diff --git a/src/main/resources/default/triggers.yml b/src/main/resources/default/triggers.yml new file mode 100644 index 00000000..e69de29b