conditions.yml where you can reference some conditions.

This commit is contained in:
Ka0rX 2022-07-27 19:36:39 +02:00
parent 5ef636f5b9
commit bfe2b27ab5
10 changed files with 34 additions and 15 deletions

View File

@ -119,21 +119,36 @@ public class DefaultMMOLoader extends MMOLoader {
}
@Override
public Condition loadCondition(MMOLineConfig config) {
public List<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"))
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;
}

View File

@ -19,7 +19,7 @@ import java.util.List;
*/
public class MMOLoader {
public Condition loadCondition(MMOLineConfig config) {
public List<Condition> loadCondition(MMOLineConfig config) {
return null;
}

View File

@ -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<Condition> loadCondition(MMOLineConfig config) {
if (config.getKey().equals("region"))
return new RegionCondition(config);
return Arrays.asList(new RegionCondition(config));
return null;
}

View File

@ -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());

View File

@ -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"));

View File

@ -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<Condition> loadCondition(MMOLineConfig config) {
return load(List.class, config, loader -> loader.loadCondition(config));
}
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {

View File

@ -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());
}

View File

@ -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());

View File

@ -60,7 +60,7 @@ public class Waypoint extends PostLoadObject implements Unlockable {
List<String> 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());
}