forked from Yu212/paper-mixin-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
69 lines (57 loc) · 2.09 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.nio.file.Files
import java.nio.file.StandardCopyOption
allprojects {
apply plugin: "java"
group "net.kunmc.lab"
version "1.0.0"
def targetJavaVersion = 8
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release = targetJavaVersion
}
}
}
task generatePatchedJar(group: "setup") {
File tmpDir = new File(projectDir.toPath().toAbsolutePath().toString() + "/tmp")
File tmpPatchedJar = new File(tmpDir.toPath().toAbsolutePath().toString() + "/cache/patched_1.16.5.jar")
File serverJar = new File(tmpDir.toPath().toAbsolutePath().toString() + "/tmpserver.jar")
File patchedJar = new File(projectDir.toPath().toAbsolutePath().toString() + "/libs/patched_1.16.5.jar")
if (patchedJar.exists()) {
return
}
tmpDir.mkdir()
URL url = new URL("https://api.papermc.io/v2/projects/paper/versions/1.16.5/builds/790/downloads/paper-1.16.5-790.jar ")
try (InputStream stream = url.openStream()) {
Files.copy(stream, serverJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
try {
Runtime runtime = Runtime.getRuntime()
Process p = runtime.exec("java -jar " + serverJar.toPath().toAbsolutePath().toString() + " nogui", new String[0], tmpDir)
p.waitFor()
p.destroy()
} catch (Exception e) {
e.printStackTrace()
}
Files.copy(tmpPatchedJar.toPath(), patchedJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
delete(tmpDir)
}
static void delete(File file) {
if (!file.exists()) {
return
}
if (file.isDirectory()) {
for (File child : file.listFiles()) {
delete(child)
}
}
file.delete()
}