generated from TeamKun/PaperPluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
127 lines (110 loc) · 4.16 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.util.stream.Collectors
plugins {
id "java"
id "com.github.johnrengelman.shadow" version "7.1.2"
}
group = "net.kunmc.lab"
version = "1.1.1"
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://papermc.io/repo/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven { url = "https://repo.dmulloy2.net/repository/public/" }
maven { url = 'https://jitpack.io' }
flatDir { dirs "server/cache", "libs" }
}
dependencies {
compileOnly "com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT"
//compileOnly "com.comphenix.protocol:ProtocolLib:4.7.0"
compileOnly name: "patched_1.16.5"
implementation 'com.github.TeamKun.CommandLib:bukkit:0.13.0'
implementation 'com.github.TeamKun.ConfigLib:bukkit:0.18.1'
}
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
}
}
shadowJar {
archiveFileName = "${rootProject.name}-${project.version}.jar"
relocate "net.kunmc.lab.commandlib", "${project.group}.${project.name.toLowerCase()}.commandlib"
relocate "net.kunmc.lab.configlib", "${project.group}.${project.name.toLowerCase()}.configlib"
}
tasks.build.dependsOn tasks.shadowJar
processResources {
def props = [name: rootProject.name, version: version, MainClass: getMainClassFQDN(projectDir.toPath())]
inputs.properties props
filteringCharset "UTF-8"
filesMatching("plugin.yml") {
expand props
}
}
task copyToServer(group: "copy", type: Copy) {
mustRunAfter build
from new File(buildDir.absolutePath, "libs/${rootProject.name}-${version}.jar")
into "./server/plugins"
}
task copyProtocolLibToServer(group: "copy", type: Copy) {
File file = configurations.compileClasspath.getFiles().stream()
.filter(x -> x.getName().matches(".*ProtocolLib.*.jar"))
.findFirst().orElse(null)
if (file != null) {
from file
into "server/plugins"
}
}
task buildAndCopy(group: "build") {
dependsOn build, copyToServer
}
task downloadServerJar {
URL url = new URL("https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/794/downloads/paper-1.16.5-794.jar ")
File file = new File(projectDir.toPath().toAbsolutePath().toString() + "/server/server.jar")
if (!file.exists()) {
try (InputStream stream = url.openStream()) {
Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
}
}
task generatePatchedJar(group: "setup", dependsOn: downloadServerJar) {
String serverDir = projectDir.toPath().toAbsolutePath().toString() + "/server"
File file = new File(serverDir + "/cache/patched_1.16.5.jar")
if (file.exists()) {
return
}
try {
Runtime runtime = Runtime.getRuntime()
Process p = runtime.exec("java -jar " + serverDir + "/server.jar nogui", new String[0], new File(serverDir))
p.waitFor()
p.destroy()
} catch (Exception e) {
e.printStackTrace()
}
}
static String getMainClassFQDN(Path projectPath) {
List<Path> javaFileList = Files.walk(projectPath)
.filter(x -> x.getFileName().toString().endsWith(".java"))
.collect(Collectors.toList())
Path mainClassFile = javaFileList.stream()
.filter(path -> Files.lines(path).anyMatch(str -> str.contains("extends JavaPlugin")))
.findFirst().get()
return mainClassFile.toString().replace("\\", ".").replace("/", ".").replaceAll(".*src.main.java.|.java\$", "")
}