mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 12:05:14 +01:00
Make sure nodes is not null and fix some checkstyles
This commit is contained in:
parent
d08e6fae38
commit
b2c1aafb62
@ -38,9 +38,8 @@ public class MVCoreConfig implements MVConfig {
|
|||||||
MVCoreConfig(@NotNull MultiverseCore core, @NotNull PluginManager pluginManager) {
|
MVCoreConfig(@NotNull MultiverseCore core, @NotNull PluginManager pluginManager) {
|
||||||
this.configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME);
|
this.configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME);
|
||||||
this.configNodes = new MVCoreConfigNodes(pluginManager);
|
this.configNodes = new MVCoreConfigNodes(pluginManager);
|
||||||
this.configHandle = CommentedYamlConfigHandle.builder(configPath)
|
this.configHandle = CommentedYamlConfigHandle.builder(configPath, configNodes.getNodes())
|
||||||
.logger(Logging.getLogger())
|
.logger(Logging.getLogger())
|
||||||
.nodes(configNodes.getNodes())
|
|
||||||
.migrator(ConfigMigrator.builder(configNodes.VERSION)
|
.migrator(ConfigMigrator.builder(configNodes.VERSION)
|
||||||
.addVersionMigrator(VersionMigrator.builder(5.0)
|
.addVersionMigrator(VersionMigrator.builder(5.0)
|
||||||
.addAction(MoveMigratorAction.of("multiverse-configuration.enforceaccess", "world.enforce-access"))
|
.addAction(MoveMigratorAction.of("multiverse-configuration.enforceaccess", "world.enforce-access"))
|
||||||
|
@ -24,16 +24,17 @@ public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfigu
|
|||||||
* Creates a new builder for a {@link CommentedYamlConfigHandle}.
|
* Creates a new builder for a {@link CommentedYamlConfigHandle}.
|
||||||
*
|
*
|
||||||
* @param configPath The path to the config file.
|
* @param configPath The path to the config file.
|
||||||
|
* @param nodes The nodes.
|
||||||
* @return The builder.
|
* @return The builder.
|
||||||
*/
|
*/
|
||||||
public static @NotNull Builder builder(@NotNull Path configPath) {
|
public static @NotNull Builder builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||||
return new Builder(configPath);
|
return new Builder(configPath, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CommentedYamlConfigHandle(
|
protected CommentedYamlConfigHandle(
|
||||||
@NotNull Path configPath,
|
@NotNull Path configPath,
|
||||||
@Nullable Logger logger,
|
@Nullable Logger logger,
|
||||||
@Nullable NodeGroup nodes,
|
@NotNull NodeGroup nodes,
|
||||||
@Nullable ConfigMigrator migrator) {
|
@Nullable ConfigMigrator migrator) {
|
||||||
super(configPath, logger, nodes, 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> {
|
public static class Builder extends FileConfigHandle.Builder<CommentedConfiguration, Builder> {
|
||||||
|
|
||||||
protected Builder(@NotNull Path configPath) {
|
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||||
super(configPath);
|
super(configPath, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,16 +18,19 @@ public class ConfigurationSectionHandle extends GenericConfigHandle<Configuratio
|
|||||||
* Creates a new builder for a {@link ConfigurationSectionHandle}.
|
* Creates a new builder for a {@link ConfigurationSectionHandle}.
|
||||||
*
|
*
|
||||||
* @param configurationSection The configuration section.
|
* @param configurationSection The configuration section.
|
||||||
|
* @param nodes The nodes.
|
||||||
* @return The builder.
|
* @return The builder.
|
||||||
*/
|
*/
|
||||||
public static Builder<? extends Builder> builder(@NotNull ConfigurationSection configurationSection) {
|
public static Builder<? extends Builder> builder(
|
||||||
return new Builder<>(configurationSection);
|
@NotNull ConfigurationSection configurationSection, @NotNull NodeGroup nodes) {
|
||||||
|
return new Builder<>(configurationSection, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ConfigurationSectionHandle(@NotNull ConfigurationSection configurationSection,
|
protected ConfigurationSectionHandle(
|
||||||
@Nullable Logger logger,
|
@NotNull ConfigurationSection configurationSection,
|
||||||
@Nullable NodeGroup nodes,
|
@Nullable Logger logger,
|
||||||
@Nullable ConfigMigrator migrator) {
|
@NotNull NodeGroup nodes,
|
||||||
|
@Nullable ConfigMigrator migrator) {
|
||||||
super(logger, nodes, migrator);
|
super(logger, nodes, migrator);
|
||||||
this.config = configurationSection;
|
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> {
|
public static class Builder<B extends Builder<B>> extends GenericConfigHandle.Builder<ConfigurationSection, B> {
|
||||||
private final ConfigurationSection configurationSection;
|
private final ConfigurationSection configurationSection;
|
||||||
|
|
||||||
protected Builder(@NotNull ConfigurationSection configurationSection) {
|
protected Builder(@NotNull ConfigurationSection configurationSection, @NotNull NodeGroup nodes) {
|
||||||
|
super(nodes);
|
||||||
this.configurationSection = configurationSection;
|
this.configurationSection = configurationSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,14 +16,19 @@ import org.mvplugins.multiverse.core.configuration.node.NodeGroup;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic configuration handle for file based configurations.
|
* Generic configuration handle for file based configurations.
|
||||||
|
*
|
||||||
* @param <C> The configuration type.
|
* @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 Path configPath;
|
||||||
protected final @NotNull File configFile;
|
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);
|
super(logger, nodes, migrator);
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
this.configFile = configPath.toFile();
|
this.configFile = configPath.toFile();
|
||||||
@ -95,11 +100,13 @@ abstract class FileConfigHandle<C extends FileConfiguration> extends GenericConf
|
|||||||
* @param <C> The configuration type.
|
* @param <C> The configuration type.
|
||||||
* @param <B> The builder 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 @NotNull Path configPath;
|
||||||
|
|
||||||
protected Builder(@NotNull Path configPath) {
|
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||||
|
super(nodes);
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,11 @@ import org.mvplugins.multiverse.core.configuration.node.ValueNode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic configuration handle for all ConfigurationSection types.
|
* Generic configuration handle for all ConfigurationSection types.
|
||||||
|
*
|
||||||
|
* @param <C> The configuration type.
|
||||||
*/
|
*/
|
||||||
public abstract class GenericConfigHandle<C extends ConfigurationSection> {
|
public abstract class GenericConfigHandle<C extends ConfigurationSection> {
|
||||||
|
|
||||||
protected final @Nullable Logger logger;
|
protected final @Nullable Logger logger;
|
||||||
protected final @NotNull NodeGroup nodes;
|
protected final @NotNull NodeGroup nodes;
|
||||||
protected final @Nullable ConfigMigrator migrator;
|
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>> {
|
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 Logger logger;
|
||||||
protected @Nullable NodeGroup nodes;
|
|
||||||
protected @Nullable ConfigMigrator migrator;
|
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();
|
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.
|
* Sets the migrator.
|
||||||
*
|
*
|
||||||
|
@ -22,13 +22,18 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
|||||||
* Creates a new builder for {@link YamlConfigHandle}.
|
* Creates a new builder for {@link YamlConfigHandle}.
|
||||||
*
|
*
|
||||||
* @param configPath The path to the config file.
|
* @param configPath The path to the config file.
|
||||||
|
* @param nodes The nodes.
|
||||||
* @return The builder.
|
* @return The builder.
|
||||||
*/
|
*/
|
||||||
public static @NotNull Builder<? extends Builder> builder(@NotNull Path configPath) {
|
public static @NotNull Builder<? extends Builder> builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||||
return new Builder<>(configPath);
|
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);
|
super(configPath, logger, nodes, migrator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,12 +56,13 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link YamlConfigHandle}.
|
* Builder for {@link YamlConfigHandle}.
|
||||||
|
*
|
||||||
* @param <B> The type of the builder.
|
* @param <B> The type of the builder.
|
||||||
*/
|
*/
|
||||||
public static class Builder<B extends Builder<B>> extends FileConfigHandle.Builder<YamlConfiguration, B> {
|
public static class Builder<B extends Builder<B>> extends FileConfigHandle.Builder<YamlConfiguration, B> {
|
||||||
|
|
||||||
protected Builder(@NotNull Path configPath) {
|
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||||
super(configPath);
|
super(configPath, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,7 +59,8 @@ public interface ValueNode<T> extends Node {
|
|||||||
* Validates the value of this node.
|
* Validates the value of this node.
|
||||||
*
|
*
|
||||||
* @param value The value to validate.
|
* @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);
|
Try<Void> validate(@Nullable T value);
|
||||||
|
|
||||||
|
@ -42,9 +42,8 @@ public final class WorldConfig {
|
|||||||
@NotNull MultiverseCore multiverseCore) {
|
@NotNull MultiverseCore multiverseCore) {
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
this.configNodes = new WorldConfigNodes(multiverseCore);
|
this.configNodes = new WorldConfigNodes(multiverseCore);
|
||||||
this.configHandle = ConfigurationSectionHandle.builder(configSection)
|
this.configHandle = ConfigurationSectionHandle.builder(configSection, configNodes.getNodes())
|
||||||
.logger(Logging.getLogger())
|
.logger(Logging.getLogger())
|
||||||
.nodes(configNodes.getNodes())
|
|
||||||
.migrator(ConfigMigrator.builder(configNodes.VERSION)
|
.migrator(ConfigMigrator.builder(configNodes.VERSION)
|
||||||
.addVersionMigrator(initialVersionMigrator())
|
.addVersionMigrator(initialVersionMigrator())
|
||||||
.build())
|
.build())
|
||||||
|
Loading…
Reference in New Issue
Block a user