mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Package default config, update README.md
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.failsafe.FailType;
|
||||
@@ -11,14 +12,20 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.polydev.gaea.util.JarUtil.copyResourcesToDirectory;
|
||||
|
||||
public final class ConfigUtil {
|
||||
public static boolean debug;
|
||||
public static long dataSave; // Period of population data saving, in ticks.
|
||||
@@ -34,6 +41,17 @@ public final class ConfigUtil {
|
||||
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis()/20L;
|
||||
masterDisableCaves = config.getBoolean("master-disable.caves", false);
|
||||
|
||||
if(config.getBoolean("dump-default", true)) {
|
||||
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
copyResourcesToDirectory(jar, "default-config", new File(main.getDataFolder(), "packs" + File.separator + "default").toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
Debug.error("Failed to dump default config files!");
|
||||
e.printStackTrace();
|
||||
Debug.error("Report this to Terra!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String fail = config.getString("fail-type", "SHUTDOWN");
|
||||
try {
|
||||
failType = FailType.valueOf(fail);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TreeConfig extends TerraConfig implements Tree {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location, Random random, boolean b, JavaPlugin javaPlugin) {
|
||||
public boolean plant(Location location, Random random, JavaPlugin javaPlugin) {
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
Structure struc = structure.get(random);
|
||||
|
||||
@@ -8,16 +8,14 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.polydev.gaea.lang.Language;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.polydev.gaea.util.JarUtil.copyResourcesToDirectory;
|
||||
|
||||
public final class LangUtil {
|
||||
private static Language language;
|
||||
private static Logger logger;
|
||||
@@ -25,7 +23,7 @@ public final class LangUtil {
|
||||
logger = main.getLogger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
copyResourcesToDirectory(jar, file.toString());
|
||||
copyResourcesToDirectory(jar, "lang", file.toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
Debug.error("Failed to dump language files!");
|
||||
e.printStackTrace();
|
||||
@@ -39,31 +37,6 @@ public final class LangUtil {
|
||||
logger.severe("Double-check your configuration before reporting this to Terra!");
|
||||
}
|
||||
}
|
||||
private static void copyResourcesToDirectory(JarFile fromJar, String destDir) throws IOException {
|
||||
for(Enumeration<JarEntry> entries = fromJar.entries(); entries.hasMoreElements(); ) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
if(entry.getName().startsWith("lang" + "/") && ! entry.isDirectory()) {
|
||||
File dest = new File(destDir + File.separator + entry.getName().substring("lang".length() + 1));
|
||||
Debug.info("Output: " + dest.toString());
|
||||
if(dest.exists()) continue;
|
||||
File parent = dest.getParentFile();
|
||||
if(parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
Debug.info("Output does not already exist. Creating... ");
|
||||
try(FileOutputStream out = new FileOutputStream(dest); InputStream in = fromJar.getInputStream(entry)) {
|
||||
byte[] buffer = new byte[8 * 1024];
|
||||
|
||||
int s;
|
||||
while((s = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, s);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new IOException("Could not copy asset from jar file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Language getLanguage() {
|
||||
return language;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if(!range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
return tree.plant(block.getLocation(), random, false, Terra.getInstance());
|
||||
return tree.plant(block.getLocation(), random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user