Make sure nodes is not null and fix some checkstyles

This commit is contained in:
Ben Woo 2023-09-23 10:14:10 +08:00
parent d08e6fae38
commit b2c1aafb62
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
8 changed files with 49 additions and 39 deletions

View File

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

View File

@ -24,16 +24,17 @@ public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfigu
* Creates a new builder for a {@link CommentedYamlConfigHandle}.
*
* @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 CommentedYamlConfigHandle(
@NotNull Path configPath,
@Nullable Logger logger,
@Nullable NodeGroup nodes,
@NotNull NodeGroup nodes,
@Nullable ConfigMigrator migrator) {
super(configPath, logger, nodes, migrator);
}
@ -96,8 +97,8 @@ public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfigu
*/
public static class Builder extends FileConfigHandle.Builder<CommentedConfiguration, Builder> {
protected Builder(@NotNull Path configPath) {
super(configPath);
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
super(configPath, nodes);
}
/**

View File

@ -18,16 +18,19 @@ public class ConfigurationSectionHandle extends GenericConfigHandle<Configuratio
* Creates a new builder for a {@link ConfigurationSectionHandle}.
*
* @param configurationSection The configuration section.
* @param nodes The nodes.
* @return The builder.
*/
public static Builder<? extends Builder> builder(@NotNull ConfigurationSection configurationSection) {
return new Builder<>(configurationSection);
public static Builder<? extends 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<Configuratio
public static class Builder<B extends Builder<B>> extends GenericConfigHandle.Builder<ConfigurationSection, B> {
private final ConfigurationSection configurationSection;
protected Builder(@NotNull ConfigurationSection configurationSection) {
protected Builder(@NotNull ConfigurationSection configurationSection, @NotNull NodeGroup nodes) {
super(nodes);
this.configurationSection = configurationSection;
}

View File

@ -16,14 +16,19 @@ import org.mvplugins.multiverse.core.configuration.node.NodeGroup;
/**
* Generic configuration handle for file based configurations.
*
* @param <C> The configuration type.
*/
abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConfigHandle<C> {
public abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConfigHandle<C> {
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<C extends FileConfiguration> extends GenericConf
* @param <C> The configuration type.
* @param <B> The builder type.
*/
public static abstract class Builder<C extends FileConfiguration, B extends Builder<C, B>> extends GenericConfigHandle.Builder<C, B> {
public abstract static class Builder<C extends FileConfiguration, B extends Builder<C, B>>
extends GenericConfigHandle.Builder<C, B> {
protected @NotNull Path configPath;
protected Builder(@NotNull Path configPath) {
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
super(nodes);
this.configPath = configPath;
}

View File

@ -14,8 +14,11 @@ import org.mvplugins.multiverse.core.configuration.node.ValueNode;
/**
* Generic configuration handle for all ConfigurationSection types.
*
* @param <C> The configuration type.
*/
public abstract class GenericConfigHandle<C extends ConfigurationSection> {
protected final @Nullable Logger logger;
protected final @NotNull NodeGroup nodes;
protected final @Nullable ConfigMigrator migrator;
@ -128,11 +131,12 @@ public abstract class GenericConfigHandle<C extends ConfigurationSection> {
*/
public abstract static class Builder<C extends ConfigurationSection, B extends GenericConfigHandle.Builder<C, B>> {
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<C extends ConfigurationSection> {
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.
*

View File

@ -22,13 +22,18 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
* 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<? extends Builder> builder(@NotNull Path configPath) {
return new Builder<>(configPath);
public static @NotNull Builder<? extends 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<YamlConfiguration> {
/**
* Builder for {@link YamlConfigHandle}.
*
* @param <B> The type of the builder.
*/
public static class Builder<B extends Builder<B>> extends FileConfigHandle.Builder<YamlConfiguration, B> {
protected Builder(@NotNull Path configPath) {
super(configPath);
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
super(configPath, nodes);
}
/**

View File

@ -59,7 +59,8 @@ public interface ValueNode<T> 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<Void> validate(@Nullable T value);

View File

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