Skip to content

Commit

Permalink
Fixed bugs with new config system
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Feb 7, 2021
1 parent d0366b3 commit b5c3af7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
21 changes: 18 additions & 3 deletions eco-util/src/main/java/com/willfp/eco/util/config/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class BaseConfig extends AbstractUpdatableConfig {

/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
Expand All @@ -19,7 +19,22 @@ public abstract class BaseConfig extends AbstractUpdatableConfig {
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final AbstractEcoPlugin plugin,
@Nullable final String... updateBlacklist) {
super(configName, plugin, "/", plugin.getClass(), removeUnused, updateBlacklist);
@NotNull final String... updateBlacklist) {
super(configName, plugin, "", plugin.getClass(), removeUnused, updateBlacklist);
}

/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
* Automatically updates.
*
* @param configName The name of the config
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param plugin The plugin.
*/
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final AbstractEcoPlugin plugin) {
super(configName, plugin, "", plugin.getClass(), removeUnused, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public abstract class StaticBaseConfig extends AbstractConfig {
*/
protected StaticBaseConfig(@NotNull final String configName,
@NotNull final AbstractEcoPlugin plugin) {
super(configName, plugin, "/", plugin.getClass());
super(configName, plugin, "", plugin.getClass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.willfp.eco.util.config;

@Deprecated
public interface ValueGetter {
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ protected String getResourcePath() {
if (subDirectoryPath.isEmpty()) {
resourcePath = name;
} else {
resourcePath = "/" + subDirectoryPath + name;
resourcePath = subDirectoryPath + name;
}

return resourcePath;
return "/" + resourcePath;
}

/**
Expand All @@ -136,8 +136,7 @@ protected YamlConfiguration getConfigInJar() {
InputStream newIn = source.getResourceAsStream(getResourcePath());

if (newIn == null) {
this.getPlugin().getLog().error(this.getName() + " is null?");
return null;
throw new NullPointerException(this.getName() + " is null?");
}

BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -36,10 +36,11 @@ protected AbstractUpdatableConfig(@NotNull final String configName,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source,
final boolean removeUnused,
@Nullable final String... updateBlacklist) {
@NotNull final String... updateBlacklist) {
super(configName, plugin, subDirectoryPath, source);
this.removeUnused = removeUnused;
this.updateBlacklist = Arrays.asList(updateBlacklist);
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
this.updateBlacklist.removeIf(String::isEmpty);

update();
}
Expand Down

0 comments on commit b5c3af7

Please sign in to comment.