-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
186 lines (168 loc) · 5.57 KB
/
Copy pathbuild.gradle
File metadata and controls
186 lines (168 loc) · 5.57 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
plugins {
id 'java'
id 'xyz.jpenilla.run-paper' version '2.3.1'
}
group = 'org.SlidrusForeal'
version = '3.1'
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "playpro"
url = "https://maven.playpro.com/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
}
/**
* Single universal JAR (CoreProtect-style):
* - compile against the oldest supported API (1.19)
* - bytecode Java 17 so it runs on 1.19+ JVMs
* - plugin.yml api-version=1.19 so Paper/Folia/Purpur/Spigot 1.19..26.2 all accept the same download
* Newer Paper APIs (GlobalRegionScheduler, etc.) are resolved at runtime via reflection.
*
* Platforms: Paper, Folia, Purpur (Paper fork), Spigot
* Minecraft: 1.19.x, 1.20.x, 1.21.x, 26.1.x, 26.2
*/
dependencies {
// Oldest supported server API — keeps one binary compatible with 1.19..26.2
compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
// Prefer local CoreProtect 24.0 jar shipped in /lib
compileOnly files("lib/CoreProtect-24.0.jar")
}
// Optional compile check against current 26.2 Paper API (does not change the shipped JAR).
configurations {
compileCheck26_2
}
dependencies {
compileCheck26_2("io.papermc.paper:paper-api:26.2.build.123-stable") {
exclude group: 'org.apache.logging.log4j'
exclude group: 'org.slf4j'
}
compileCheck26_2 files("lib/CoreProtect-24.0.jar")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
tasks.named('compileJava', JavaCompile).configure {
options.encoding = 'UTF-8'
// Target Java 17 for 1.19 server compatibility; newer JVMs run this fine.
options.release = 17
}
tasks.named('processResources', Copy).configure {
def props = [
version : version,
apiVersion : '1.19',
foliaSupported: 'true'
]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
tasks.named('jar', Jar).configure {
archiveBaseName.set('ExplosionProtector')
archiveVersion.set(project.version.toString())
// Friendly alias next to the versioned artifact.
doLast {
def out = archiveFile.get().asFile
def alias = new File(out.parentFile, 'ExplosionProtector.jar')
alias.bytes = out.bytes
}
}
tasks.register('printUniversalJar') {
group = 'help'
description = 'Print the universal JAR path'
doLast {
println "Universal JAR: ${tasks.jar.archiveFile.get().asFile}"
println "Alias: ${layout.buildDirectory.get().asFile}/libs/ExplosionProtector.jar"
println "Platforms: Paper, Folia, Purpur, Spigot"
println "Minecraft: 1.19.x, 1.20.x, 1.21.x, 26.1.x, 26.2"
println "CoreProtect: 24.0 API (runtime softdepend, older CP usually still works)"
}
}
tasks.register('compileCheckJava26_2', JavaCompile) {
group = 'verification'
description = 'Compile sources against Paper API 26.2 to verify compatibility'
source = sourceSets.main.java
classpath = configurations.compileCheck26_2
destinationDirectory = layout.buildDirectory.dir('classes/java/check26_2')
options.encoding = 'UTF-8'
options.release = 21
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(25)
}
}
// Folia test server on 26.2 (requires run-paper that understands fill.papermc.io; may need Gradle 8.14+)
runPaper.folia.registerTask()
tasks.named('runFolia').configure {
minecraftVersion('26.2')
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(25)
}
jvmArgs('-Dcom.mojang.eula.agree=true')
}
tasks.register('prepareFoliaRun') {
group = 'application'
description = 'Prepare Folia run directory (EULA, offline-mode, CoreProtect)'
doLast {
def runDir = file('run')
def pluginsDir = new File(runDir, 'plugins')
pluginsDir.mkdirs()
def eula = new File(runDir, 'eula.txt')
eula.text = 'eula=true\n'
def props = new File(runDir, 'server.properties')
if (!props.exists()) {
props.text = '''online-mode=false
gamemode=creative
difficulty=peaceful
spawn-protection=0
max-players=20
motd=ExplosionProtector Folia Test
server-port=25565
level-name=world
allow-flight=true
'''.stripIndent()
} else {
def text = props.getText('UTF-8')
text = text.replaceAll(/(?m)^online-mode=.*/, 'online-mode=false')
if (!text.contains('online-mode=')) {
text += '\nonline-mode=false\n'
}
props.write(text, 'UTF-8')
}
def cpSrc = file('lib/CoreProtect-24.0.jar')
if (cpSrc.exists()) {
copy {
from cpSrc
into pluginsDir
rename { 'CoreProtect.jar' }
}
}
// Ensure plugin config uses protect-first-unknown=false for testing TNT terrain.
def epDir = new File(pluginsDir, 'ExplosionProtector')
epDir.mkdirs()
def cfg = new File(epDir, 'config.yml')
if (!cfg.exists()) {
copy {
from 'src/main/resources/config.yml'
into epDir
}
} else {
def text = cfg.getText('UTF-8')
text = text.replaceAll(/(?m)^protect-first-unknown:.*/, 'protect-first-unknown: false')
cfg.write(text, 'UTF-8')
}
}
}
tasks.named('runFolia').configure {
dependsOn 'prepareFoliaRun', 'jar'
}