mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
dump resources in separate method
This commit is contained in:
parent
f7d53c9db3
commit
b4a4d7e377
@ -125,36 +125,7 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
config.load(this); // load config.yml
|
config.load(this); // load config.yml
|
||||||
|
|
||||||
if(config.dumpDefaultConfig()) {
|
if(config.dumpDefaultConfig()) {
|
||||||
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
dumpResources();
|
||||||
if(resourcesConfig == null) {
|
|
||||||
logger.info("No resources config found. Skipping resource dumping.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
|
||||||
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
|
||||||
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
|
||||||
String resourcePath = String.format("%s/%s", dir, entry);
|
|
||||||
File resource = new File(getDataFolder(), resourcePath);
|
|
||||||
if(resource.exists())
|
|
||||||
return; // dont overwrite
|
|
||||||
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
|
||||||
try {
|
|
||||||
resource.getParentFile().mkdirs();
|
|
||||||
resource.createNewFile();
|
|
||||||
} catch(IOException e) {
|
|
||||||
throw new UncheckedIOException(e);
|
|
||||||
}
|
|
||||||
logger.debug("Copying resource {}", resourcePath);
|
|
||||||
try(InputStream is = getClass().getResourceAsStream("/" + resourcePath);
|
|
||||||
OutputStream os = new FileOutputStream(resource)) {
|
|
||||||
IOUtils.copy(is, os);
|
|
||||||
} catch(IOException e) {
|
|
||||||
throw new UncheckedIOException(e);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
} catch(IOException e) {
|
|
||||||
logger.error("Error while dumping resources...", e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.info("Skipping resource dumping.");
|
logger.info("Skipping resource dumping.");
|
||||||
}
|
}
|
||||||
@ -227,6 +198,39 @@ public abstract class AbstractPlatform implements Platform {
|
|||||||
logger.info("Finished initialization.");
|
logger.info("Finished initialization.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void dumpResources() {
|
||||||
|
try(InputStream resourcesConfig = getClass().getResourceAsStream("/resources.yml")) {
|
||||||
|
if(resourcesConfig == null) {
|
||||||
|
logger.info("No resources config found. Skipping resource dumping.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
|
||||||
|
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
|
||||||
|
resources.forEach((dir, entries) -> entries.forEach(entry -> {
|
||||||
|
String resourcePath = String.format("%s/%s", dir, entry);
|
||||||
|
File resource = new File(getDataFolder(), resourcePath);
|
||||||
|
if(resource.exists())
|
||||||
|
return; // dont overwrite
|
||||||
|
logger.info("Dumping resource {}...", resource.getAbsolutePath());
|
||||||
|
try {
|
||||||
|
resource.getParentFile().mkdirs();
|
||||||
|
resource.createNewFile();
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
|
logger.debug("Copying resource {}", resourcePath);
|
||||||
|
try(InputStream is = getClass().getResourceAsStream("/" + resourcePath);
|
||||||
|
OutputStream os = new FileOutputStream(resource)) {
|
||||||
|
IOUtils.copy(is, os);
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} catch(IOException e) {
|
||||||
|
logger.error("Error while dumping resources...", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(TypeRegistry registry) {
|
public void register(TypeRegistry registry) {
|
||||||
loaders.register(registry);
|
loaders.register(registry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user