Finally added eco.yml
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.config.TransientConfig;
|
||||
import com.willfp.eco.core.config.base.ConfigYml;
|
||||
import com.willfp.eco.core.config.base.LangYml;
|
||||
import com.willfp.eco.core.config.updating.ConfigHandler;
|
||||
@@ -152,10 +153,13 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
private final ProxyFactory proxyFactory;
|
||||
|
||||
/**
|
||||
* Create a new plugin without a specified color, proxy support, polymart, or bStats.
|
||||
* Create a new plugin.
|
||||
* <p>
|
||||
* Will read from eco.yml (like plugin.yml) to fetch values that would otherwise be passed
|
||||
* into the constructor.
|
||||
*/
|
||||
protected EcoPlugin() {
|
||||
this("&f");
|
||||
this((EcoPluginProps) null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,6 +240,23 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this(
|
||||
new EcoPluginProps(
|
||||
resourceId,
|
||||
bStatsId,
|
||||
proxyPackage,
|
||||
color,
|
||||
supportingExtensions
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
* @param pluginProps The props. If left null, it will read from eco.yml.
|
||||
*/
|
||||
protected EcoPlugin(@Nullable final EcoPluginProps pluginProps) {
|
||||
/*
|
||||
The handler must be initialized before any plugin's constructors
|
||||
are called, as the constructors call Eco#getHandler().
|
||||
@@ -272,11 +293,15 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
||||
|
||||
assert Eco.getHandler() != null;
|
||||
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
this.supportingExtensions = supportingExtensions;
|
||||
EcoPluginProps props = pluginProps != null ? pluginProps : EcoPluginProps.fromConfig(
|
||||
new TransientConfig(this.getClass().getResourceAsStream("eco.yml"))
|
||||
);
|
||||
|
||||
this.resourceId = props.resourceId();
|
||||
this.bStatsId = props.bStatsId();
|
||||
this.proxyPackage = props.proxyPackage();
|
||||
this.color = props.color();
|
||||
this.supportingExtensions = props.supportingExtensions();
|
||||
|
||||
this.scheduler = Eco.getHandler().createScheduler(this);
|
||||
this.eventManager = Eco.getHandler().createEventManager(this);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public record EcoPluginProps(int resourceId,
|
||||
int bStatsId,
|
||||
@NotNull String proxyPackage,
|
||||
@NotNull String color,
|
||||
boolean supportingExtensions) {
|
||||
/**
|
||||
* The parser for config props.
|
||||
*/
|
||||
private static PropsParser<Config> configParser = null;
|
||||
|
||||
/**
|
||||
* Load props from config.
|
||||
*
|
||||
* @param config The config.
|
||||
* @return The props.
|
||||
*/
|
||||
public static EcoPluginProps fromConfig(@NotNull final Config config) {
|
||||
return configParser.parseFrom(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the parser for eco.yml.
|
||||
*
|
||||
* @param parser The parser.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void setConfigParser(@NotNull final PropsParser<Config> parser) {
|
||||
configParser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse arguments into props for a plugin.
|
||||
*
|
||||
* @param <T> The type of source.
|
||||
*/
|
||||
public interface PropsParser<T> {
|
||||
/**
|
||||
* Parse props from a given source.
|
||||
*
|
||||
* @param source The source.
|
||||
* @return The props.
|
||||
*/
|
||||
EcoPluginProps parseFrom(@NotNull T source);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,10 @@ import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.wrapper.ConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -21,6 +24,15 @@ public class TransientConfig extends ConfigWrapper<Config> {
|
||||
super(Eco.getHandler().getConfigFactory().createConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stream The InputStream.
|
||||
*/
|
||||
public TransientConfig(@Nullable final InputStream stream) {
|
||||
super(stream != null ? Eco.getHandler().getConfigFactory().createConfig(YamlConfiguration.loadConfiguration(
|
||||
new InputStreamReader(stream)
|
||||
)) : new TransientConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new empty transient config.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user