From bfe2b27ab5187b5e57b9585fc8e161cc8ede14fd Mon Sep 17 00:00:00 2001 From: Ka0rX Date: Wed, 27 Jul 2022 19:36:39 +0200 Subject: [PATCH] conditions.yml where you can reference some conditions. --- .../mmocore/api/load/DefaultMMOLoader.java | 27 ++++++++++++++----- .../Indyuce/mmocore/api/load/MMOLoader.java | 2 +- .../comp/region/WorldGuardMMOLoader.java | 7 +++-- .../mmocore/loot/droptable/DropTable.java | 2 +- .../mmocore/manager/ConfigManager.java | 1 + .../mmocore/manager/MMOLoadManager.java | 4 +-- .../profession/CustomBlockManager.java | 2 +- .../manager/profession/FishingManager.java | 2 +- .../Indyuce/mmocore/waypoint/Waypoint.java | 2 +- src/main/resources/default/conditions.yml | 0 10 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/default/conditions.yml 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 e9c5a623..cd2c891d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -119,21 +119,36 @@ public class DefaultMMOLoader extends MMOLoader { } @Override - public Condition loadCondition(MMOLineConfig config) { + 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; + + } + if (config.getKey().equals("distance")) - return new DistanceCondition(config); + return Arrays.asList(new DistanceCondition(config)); if (config.getKey().equals("world")) - return new WorldCondition(config); + return Arrays.asList(new WorldCondition(config)); if (config.getKey().equals("biome")) - return new BiomeCondition(config); + return Arrays.asList(new BiomeCondition(config)); if (config.getKey().equals("level")) - return new LevelCondition(config); + return Arrays.asList(new LevelCondition(config)); if (config.getKey().equals("permission")) - return new PermissionCondition(config); + return Arrays.asList(new PermissionCondition(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 42cf0453..4e83734e 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -19,7 +19,7 @@ import java.util.List; */ public class MMOLoader { - public Condition loadCondition(MMOLineConfig config) { + public List loadCondition(MMOLineConfig 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 735ebda6..50da8a61 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java @@ -4,13 +4,16 @@ 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; + public class WorldGuardMMOLoader extends MMOLoader { @Override - public Condition loadCondition(MMOLineConfig config) { + public List loadCondition(MMOLineConfig config) { if (config.getKey().equals("region")) - return new RegionCondition(config); + return Arrays.asList(new RegionCondition(config)); return null; } 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 ffc90a61..9b69db63 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.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); + conditions.addAll(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/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 72c94f91..f089e009 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -89,6 +89,7 @@ public class ConfigManager { loadDefaultFile("exp-tables.yml"); loadDefaultFile("exp-sources.yml"); loadDefaultFile("triggers.yml"); + loadDefaultFile("conditions.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 157deaaf..95301573 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -33,8 +33,8 @@ public class MMOLoadManager { loaders.add(loader); } - public Condition loadCondition(MMOLineConfig config) { - return load(Condition.class, config, loader -> loader.loadCondition(config)); + public List loadCondition(MMOLineConfig config) { + return load(List.class, config, loader -> loader.loadCondition(config)); } public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { 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 4f089d10..f1f23f87 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.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key))); + customMineConditions.addAll(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 aad6403d..bd50a234 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.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(str))); + conditions.addAll(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 93bee8ae..bd263ac0 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.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(condition))); + dynamicUseConditions.addAll(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()); } diff --git a/src/main/resources/default/conditions.yml b/src/main/resources/default/conditions.yml new file mode 100644 index 00000000..e69de29b