3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-04 23:30:24 +01:00

Move config to assets/viaversion & refactor Config

Config loading is done by the implementing class.
Platforms can now specify the URL of the default config.
Dieser Commit ist enthalten in:
Myles 2017-09-11 13:10:54 +01:00
Ursprung 4a51958da4
Commit 298835be42
6 geänderte Dateien mit 45 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -15,6 +16,8 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig {
public BukkitConfigAPI() {
super(new File(((ViaVersionPlugin) Via.getPlatform()).getDataFolder(), "config.yml"));
// Load config
reloadConfig();
}
@Override
@ -177,6 +180,11 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig {
return getString("reload-disconnect-msg", "Server reload, please rejoin!");
}
@Override
public URL getDefaultConfigURL() {
return BukkitConfigAPI.class.getClassLoader().getResource("assets/viaversion/config.yml");
}
@Override
protected void handleConfig(Map<String, Object> config) {
// Nothing currently

Datei anzeigen

@ -6,6 +6,7 @@ import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
import us.myles.ViaVersion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.*;
public class BungeeConfigAPI extends Config implements ViaVersionConfig {
@ -13,6 +14,13 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig {
public BungeeConfigAPI(File configFile) {
super(new File(configFile, "config.yml"));
// Load config
reloadConfig();
}
@Override
public URL getDefaultConfigURL() {
return BungeeConfigAPI.class.getClassLoader().getResource("assets/viaversion/config.yml");
}
@Override

Datei anzeigen

@ -29,14 +29,21 @@ public abstract class Config implements ConfigurationProvider {
private final File configFile;
private ConcurrentSkipListMap<String, Object> config;
/**
* Create a new Config instance, this will *not* load the config by default.
* To load config see {@link #reloadConfig()}
*
* @param configFile The location of where the config is loaded/saved.
*/
public Config(File configFile) {
this.configFile = configFile;
reloadConfig();
}
public abstract URL getDefaultConfigURL();
public synchronized Map<String, Object> loadConfig(File location) {
List<String> unsupported = getUnsupportedOptions();
URL jarConfigFile = Config.class.getClassLoader().getResource("config.yml");
URL jarConfigFile = getDefaultConfigURL();
try {
commentStore.storeComments(jarConfigFile.openStream());
for (String option : unsupported) {

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
@ -62,7 +63,7 @@ public class SpongePlugin implements ViaPlatform {
// Setup Logger
logger = new LoggerWrapper(container.getLogger());
// Setup Plugin
conf = new SpongeConfigAPI(defaultConfig.getParentFile());
conf = new SpongeConfigAPI(container, defaultConfig.getParentFile());
syncExecutor = game.getScheduler().createSyncExecutor(this);
asyncExecutor = game.getScheduler().createAsyncExecutor(this);
SpongeCommandHandler commandHandler = new SpongeCommandHandler();

Datei anzeigen

@ -1,18 +1,35 @@
package us.myles.ViaVersion.sponge.platform;
import org.spongepowered.api.asset.Asset;
import org.spongepowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class SpongeConfigAPI extends Config implements ViaVersionConfig {
private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers");
private final PluginContainer pluginContainer;
public SpongeConfigAPI(File configFile) {
public SpongeConfigAPI(PluginContainer pluginContainer, File configFile) {
super(new File(configFile, "config.yml"));
this.pluginContainer = pluginContainer;
// Load config
reloadConfig();
}
@Override
public URL getDefaultConfigURL() {
Optional<Asset> config = pluginContainer.getAsset("config.yml");
if (!config.isPresent()) {
throw new IllegalArgumentException("Default config is missing from jar");
}
return config.get().getUrl();
}
@Override