diff --git a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java index a82f83df..7c8e18fc 100644 --- a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java @@ -38,9 +38,8 @@ public class MVCoreConfig implements MVConfig { MVCoreConfig(@NotNull MultiverseCore core, @NotNull PluginManager pluginManager) { this.configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME); this.configNodes = new MVCoreConfigNodes(pluginManager); - this.configHandle = CommentedYamlConfigHandle.builder(configPath) + this.configHandle = CommentedYamlConfigHandle.builder(configPath, configNodes.getNodes()) .logger(Logging.getLogger()) - .nodes(configNodes.getNodes()) .migrator(ConfigMigrator.builder(configNodes.VERSION) .addVersionMigrator(VersionMigrator.builder(5.0) .addAction(MoveMigratorAction.of("multiverse-configuration.enforceaccess", "world.enforce-access")) diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/CommentedYamlConfigHandle.java b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/CommentedYamlConfigHandle.java index d6590a9b..9766108d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/CommentedYamlConfigHandle.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/CommentedYamlConfigHandle.java @@ -24,16 +24,17 @@ public class CommentedYamlConfigHandle extends FileConfigHandle { - protected Builder(@NotNull Path configPath) { - super(configPath); + protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) { + super(configPath, nodes); } /** diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/ConfigurationSectionHandle.java b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/ConfigurationSectionHandle.java index ec9052e5..52707929 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/ConfigurationSectionHandle.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/ConfigurationSectionHandle.java @@ -18,16 +18,19 @@ public class ConfigurationSectionHandle extends GenericConfigHandle builder(@NotNull ConfigurationSection configurationSection) { - return new Builder<>(configurationSection); + public static Builder builder( + @NotNull ConfigurationSection configurationSection, @NotNull NodeGroup nodes) { + return new Builder<>(configurationSection, nodes); } - protected ConfigurationSectionHandle(@NotNull ConfigurationSection configurationSection, - @Nullable Logger logger, - @Nullable NodeGroup nodes, - @Nullable ConfigMigrator migrator) { + protected ConfigurationSectionHandle( + @NotNull ConfigurationSection configurationSection, + @Nullable Logger logger, + @NotNull NodeGroup nodes, + @Nullable ConfigMigrator migrator) { super(logger, nodes, migrator); this.config = configurationSection; } @@ -51,7 +54,8 @@ public class ConfigurationSectionHandle extends GenericConfigHandle> extends GenericConfigHandle.Builder { private final ConfigurationSection configurationSection; - protected Builder(@NotNull ConfigurationSection configurationSection) { + protected Builder(@NotNull ConfigurationSection configurationSection, @NotNull NodeGroup nodes) { + super(nodes); this.configurationSection = configurationSection; } diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/FileConfigHandle.java b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/FileConfigHandle.java index 3aeecd4b..408cb48d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/FileConfigHandle.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/FileConfigHandle.java @@ -16,14 +16,19 @@ import org.mvplugins.multiverse.core.configuration.node.NodeGroup; /** * Generic configuration handle for file based configurations. + * * @param The configuration type. */ -abstract class FileConfigHandle extends GenericConfigHandle { +public abstract class FileConfigHandle extends GenericConfigHandle { protected final @NotNull Path configPath; protected final @NotNull File configFile; - protected FileConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @Nullable NodeGroup nodes, @Nullable ConfigMigrator migrator) { + protected FileConfigHandle( + @NotNull Path configPath, + @Nullable Logger logger, + @NotNull NodeGroup nodes, + @Nullable ConfigMigrator migrator) { super(logger, nodes, migrator); this.configPath = configPath; this.configFile = configPath.toFile(); @@ -95,11 +100,13 @@ abstract class FileConfigHandle extends GenericConf * @param The configuration type. * @param The builder type. */ - public static abstract class Builder> extends GenericConfigHandle.Builder { + public abstract static class Builder> + extends GenericConfigHandle.Builder { protected @NotNull Path configPath; - protected Builder(@NotNull Path configPath) { + protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) { + super(nodes); this.configPath = configPath; } diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/GenericConfigHandle.java b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/GenericConfigHandle.java index a0db2939..ae523dec 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/GenericConfigHandle.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/GenericConfigHandle.java @@ -14,8 +14,11 @@ import org.mvplugins.multiverse.core.configuration.node.ValueNode; /** * Generic configuration handle for all ConfigurationSection types. + * + * @param The configuration type. */ public abstract class GenericConfigHandle { + protected final @Nullable Logger logger; protected final @NotNull NodeGroup nodes; protected final @Nullable ConfigMigrator migrator; @@ -128,11 +131,12 @@ public abstract class GenericConfigHandle { */ public abstract static class Builder> { + protected final @NotNull NodeGroup nodes; protected @Nullable Logger logger; - protected @Nullable NodeGroup nodes; protected @Nullable ConfigMigrator migrator; - protected Builder() { + protected Builder(@NotNull NodeGroup nodes) { + this.nodes = nodes; } /** @@ -157,17 +161,6 @@ public abstract class GenericConfigHandle { return self(); } - /** - * Sets the nodes. - * - * @param nodes The nodes. - * @return The builder. - */ - public B nodes(@Nullable NodeGroup nodes) { - this.nodes = nodes; - return self(); - } - /** * Sets the migrator. * diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/YamlConfigHandle.java b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/YamlConfigHandle.java index f80f79ad..90e70ca0 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/handle/YamlConfigHandle.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/handle/YamlConfigHandle.java @@ -22,13 +22,18 @@ public class YamlConfigHandle extends FileConfigHandle { * Creates a new builder for {@link YamlConfigHandle}. * * @param configPath The path to the config file. + * @param nodes The nodes. * @return The builder. */ - public static @NotNull Builder builder(@NotNull Path configPath) { - return new Builder<>(configPath); + public static @NotNull Builder builder(@NotNull Path configPath, @NotNull NodeGroup nodes) { + return new Builder<>(configPath, nodes); } - protected YamlConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @Nullable NodeGroup nodes, @Nullable ConfigMigrator migrator) { + protected YamlConfigHandle( + @NotNull Path configPath, + @Nullable Logger logger, + @NotNull NodeGroup nodes, + @Nullable ConfigMigrator migrator) { super(configPath, logger, nodes, migrator); } @@ -51,12 +56,13 @@ public class YamlConfigHandle extends FileConfigHandle { /** * Builder for {@link YamlConfigHandle}. + * * @param The type of the builder. */ public static class Builder> extends FileConfigHandle.Builder { - protected Builder(@NotNull Path configPath) { - super(configPath); + protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) { + super(configPath, nodes); } /** diff --git a/src/main/java/org/mvplugins/multiverse/core/configuration/node/ValueNode.java b/src/main/java/org/mvplugins/multiverse/core/configuration/node/ValueNode.java index 6830d5a7..6a7115da 100644 --- a/src/main/java/org/mvplugins/multiverse/core/configuration/node/ValueNode.java +++ b/src/main/java/org/mvplugins/multiverse/core/configuration/node/ValueNode.java @@ -59,7 +59,8 @@ public interface ValueNode extends Node { * Validates the value of this node. * * @param value The value to validate. - * @return True if the value is valid, false otherwise. + * @return An empty {@link Try} if the value is valid, or a {@link Try} containing an exception if the value is + * invalid. */ Try validate(@Nullable T value); diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java index 0c008763..827606f8 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java @@ -42,9 +42,8 @@ public final class WorldConfig { @NotNull MultiverseCore multiverseCore) { this.worldName = worldName; this.configNodes = new WorldConfigNodes(multiverseCore); - this.configHandle = ConfigurationSectionHandle.builder(configSection) + this.configHandle = ConfigurationSectionHandle.builder(configSection, configNodes.getNodes()) .logger(Logging.getLogger()) - .nodes(configNodes.getNodes()) .migrator(ConfigMigrator.builder(configNodes.VERSION) .addVersionMigrator(initialVersionMigrator()) .build())