triggers.yml where you can reference some triggers.

This commit is contained in:
Ka0rX 2022-07-27 19:19:21 +02:00
parent f3b8db1383
commit 5ef636f5b9
14 changed files with 60 additions and 34 deletions

View File

@ -52,7 +52,7 @@ public class BlockInfo {
for (String key : list) for (String key : list)
try { try {
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); triggers.addAll(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

@ -43,30 +43,43 @@ import java.util.logging.Level;
public class DefaultMMOLoader extends MMOLoader { public class DefaultMMOLoader extends MMOLoader {
@Override @Override
public Trigger loadTrigger(MMOLineConfig config) { public List<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 new MessageTrigger(config); return Arrays.asList(new MessageTrigger(config));
if (config.getKey().equals("sound") || config.getKey().equals("playsound")) if (config.getKey().equals("sound") || config.getKey().equals("playsound"))
return new SoundTrigger(config); return Arrays.asList(new SoundTrigger(config));
if (config.getKey().equals("mana")) if (config.getKey().equals("mana"))
return new ManaTrigger(config); return Arrays.asList(new ManaTrigger(config));
if (config.getKey().equals("stamina")) if (config.getKey().equals("stamina"))
return new StaminaTrigger(config); return Arrays.asList(new StaminaTrigger(config));
if (config.getKey().equals("stellium")) if (config.getKey().equals("stellium"))
return new StelliumTrigger(config); return Arrays.asList(new StelliumTrigger(config));
if (config.getKey().equals("command")) if (config.getKey().equals("command"))
return new CommandTrigger(config); return Arrays.asList(new CommandTrigger(config));
if (config.getKey().equals("item") || config.getKey().equals("vanilla")) 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")) if (config.getKey().equals("exp") || config.getKey().equals("experience"))
return new ExperienceTrigger(config); return Arrays.asList(new ExperienceTrigger(config));
return null; return null;
} }
@ -126,19 +139,18 @@ public class DefaultMMOLoader extends MMOLoader {
} }
@Override @Override
public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { public List<ExperienceSource<?>> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
if(config.getKey().equals("from")) { if (config.getKey().equals("from")) {
String source=config.getString("source"); String source = config.getString("source");
ConfigFile configFile= new ConfigFile("exp-sources"); ConfigFile configFile = new ConfigFile("exp-sources");
if(!configFile.getConfig().contains(source)) { if (!configFile.getConfig().contains(source)) {
MMOCore.plugin.getLogger().log(Level.WARNING,"Couldn't find "+source+" in experience-sources.yml"); MMOCore.plugin.getLogger().log(Level.WARNING, "Couldn't find " + source + " in experience-sources.yml");
return null; return null;
} }
List<ExperienceSource<?>> list= new ArrayList<>(); List<ExperienceSource<?>> list = new ArrayList<>();
for(String expSource: configFile.getConfig().getStringList(source)) { for (String expSource : configFile.getConfig().getStringList(source)) {
list.addAll(loadExperienceSource(new MMOLineConfig(expSource),dispenser)); list.addAll(loadExperienceSource(new MMOLineConfig(expSource), dispenser));
} }
return list; return list;

View File

@ -23,7 +23,7 @@ public class MMOLoader {
return null; return null;
} }
public Trigger loadTrigger(MMOLineConfig config) { public List<Trigger> loadTrigger(MMOLineConfig config) {
return null; return null;
} }

View File

@ -25,7 +25,7 @@ public class EventTrigger {
for (String format : list) for (String format : list)
try { try {
triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); triggers.addAll(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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(key))); triggers.addAll(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

@ -16,10 +16,10 @@ import java.util.List;
public class MythicMobsMMOLoader extends MMOLoader { public class MythicMobsMMOLoader extends MMOLoader {
@Override @Override
public Trigger loadTrigger(MMOLineConfig config) { public List<Trigger> loadTrigger(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill")) if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill"))
return new MythicSkillTrigger(config); return Arrays.asList(new MythicSkillTrigger(config));
return null; return null;
} }

View File

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

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.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(triggerFormat))); triggers.addAll(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).getTrigger().apply(getPlayerData()); ((TriggerItem) item).getTriggers().forEach(trigger->trigger.apply(getPlayerData()));
else else
whenClicked(event, item); whenClicked(event, item);
} }

View File

@ -6,13 +6,15 @@ import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import java.util.List;
public class TriggerItem extends InventoryItem { public class TriggerItem extends InventoryItem {
private final Trigger trigger; private final List<Trigger> triggers;
public TriggerItem(ConfigurationSection config, String format) { public TriggerItem(ConfigurationSection config, String format) {
super(config); super(config);
trigger = MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format)); triggers = MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format));
} }
@Override @Override
@ -20,7 +22,7 @@ public class TriggerItem extends InventoryItem {
return new Placeholders(); return new Placeholders();
} }
public Trigger getTrigger() { public List<Trigger> getTriggers() {
return trigger; return triggers;
} }
} }

View File

@ -88,6 +88,7 @@ public class ConfigManager {
loadDefaultFile("commands.yml"); loadDefaultFile("commands.yml");
loadDefaultFile("exp-tables.yml"); loadDefaultFile("exp-tables.yml");
loadDefaultFile("exp-sources.yml"); loadDefaultFile("exp-sources.yml");
loadDefaultFile("triggers.yml");
loadDefaultFile("guilds.yml"); loadDefaultFile("guilds.yml");
commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose")); commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose"));

View File

@ -50,8 +50,8 @@ public class MMOLoadManager {
return load(List.class, config, loader -> loader.loadExperienceSource(config, dispenser)); return load(List.class, config, loader -> loader.loadExperienceSource(config, dispenser));
} }
public Trigger loadTrigger(MMOLineConfig config) { public List<Trigger> loadTrigger(MMOLineConfig config) {
return load(Trigger.class, config, loader -> loader.loadTrigger(config)); return load(List.class, config, loader -> loader.loadTrigger(config));
} }
public DropItem loadDropItem(MMOLineConfig config) { public DropItem loadDropItem(MMOLineConfig config) {

View File

@ -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"}'

View File