The config changes dont end
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.core.config;
|
||||
package com.willfp.eco.core.config.interfaces;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.willfp.eco.core.config.interfaces;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JSONConfig extends Config {
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<JSONConfig> getSubsections(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||
|
||||
@Override
|
||||
JSONConfig clone();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.core.config;
|
||||
package com.willfp.eco.core.config.interfaces;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.core.config.interfaces;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public interface WrappedYamlConfiguration {
|
||||
/**
|
||||
* Get the ConfigurationSection handle.
|
||||
*
|
||||
* @return The handle.
|
||||
*/
|
||||
YamlConfiguration getBukkitHandle();
|
||||
}
|
||||
@@ -1,30 +1,20 @@
|
||||
package com.willfp.eco.core.config.json;
|
||||
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.config.json.wrapper.JSONConfigWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface JSONConfig extends Config {
|
||||
public class JSONConfig extends JSONConfigWrapper {
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
* Config implementation for passing maps.
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
* @param values The map of values.
|
||||
*/
|
||||
@NotNull
|
||||
List<JSONConfig> getSubsections(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||
|
||||
@Override
|
||||
JSONConfig clone();
|
||||
public JSONConfig(@NotNull final Map<String, Object> values) {
|
||||
super(Eco.getHandler().getConfigFactory().createJSONConfig(values));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.json.wrapper.LoadableJSONConfigWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class JsonStaticBaseConfig extends LoadableJSONConfigWrapper {
|
||||
public abstract class JSONStaticBaseConfig extends LoadableJSONConfigWrapper {
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.json, lang.json).
|
||||
* <p>
|
||||
@@ -14,7 +14,7 @@ public abstract class JsonStaticBaseConfig extends LoadableJSONConfigWrapper {
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected JsonStaticBaseConfig(@NotNull final String configName,
|
||||
protected JSONStaticBaseConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(Eco.getHandler().getConfigFactory().createLoadableJSONConfig(configName, plugin, "", plugin.getClass()));
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.willfp.eco.core.config.json;
|
||||
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
|
||||
public interface LoadableJSONConfig extends JSONConfig, LoadableConfig {
|
||||
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.willfp.eco.core.config.json.wrapper;
|
||||
|
||||
import com.willfp.eco.core.config.json.JSONConfig;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.config.wrapper.ConfigWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JSONConfigWrapper<T extends JSONConfig> extends ConfigWrapper<T> implements JSONConfig {
|
||||
public abstract class JSONConfigWrapper extends ConfigWrapper<JSONConfig> implements JSONConfig {
|
||||
/**
|
||||
* Create a config wrapper.
|
||||
*
|
||||
* @param handle The handle.
|
||||
*/
|
||||
public JSONConfigWrapper(@NotNull final T handle) {
|
||||
protected JSONConfigWrapper(@NotNull final JSONConfig handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,48 @@
|
||||
package com.willfp.eco.core.config.json.wrapper;
|
||||
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
import com.willfp.eco.core.config.json.LoadableJSONConfig;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class LoadableJSONConfigWrapper extends JSONConfigWrapper<LoadableJSONConfig> implements LoadableConfig {
|
||||
public abstract class LoadableJSONConfigWrapper extends JSONConfigWrapper implements LoadableConfig {
|
||||
/**
|
||||
* Create a config wrapper.
|
||||
*
|
||||
* @param handle The handle.
|
||||
*/
|
||||
public LoadableJSONConfigWrapper(@NotNull final LoadableJSONConfig handle) {
|
||||
protected LoadableJSONConfigWrapper(@NotNull final JSONConfig handle) {
|
||||
super(handle);
|
||||
|
||||
Validate.isTrue(handle instanceof LoadableConfig, "Wrapped config must be loadable!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createFile() {
|
||||
this.getHandle().createFile();
|
||||
((LoadableConfig) this.getHandle()).createFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
return this.getHandle().getResourcePath();
|
||||
return ((LoadableConfig) this.getHandle()).getResourcePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
this.getHandle().save();
|
||||
((LoadableConfig) this.getHandle()).save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getConfigFile() {
|
||||
return this.getHandle().getConfigFile();
|
||||
return ((LoadableConfig) this.getHandle()).getConfigFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getHandle().getName();
|
||||
return ((LoadableConfig) this.getHandle()).getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.core.config.updating;
|
||||
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ConfigHandler {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.willfp.eco.core.config.wrapper;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.json.JSONConfig;
|
||||
import com.willfp.eco.core.config.json.LoadableJSONConfig;
|
||||
import com.willfp.eco.core.config.yaml.LoadableYamlConfig;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -21,7 +19,7 @@ public interface ConfigFactory {
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||
*/
|
||||
LoadableYamlConfig createUpdatableYamlConfig(@NotNull String configName,
|
||||
Config createUpdatableYamlConfig(@NotNull String configName,
|
||||
@NotNull EcoPlugin plugin,
|
||||
@NotNull String subDirectoryPath,
|
||||
@NotNull Class<?> source,
|
||||
@@ -36,7 +34,7 @@ public interface ConfigFactory {
|
||||
* @param subDirectoryPath The subdirectory path.
|
||||
* @param source The class that owns the resource.
|
||||
*/
|
||||
LoadableJSONConfig createLoadableJSONConfig(@NotNull String configName,
|
||||
JSONConfig createLoadableJSONConfig(@NotNull String configName,
|
||||
@NotNull EcoPlugin plugin,
|
||||
@NotNull String subDirectoryPath,
|
||||
@NotNull Class<?> source);
|
||||
@@ -49,7 +47,7 @@ public interface ConfigFactory {
|
||||
* @param subDirectoryPath The subdirectory path.
|
||||
* @param source The class that owns the resource.
|
||||
*/
|
||||
LoadableYamlConfig createLoadableYamlConfig(@NotNull String configName,
|
||||
Config createLoadableYamlConfig(@NotNull String configName,
|
||||
@NotNull EcoPlugin plugin,
|
||||
@NotNull String subDirectoryPath,
|
||||
@NotNull Class<?> source);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.core.config.wrapper;
|
||||
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.willfp.eco.core.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
|
||||
public interface LoadableYamlConfig extends Config, LoadableConfig {
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.willfp.eco.core.config.yaml.wrapper.LoadableYamlConfigWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class YamlBaseConfig extends LoadableYamlConfigWrapper {
|
||||
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.willfp.eco.core.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.yaml.wrapper.YamlConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
public class YamlConfig extends YamlConfigWrapper<Config> {
|
||||
public class YamlConfig extends YamlConfigWrapper {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
|
||||
@@ -1,45 +1,48 @@
|
||||
package com.willfp.eco.core.config.yaml.wrapper;
|
||||
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
import com.willfp.eco.core.config.yaml.LoadableYamlConfig;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class LoadableYamlConfigWrapper extends YamlConfigWrapper<LoadableYamlConfig> implements LoadableConfig {
|
||||
public abstract class LoadableYamlConfigWrapper extends YamlConfigWrapper implements LoadableConfig {
|
||||
/**
|
||||
* Create a config wrapper.
|
||||
*
|
||||
* @param handle The handle.
|
||||
*/
|
||||
public LoadableYamlConfigWrapper(@NotNull final LoadableYamlConfig handle) {
|
||||
protected LoadableYamlConfigWrapper(@NotNull final Config handle) {
|
||||
super(handle);
|
||||
|
||||
Validate.isTrue(handle instanceof LoadableConfig, "Wrapped config must be loadable!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void createFile() {
|
||||
this.getHandle().createFile();
|
||||
((LoadableConfig) this.getHandle()).createFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
return this.getHandle().getResourcePath();
|
||||
return ((LoadableConfig) this.getHandle()).getResourcePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
this.getHandle().save();
|
||||
((LoadableConfig) this.getHandle()).save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getConfigFile() {
|
||||
return this.getHandle().getConfigFile();
|
||||
return ((LoadableConfig) this.getHandle()).getConfigFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getHandle().getName();
|
||||
return ((LoadableConfig) this.getHandle()).getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.willfp.eco.core.config.yaml.wrapper;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public interface WrappedYamlBukkitConfig<T extends ConfigurationSection> {
|
||||
/**
|
||||
* Get the ConfigurationSection handle.
|
||||
*
|
||||
* @return The handle.
|
||||
*/
|
||||
T getBukkitHandle();
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
package com.willfp.eco.core.config.yaml.wrapper;
|
||||
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.interfaces.WrappedYamlConfiguration;
|
||||
import com.willfp.eco.core.config.wrapper.ConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class YamlConfigWrapper<T extends Config> extends ConfigWrapper<T> implements WrappedYamlBukkitConfig<YamlConfiguration> {
|
||||
public abstract class YamlConfigWrapper extends ConfigWrapper<Config> implements WrappedYamlConfiguration {
|
||||
/**
|
||||
* Create a config wrapper.
|
||||
*
|
||||
* @param handle The handle.
|
||||
*/
|
||||
public YamlConfigWrapper(@NotNull final T handle) {
|
||||
protected YamlConfigWrapper(@NotNull final Config handle) {
|
||||
super(handle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public YamlConfiguration getBukkitHandle() {
|
||||
return (YamlConfiguration) ((WrappedYamlBukkitConfig<?>) this.getHandle()).getBukkitHandle();
|
||||
return ((WrappedYamlConfiguration) this.getHandle()).getBukkitHandle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.willfp.eco.core.data;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.json.JSONConfig;
|
||||
import com.willfp.eco.core.config.json.JsonStaticBaseConfig;
|
||||
import com.willfp.eco.core.config.LoadableConfig;
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.interfaces.JSONConfig;
|
||||
import com.willfp.eco.core.config.json.JSONStaticBaseConfig;
|
||||
import com.willfp.eco.core.config.interfaces.LoadableConfig;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -34,7 +34,7 @@ public class Data {
|
||||
* @param config data.json.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void init(@NotNull final JsonStaticBaseConfig config) {
|
||||
public void init(@NotNull final JSONStaticBaseConfig config) {
|
||||
datafile = config;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user