mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-21 08:11:06 +00:00
Remove dump-resources and allow for ignoring specific resources
This commit is contained in:
@@ -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<String> getIgnoredResources();
|
||||
|
||||
int getProviderCache();
|
||||
}
|
||||
|
||||
@@ -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<String> ignoredResources) {
|
||||
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
||||
if(resourcesConfig == null) {
|
||||
logger.info("No resources config found. Skipping resource dumping.");
|
||||
@@ -301,6 +298,9 @@ public abstract class AbstractPlatform implements Platform {
|
||||
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
||||
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
||||
String resourceClassPath = dir + "/" + entry;
|
||||
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())
|
||||
@@ -338,7 +338,7 @@ public abstract class AbstractPlatform implements Platform {
|
||||
resourcePath);
|
||||
}
|
||||
|
||||
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
||||
logger.info("Dumping resource {}.", resource.getAbsolutePath());
|
||||
resource.getParentFile().mkdirs();
|
||||
resource.createNewFile();
|
||||
try(OutputStream os = new FileOutputStream(resource)) {
|
||||
@@ -347,6 +347,7 @@ public abstract class AbstractPlatform implements Platform {
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch(IOException e) {
|
||||
logger.error("Error while dumping resources...", e);
|
||||
|
||||
+9
-7
@@ -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<String> 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<String> getIgnoredResources() {
|
||||
return ignoredResources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxRecursion() {
|
||||
return maxRecursion;
|
||||
|
||||
@@ -10,7 +10,6 @@ debug:
|
||||
log: false
|
||||
profiler: false
|
||||
script: false
|
||||
dump-default: true
|
||||
biome-search-resolution: 4
|
||||
cache:
|
||||
structure: 32
|
||||
@@ -18,3 +17,6 @@ cache:
|
||||
biome-provider: 32
|
||||
script:
|
||||
max-recursion: 1000
|
||||
ignored-resources:
|
||||
# - "addons"
|
||||
# - "packs"
|
||||
Reference in New Issue
Block a user