Merge pull request #10 from solonovamax/resources

Download configs from online
This commit is contained in:
dfsek 2020-11-12 17:13:45 -07:00 committed by GitHub
commit 9b6536d76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 20 deletions

View File

@ -5,9 +5,12 @@ import java.nio.channels.Channels
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.nio.file.StandardCopyOption import java.nio.file.StandardCopyOption
//import java.util.zip.ZipFile
import java.util.zip.ZipInputStream
plugins { plugins {
java java
maven
id("com.github.johnrengelman.shadow").version("6.1.0") id("com.github.johnrengelman.shadow").version("6.1.0")
} }
@ -19,6 +22,7 @@ repositories {
maven { url = uri("http://maven.enginehub.org/repo/") } maven { url = uri("http://maven.enginehub.org/repo/") }
maven { url = uri("https://repo.codemc.org/repository/maven-public") } maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven { url = uri("https://papermc.io/repo/repository/maven-public/") } maven { url = uri("https://papermc.io/repo/repository/maven-public/") }
// maven { url = uri("https://maven.pkg.github.com/solonovamax/Gaea") }
} }
java { java {
@ -26,14 +30,17 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
val versionObj = Version("1", "3", "0", "BETA") val versionObj = Version("1", "3", "1", true)
version = versionObj version = versionObj
dependencies { dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT") // compileOnly("org.polydev.gaea:gaea:1.14.2-github-actions+9d59b49")
compileOnly("org.jetbrains:annotations:20.1.0") // more recent.
implementation("commons-io:commons-io:2.4")
compileOnly(name = "Gaea-1.14.2", group = "") compileOnly(name = "Gaea-1.14.2", group = "")
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:20.1.0")
implementation("commons-io:commons-io:2.4")
implementation("org.apache.commons:commons-imaging:1.0-alpha2") implementation("org.apache.commons:commons-imaging:1.0-alpha2")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT") compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:1.7") implementation("org.bstats:bstats-bukkit:1.7")
@ -46,21 +53,20 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation(name = "Gaea-1.14.2", group = "") testImplementation(name = "Gaea-1.14.2", group = "")
testImplementation("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
} }
val compileJava: JavaCompile by tasks val compileJava: JavaCompile by tasks
compileJava.apply { compileJava.apply {
options.encoding = "UTF-8" options.encoding = "UTF-8"
doFirst { doFirst {
options.compilerArgs = mutableListOf("-Xlint:all", "-Xlint:-processing") options.compilerArgs = mutableListOf("-Xlint:all")
} }
} }
tasks.test { tasks.test {
useJUnitPlatform() useJUnitPlatform()
maxHeapSize = "1G" maxHeapSize = "4G"
ignoreFailures = false ignoreFailures = false
failFast = true failFast = true
maxParallelForks = 12 maxParallelForks = 12
@ -102,6 +108,22 @@ val setupServer = tasks.create("setupServer") {
} }
} }
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
doFirst {
// Downloading latest paper jar.
// if (file("${buildDir}/resources/main/packs/default").exists() && file("${buildDir}/resources/main/packs/nether").exists())
// return@doFirst
// else
file("${buildDir}/resources/main/packs/").deleteRecursively()
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
downloadAndUnzipPack(defaultPackUrl)
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
downloadAndUnzipPack(netherPackUrl)
}
}
tasks.processResources.get().dependsOn(downloadDefaultPacks)
val testWithPaper = task<JavaExec>(name = "testWithPaper") { val testWithPaper = task<JavaExec>(name = "testWithPaper") {
standardInput = System.`in` standardInput = System.`in`
dependsOn(tasks.shadowJar) dependsOn(tasks.shadowJar)
@ -151,13 +173,13 @@ tasks.build {
* Version class that does version stuff. * Version class that does version stuff.
*/ */
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
class Version(val major: String, val minor: String, val revision: String, val preReleaseData: String? = null) { class Version(val major: String, val minor: String, val revision: String, val preRelease: Boolean = false) {
override fun toString(): String { override fun toString(): String {
return if (preReleaseData.isNullOrBlank()) return if (!preRelease)
"$major.$minor.$revision" "$major.$minor.$revision"
else //Only use git hash if it's a prerelease. else //Only use git hash if it's a prerelease.
"$major.$minor.$revision-$preReleaseData+${getGitHash()}" "$major.$minor.$revision-BETA+${getGitHash()}"
} }
} }
@ -177,3 +199,17 @@ fun gitClone(name: String) {
standardOutput = stdout standardOutput = stdout
} }
} }
fun downloadAndUnzipPack(packUrl: URL) {
ZipInputStream(packUrl.openStream()).use { zip ->
while (true) {
val entry = zip.nextEntry ?: break
if (entry.isDirectory)
file("${buildDir}/resources/main/packs/${entry.name}").mkdirs()
else
file("${buildDir}/resources/main/packs/${entry.name}").outputStream().use { output ->
output.write(zip.readBytes())
}
}
}
}

View File

@ -12,6 +12,7 @@ import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.polydev.gaea.util.JarUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -25,8 +26,6 @@ import java.util.jar.JarFile;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import static org.polydev.gaea.util.JarUtil.copyResourcesToDirectory;
public final class ConfigUtil { public final class ConfigUtil {
public static boolean debug; public static boolean debug;
public static long dataSave; // Period of population data saving, in ticks. public static long dataSave; // Period of population data saving, in ticks.
@ -47,7 +46,7 @@ public final class ConfigUtil {
if(config.getBoolean("dump-default", true)) { if(config.getBoolean("dump-default", true)) {
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) { 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()); JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
} catch(IOException | URISyntaxException e) { } catch(IOException | URISyntaxException e) {
Debug.error("Failed to dump default config files!"); Debug.error("Failed to dump default config files!");
e.printStackTrace(); e.printStackTrace();