-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
166 lines (143 loc) · 5.12 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
plugins {
id "java"
id "com.gradleup.shadow" version "8.3.5"
}
group = "net.kunmc.lab"
version = "1.0.0"
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
maven {
name = "enginehub-maven"
url = "https://maven.enginehub.org/repo/"
}
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"
// Change targetJavaVersion to 21 or later when using PaperAPI version 1.21 or later
//compileOnly "io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT"
//compileOnly "com.sk89q.worldedit:worldedit-bukkit:latest.release"
//compileOnly "com.sk89q.worldedit:worldedit-core:latest.release"
//compileOnly "com.comphenix.protocol:ProtocolLib:latest.release"
//compileOnly name: "patched_1.16.5"
implementation 'com.github.TeamKun.CommandLib:bukkit:latest.release'
implementation 'com.github.TeamKun.ConfigLib:bukkit:latest.release'
}
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
}
}
jar {
doFirst {
copy {
from '.'
into buildDir.name + '/resources/main/'
include 'LICENSE*'
}
}
}
shadowJar {
mergeServiceFiles()
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: getMainClassFQCN(projectDir.toPath())]
inputs.properties props
filteringCharset "UTF-8"
filesMatching("plugin.yml") {
expand props
}
}
task copyToServer(group: "copy") {
mustRunAfter build
doLast {
copy {
from new File(buildDir.absolutePath, "libs/${rootProject.name}-${version}.jar")
into "./server/plugins"
rename { String fileName ->
fileName.replace("-${version}", "")
}
}
}
}
task copyProtocolLibToServer(group: "copy", type: Copy) {
String fileNamePattern = ".*ProtocolLib.*.jar"
boolean exists = new File("server/plugins/").listFiles(new FilenameFilter() {
@Override
boolean accept(File dir, String name) {
return name.matches(fileNamePattern)
}
})
if (exists) {
return
}
configurations.compileClasspath.getFiles().stream()
.filter(x -> x.getName().matches(fileNamePattern))
.findFirst()
.ifPresent(x -> {
from x
into "server/plugins"
})
}
task buildAndCopy(group: "build") {
dependsOn build, copyToServer
}
task downloadServerJar {
URL url = new URL("https://api.papermc.io/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 getMainClassFQCN(Path projectPath) {
Path mainClassFile = Files.walk(projectPath)
.filter(x -> x.getFileName().toString().endsWith(".java"))
.filter(path -> Files.lines(path).anyMatch(str -> str.contains("extends JavaPlugin")))
.findFirst()
.get()
return mainClassFile.toString().replace("\\", ".").replace("/", ".").replaceAll(".*src.main.java.|.java\$", "")
}