mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-10 10:17:41 +01:00
refactor: Allow for nullable NodeGroup
This commit is contained in:
parent
90a3388728
commit
5cc5e6828f
@ -34,8 +34,9 @@ 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, configNodes.getNodes())
|
||||
this.configHandle = CommentedYamlConfigHandle.builder(configPath)
|
||||
.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"))
|
||||
|
@ -14,11 +14,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfiguration> {
|
||||
|
||||
public static @NotNull Builder builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||
return new Builder(configPath, nodes);
|
||||
public static @NotNull Builder builder(@NotNull Path configPath) {
|
||||
return new Builder(configPath);
|
||||
}
|
||||
|
||||
protected CommentedYamlConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @NotNull NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
protected CommentedYamlConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @Nullable NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
super(configPath, logger, nodes, migrator);
|
||||
}
|
||||
|
||||
@ -30,6 +30,10 @@ public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfigu
|
||||
|
||||
@Override
|
||||
protected void setUpNodes() {
|
||||
if (nodes == null || nodes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommentedConfiguration oldConfig = config;
|
||||
this.config = new CommentedConfiguration(configPath, logger);
|
||||
|
||||
@ -56,8 +60,8 @@ public class CommentedYamlConfigHandle extends FileConfigHandle<CommentedConfigu
|
||||
|
||||
public static class Builder extends FileConfigHandle.Builder<CommentedConfiguration, Builder> {
|
||||
|
||||
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||
super(configPath, nodes);
|
||||
protected Builder(@NotNull Path configPath) {
|
||||
super(configPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,12 +20,12 @@ abstract class FileConfigHandle<C extends FileConfiguration> {
|
||||
protected final @NotNull Path configPath;
|
||||
protected final @NotNull File configFile;
|
||||
protected final @Nullable Logger logger;
|
||||
protected final @NotNull NodeGroup nodes;
|
||||
protected final @Nullable NodeGroup nodes;
|
||||
protected final @Nullable ConfigMigrator migrator;
|
||||
|
||||
protected C config;
|
||||
|
||||
protected FileConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @NotNull NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
protected FileConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @Nullable NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
this.configPath = configPath;
|
||||
this.configFile = configPath.toFile();
|
||||
this.logger = logger;
|
||||
@ -158,12 +158,11 @@ abstract class FileConfigHandle<C extends FileConfiguration> {
|
||||
|
||||
protected @NotNull Path configPath;
|
||||
protected @Nullable Logger logger;
|
||||
protected @NotNull NodeGroup nodes;
|
||||
protected @Nullable NodeGroup nodes;
|
||||
protected @Nullable ConfigMigrator migrator;
|
||||
|
||||
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||
protected Builder(@NotNull Path configPath) {
|
||||
this.configPath = configPath;
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,11 +176,22 @@ abstract class FileConfigHandle<C extends FileConfiguration> {
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the logger.
|
||||
*
|
||||
* @param plugin The plugin to get the logger from.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B logger(Plugin plugin) {
|
||||
this.logger = plugin.getLogger();
|
||||
return self();
|
||||
}
|
||||
|
||||
public B nodes(@Nullable NodeGroup nodes) {
|
||||
this.nodes = nodes;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the migrator.
|
||||
*
|
||||
|
@ -14,14 +14,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
||||
|
||||
public static @NotNull Builder<? extends Builder> builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||
return new Builder<>(configPath, nodes);
|
||||
public static @NotNull Builder<? extends Builder> builder(@NotNull Path configPath) {
|
||||
return new Builder<>(configPath);
|
||||
}
|
||||
|
||||
protected YamlConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @NotNull NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
protected YamlConfigHandle(@NotNull Path configPath, @Nullable Logger logger, @Nullable NodeGroup nodes, @Nullable ConfigMigrator migrator) {
|
||||
super(configPath, logger, nodes, migrator);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected boolean loadConfigObject() {
|
||||
config = new YamlConfiguration();
|
||||
@ -33,8 +36,15 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void setUpNodes() {
|
||||
if (nodes == null || nodes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
YamlConfiguration oldConfig = config;
|
||||
config = new YamlConfiguration();
|
||||
nodes.forEach(node -> {
|
||||
@ -44,6 +54,9 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean save() {
|
||||
try {
|
||||
@ -56,10 +69,13 @@ public class YamlConfigHandle extends FileConfigHandle<YamlConfiguration> {
|
||||
|
||||
public static class Builder<B extends Builder<B>> extends FileConfigHandle.Builder<YamlConfiguration, B> {
|
||||
|
||||
protected Builder(@NotNull Path configPath, @NotNull NodeGroup nodes) {
|
||||
super(configPath, nodes);
|
||||
protected Builder(@NotNull Path configPath) {
|
||||
super(configPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public @NotNull YamlConfigHandle build() {
|
||||
return new YamlConfigHandle(configPath, logger, nodes, migrator);
|
||||
|
Loading…
Reference in New Issue
Block a user