-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
357 lines (296 loc) · 15.3 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
357 lines (296 loc) · 15.3 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import java.net.URI
import java.time.LocalDate
plugins {
id("com.gradleup.shadow")
}
val shade: Configuration by configurations.creating
configurations {
implementation.get().extendsFrom(shade)
}
dependencies {
api(project(":api"))
@Suppress("GradleDependency")
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
shade("com.zaxxer:HikariCP:7.0.2")
shade("org.mariadb.jdbc:mariadb-java-client:3.5.8")
compileOnly("org.xerial:sqlite-jdbc:3.53.0.0")
compileOnly("org.geysermc.floodgate:api:2.2.5-SNAPSHOT")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("com.github.brcdev-minecraft:shopgui-api:3.2.0") {
exclude(group = "*")
}
compileOnly("com.palmergames.bukkit.towny:towny:0.102.0.14")
compileOnly("com.bgsoftware:SuperiorSkyblockAPI:2026.1")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
compileOnly("su.nightexpress.coinsengine:CoinsEngine:2.6.0")
compileOnly("com.github.Gypopo:EconomyShopGUI-API:1.9.0")
compileOnly("world.bentobox:bentobox:3.15.0")
compileOnly("su.nightexpress.excellentshop:Core:4.22.0")
compileOnly("dev.aurelium:auraskills-api-bukkit:2.3.12")
compileOnly("pl.minecodes.plots:plugin-api:4.6.2")
compileOnly("fr.maxlego08.shop:zshop-api:3.3.4")
compileOnly("fr.maxlego08.menu:zmenu-api:1.1.1.3")
implementation("com.github.GriefPrevention:GriefPrevention:18.0.0")
implementation("com.github.IncrediblePlugins:LandsAPI:7.25.4")
implementation("com.github.Xyness:SimpleClaimSystem-API:v2.3.4")
implementation("com.github.Xyness:SimpleClaimSystem:1.13.0.2")
implementation("com.github.Zrips:Residence:6.0.0.1") {
exclude(group = "org.bukkit")
}
compileOnly("io.lumine:Mythic-Dist:5.12.0")
compileOnly("com.iridium:IridiumSkyblock:4.1.4")
implementation(platform("com.intellectualsites.bom:bom-newest:1.56"))
compileOnly("com.intellectualsites.plotsquared:plotsquared-core")
compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.5.10")
compileOnly("org.projectlombok:lombok:1.18.46")
annotationProcessor("org.projectlombok:lombok:1.18.46")
implementation("org.bstats:bstats-bukkit:3.2.1")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-nowarn", "-Xlint:-deprecation"))
}
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
// Don't use 'jar' task to build plugin jar, use 'shadowJar' task instead
tasks.jar {
archiveBaseName.set("SmartSpawnerJar")
archiveVersion.set(version.toString())
from(project(":api").sourceSets["main"].output)
from(sourceSets["main"].output)
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}
tasks.shadowJar {
archiveBaseName.set("SmartSpawner")
archiveVersion.set(version.toString())
archiveClassifier.set("")
from(project(":api").sourceSets["main"].output)
configurations = listOf(shade)
relocate("com.zaxxer.hikari", "github.nighter.smartspawner.libs.hikari")
relocate("org.mariadb.jdbc", "github.nighter.smartspawner.libs.mariadb")
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
exclude("META-INF/maven/**")
exclude("META-INF/MANIFEST.MF")
exclude("META-INF/LICENSE*")
exclude("META-INF/NOTICE*")
from(sourceSets["main"].output)
exclude("org/slf4j/**")
mergeServiceFiles()
// destinationDirectory.set(file("C:\\Users\\USER\\Desktop\\TestServer\\plugins"))
}
tasks.build {
dependsOn(tasks.shadowJar)
}
tasks.processResources {
val props = mapOf("version" to version)
inputs.properties(props)
filteringCharset = "UTF-8"
filesMatching(listOf("plugin.yml", "paper-plugin.yml")) {
expand(props)
}
}
tasks.register("generateLanguageChangelog") {
group = "documentation"
description = "Diffs en_US language keys vs the latest GitHub release and prepends a changelog entry."
val changelogFile = project.file("src/main/resources/language/CHANGELOG.txt")
inputs.property("projectVersion", project.version.toString())
outputs.file(changelogFile)
doLast {
val currentVersion = project.version.toString()
val locale = "en_US"
val langFiles = listOf("messages.yml", "gui.yml", "items.yml", "formatting.yml", "command_messages.yml", "hologram.yml")
// ── 1. Fetch latest GitHub release tag ───────────────────────────────
val githubVersion: String = try {
val conn = URI.create(
"https://api.github.com/repos/NighterDevelopment/SmartSpawner/releases/latest"
).toURL().openConnection() as java.net.HttpURLConnection
conn.requestMethod = "GET"
conn.setRequestProperty("Accept", "application/vnd.github.v3+json")
conn.setRequestProperty("User-Agent", "SmartSpawner-Changelog-Bot/1.0")
conn.connectTimeout = 6_000
conn.readTimeout = 6_000
if (conn.responseCode == 200) {
val body = conn.inputStream.bufferedReader().readText()
Regex(""""tag_name"\s*:\s*"v?([^"]+)"""").find(body)
?.groupValues?.get(1) ?: "0.0.0"
} else {
println("[changelog] GitHub API returned HTTP ${conn.responseCode} – skipping.")
return@doLast
}
} catch (e: Exception) {
println("[changelog] ⚠ Cannot reach GitHub API (${e.message}) – skipping changelog update.")
return@doLast
}
// ── 2. Compare versions ──────────────────────────────────────────────
fun parseVer(v: String): List<Int> =
v.removePrefix("v").split(".").map { it.toIntOrNull() ?: 0 }
val cur = parseVer(currentVersion)
val gh = parseVer(githubVersion)
var isNewer = false
for (i in 0 until maxOf(cur.size, gh.size)) {
val a = cur.getOrElse(i) { 0 }
val b = gh.getOrElse(i) { 0 }
if (a > b) { isNewer = true; break }
if (a < b) break
}
if (!isNewer) {
println("[changelog] Up-to-date (build=$currentVersion, github=$githubVersion) – nothing to add.")
return@doLast
}
// ── 3. Guard against duplicates ──────────────────────────────────────
val existing = if (changelogFile.exists()) changelogFile.readText() else ""
if (existing.contains("── v$currentVersion")) {
println("[changelog] Version $currentVersion already present – skipping.")
return@doLast
}
// ── 3b. Resolve the "to" ref: use the version tag if it exists, else main ──
// Tags in this repo have no "v" prefix (e.g. "1.6.2"), so we check
// both the bare version and the v-prefixed form.
val toRef: String = run {
listOf(currentVersion, "v$currentVersion").firstOrNull { tag ->
try {
val tagConn = URI.create(
"https://api.github.com/repos/NighterDevelopment/SmartSpawner/git/refs/tags/$tag"
).toURL().openConnection() as java.net.HttpURLConnection
tagConn.requestMethod = "GET"
tagConn.setRequestProperty("Accept", "application/vnd.github.v3+json")
tagConn.setRequestProperty("User-Agent", "SmartSpawner-Changelog-Bot/1.0")
tagConn.connectTimeout = 6_000
tagConn.readTimeout = 6_000
tagConn.responseCode == 200
} catch (e: Exception) { false }
} ?: "main"
}
println("[changelog] Compare range: $githubVersion...$toRef")
// ── 4. YAML flat-key extractor ───────────────────────────────────────
// Returns map of dotPath → Pair(1-based lineNumber, rawValue)
// Handles comments, blank lines, list items, and block scalars.
fun extractKeys(yaml: String): LinkedHashMap<String, Pair<Int, String>> {
val result = LinkedHashMap<String, Pair<Int, String>>()
// stack entries: indent-level → key-name
val stack = ArrayDeque<Pair<Int, String>>()
var blockScalarIndent = -1 // >=0 while inside a | or > scalar
yaml.lines().forEachIndexed { idx, raw ->
val lineNo = idx + 1
val trimmed = raw.trimStart()
if (trimmed.isEmpty() || trimmed.startsWith('#')) return@forEachIndexed
val indent = raw.length - trimmed.length
// Leaving a block scalar when indentation returns to its level
if (blockScalarIndent >= 0) {
if (indent > blockScalarIndent) return@forEachIndexed
else blockScalarIndent = -1
}
// List items are not individually tracked as keys
if (trimmed.startsWith("- ") || trimmed == "-") return@forEachIndexed
val colonIdx = trimmed.indexOf(':')
if (colonIdx < 0) return@forEachIndexed
val key = trimmed.substring(0, colonIdx).trim()
if (key.isEmpty() || key.startsWith('#')) return@forEachIndexed
var value = trimmed.substring(colonIdx + 1).trim()
// Strip trailing inline comment (only outside quoted values)
if (!value.startsWith('"') && !value.startsWith('\'')) {
val ci = value.indexOf(" #")
if (ci >= 0) value = value.substring(0, ci).trim()
}
// Pop stack entries whose indent >= current level
while (stack.isNotEmpty() && stack.last().first >= indent) stack.removeLast()
val path = if (stack.isEmpty()) key
else stack.joinToString(".") { it.second } + ".$key"
if (value == "|" || value == ">" || value == "|-" || value == ">-"
|| value == "|+" || value == ">+") {
result[path] = lineNo to value
blockScalarIndent = indent
} else {
result[path] = lineNo to value
}
stack.addLast(indent to key)
}
return result
}
// Truncate long values for display
fun truncate(s: String, max: Int = 70) = if (s.length > max) s.take(max) + "…" else s
// ── 5. Fetch the old language files from GitHub and diff ─────────────
fun fetchRaw(tag: String, file: String): String? = try {
val url = "https://raw.githubusercontent.com/NighterDevelopment/" +
"SmartSpawner/$tag/core/src/main/resources/language/$locale/$file"
val conn = URI.create(url).toURL().openConnection() as java.net.HttpURLConnection
conn.requestMethod = "GET"
conn.setRequestProperty("User-Agent", "SmartSpawner-Changelog-Bot/1.0")
conn.connectTimeout = 8_000
conn.readTimeout = 8_000
if (conn.responseCode == 200) conn.inputStream.bufferedReader().readText() else null
} catch (e: Exception) { null }
// Per-file diffs: maps file name → pre-formatted entry lines
val addedPerFile = mutableMapOf<String, List<String>>()
val changedPerFile = mutableMapOf<String, List<String>>()
val removedPerFile = mutableMapOf<String, List<String>>()
for (file in langFiles) {
val oldYaml = fetchRaw(githubVersion, file)
if (oldYaml == null) {
println("[changelog] ⚠ Could not fetch $file @ $githubVersion – skipping diff.")
continue
}
val newFile = project.file("src/main/resources/language/$locale/$file")
if (!newFile.exists()) continue
val oldKeys = extractKeys(oldYaml)
val newKeys = extractKeys(newFile.readText())
val added = newKeys.entries
.filter { it.key !in oldKeys }
.sortedBy { it.key }
.map { (k, e) -> " - $k (L${e.first}): ${truncate(e.second)}" }
val removed = oldKeys.entries
.filter { it.key !in newKeys }
.sortedBy { it.key }
.map { (k, e) -> " - $k (L${e.first}): ${truncate(e.second)}" }
val changed = newKeys.entries
.filter { it.key in oldKeys && oldKeys[it.key]!!.second != it.value.second }
.sortedBy { it.key }
.map { (k, newE) ->
val oldVal = truncate(oldKeys[k]!!.second)
val newVal = truncate(newE.second)
" - $k (L${newE.first}): $oldVal → $newVal"
}
if (added.isNotEmpty()) addedPerFile[file] = added
if (changed.isNotEmpty()) changedPerFile[file] = changed
if (removed.isNotEmpty()) removedPerFile[file] = removed
println("[changelog] $file – +${added.size} ~${changed.size} -${removed.size}")
}
// ── 6. Build the CHANGELOG entry ─────────────────────────────────────
// perFile values are already fully-formatted lines (" - key (Lnn): value")
fun formatSection(label: String, perFile: Map<String, List<String>>): String {
if (perFile.isEmpty()) return " $label:\n (none)"
val sb = StringBuilder(" $label:\n")
for ((file, lines) in perFile) {
sb.appendLine(" $file:")
lines.forEach { sb.appendLine(it) }
}
return sb.toString().trimEnd()
}
val today = LocalDate.now().toString()
val separator = "─".repeat(80 - "── v$currentVersion ($today) ".length)
val newEntry = buildString {
appendLine("── v$currentVersion ($today) $separator")
appendLine()
appendLine(" Summary: Version $currentVersion released – fill in details here.")
appendLine(" Compare: https://github.com/NighterDevelopment/SmartSpawner/compare/$githubVersion...$toRef")
appendLine()
appendLine(formatSection("ADDED", addedPerFile))
appendLine()
appendLine(formatSection("CHANGED", changedPerFile))
appendLine()
appendLine(formatSection("REMOVED", removedPerFile))
appendLine()
}
// ── 7. Insert before the first existing version entry ────────────────
val marker = "\n──"
val updated = if (existing.contains(marker)) {
existing.replaceFirst(marker, "\n$newEntry──")
} else {
"$existing\n$newEntry"
}
changelogFile.writeText(updated)
println("[changelog] ✓ Prepended entry for v$currentVersion into language/CHANGELOG.txt")
}
}