diff --git a/common/api/src/main/java/com/dfsek/terra/api/config/PluginConfig.java b/common/api/src/main/java/com/dfsek/terra/api/config/PluginConfig.java index 7946d0ec9..62919f12d 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/config/PluginConfig.java +++ b/common/api/src/main/java/com/dfsek/terra/api/config/PluginConfig.java @@ -9,12 +9,12 @@ package com.dfsek.terra.api.config; import com.dfsek.terra.api.Platform; +import java.util.List; + public interface PluginConfig { void load(Platform platform); - boolean dumpDefaultConfig(); - boolean isDebugCommands(); boolean isDebugProfiler(); @@ -31,5 +31,7 @@ public interface PluginConfig { int getMaxRecursion(); + List getIgnoredResources(); + int getProviderCache(); } diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/AbstractPlatform.java b/common/implementation/base/src/main/java/com/dfsek/terra/AbstractPlatform.java index 1ea3fc88b..6637201fe 100644 --- a/common/implementation/base/src/main/java/com/dfsek/terra/AbstractPlatform.java +++ b/common/implementation/base/src/main/java/com/dfsek/terra/AbstractPlatform.java @@ -143,11 +143,8 @@ public abstract class AbstractPlatform implements Platform { config.load(this); // load config.yml - if(config.dumpDefaultConfig()) { - dumpResources(); - } else { - logger.info("Skipping resource dumping."); - } + + dumpResources(config.getIgnoredResources()); if(config.isDebugProfiler()) { // if debug.profiler is enabled, start profiling profiler.start(); @@ -259,7 +256,7 @@ public abstract class AbstractPlatform implements Platform { return internalAddon; } - protected void dumpResources() { + protected void dumpResources(List ignoredResources) { try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) { if(resourcesConfig == null) { logger.info("No resources config found. Skipping resource dumping."); @@ -301,51 +298,55 @@ public abstract class AbstractPlatform implements Platform { Map> resources = new Yaml().load(resourceYaml); resources.forEach((dir, entries) -> entries.forEach(entry -> { String resourceClassPath = dir + "/" + entry; - String resourcePath = resourceClassPath.replace('/', File.separatorChar); - File resource = new File(getDataFolder(), resourcePath); - if(resource.exists()) - return; // dont overwrite + if (ignoredResources.contains(dir) || ignoredResources.contains(entry) || ignoredResources.contains(resourceClassPath)) { + logger.info("Not dumping resource {} because it is ignored.", resourceClassPath); + } else { + String resourcePath = resourceClassPath.replace('/', File.separatorChar); + File resource = new File(getDataFolder(), resourcePath); + if(resource.exists()) + return; // dont overwrite - try(InputStream is = getClass().getResourceAsStream("/" + resourceClassPath)) { - if(is == null) { - logger.error("Resource {} doesn't exist on the classpath!", resourcePath); - return; + try(InputStream is = getClass().getResourceAsStream("/" + resourceClassPath)) { + if(is == null) { + logger.error("Resource {} doesn't exist on the classpath!", resourcePath); + return; + } + + paths + .stream() + .filter(Pair.testRight(resourcePath::startsWith)) + .forEach(Pair.consumeLeft(path -> { + logger.info("Removing outdated resource {}, replacing with {}", path, resourcePath); + try { + Files.delete(path); + } catch(IOException e) { + throw new UncheckedIOException(e); + } + })); + + if(pathsNoMajor + .stream() + .anyMatch(resourcePath::startsWith) && // if any share name + paths + .stream() + .map(Pair.unwrapRight()) + .noneMatch(resourcePath::startsWith)) { // but dont share major version + logger.warn( + "Addon {} has a new major version available. It will not be automatically updated; you will need to " + + "ensure " + + "compatibility and update manually.", + resourcePath); + } + + logger.info("Dumping resource {}.", resource.getAbsolutePath()); + resource.getParentFile().mkdirs(); + resource.createNewFile(); + try(OutputStream os = new FileOutputStream(resource)) { + IOUtils.copy(is, os); + } + } catch(IOException e) { + throw new UncheckedIOException(e); } - - paths - .stream() - .filter(Pair.testRight(resourcePath::startsWith)) - .forEach(Pair.consumeLeft(path -> { - logger.info("Removing outdated resource {}, replacing with {}", path, resourcePath); - try { - Files.delete(path); - } catch(IOException e) { - throw new UncheckedIOException(e); - } - })); - - if(pathsNoMajor - .stream() - .anyMatch(resourcePath::startsWith) && // if any share name - paths - .stream() - .map(Pair.unwrapRight()) - .noneMatch(resourcePath::startsWith)) { // but dont share major version - logger.warn( - "Addon {} has a new major version available. It will not be automatically updated; you will need to " + - "ensure " + - "compatibility and update manually.", - resourcePath); - } - - logger.info("Dumping resource {}...", resource.getAbsolutePath()); - resource.getParentFile().mkdirs(); - resource.createNewFile(); - try(OutputStream os = new FileOutputStream(resource)) { - IOUtils.copy(is, os); - } - } catch(IOException e) { - throw new UncheckedIOException(e); } })); } catch(IOException e) { diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java b/common/implementation/base/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java index d22c2945f..b63b09eef 100644 --- a/common/implementation/base/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java +++ b/common/implementation/base/src/main/java/com/dfsek/terra/config/PluginConfigImpl.java @@ -30,6 +30,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.UncheckedIOException; +import java.util.Collections; +import java.util.List; import com.dfsek.terra.api.Platform; import com.dfsek.terra.api.config.PluginConfig; @@ -71,9 +73,9 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig { @Default private int providerCache = 32; - @Value("dump-default") + @Value("ignored-resources") @Default - private boolean dumpDefaultData = true; + private List ignoredResources = Collections.emptyList(); @Value("script.max-recursion") @Default @@ -99,11 +101,6 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig { logger.info("Debug logging enabled."); } - @Override - public boolean dumpDefaultConfig() { - return dumpDefaultData; - } - @Override public boolean isDebugCommands() { return debugCommands; @@ -139,6 +136,11 @@ public class PluginConfigImpl implements ConfigTemplate, PluginConfig { return samplerCache; } + @Override + public List getIgnoredResources() { + return ignoredResources; + } + @Override public int getMaxRecursion() { return maxRecursion; diff --git a/common/implementation/base/src/main/resources/config.yml b/common/implementation/base/src/main/resources/config.yml index 72dd67061..ae2f6c2a8 100644 --- a/common/implementation/base/src/main/resources/config.yml +++ b/common/implementation/base/src/main/resources/config.yml @@ -10,11 +10,13 @@ debug: log: false profiler: false script: false -dump-default: true biome-search-resolution: 4 cache: structure: 32 sampler: 128 biome-provider: 32 script: - max-recursion: 1000 \ No newline at end of file + max-recursion: 1000 +ignored-resources: +# - "addons" +# - "packs" \ No newline at end of file