forked from WolvesFortress/HyghtmapMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
346 lines (300 loc) · 14 KB
/
build.gradle
File metadata and controls
346 lines (300 loc) · 14 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
plugins {
id 'java'
id 'com.gradleup.shadow' version '8.3.0'
}
group = 'net.wolvesfortress.heightmap'
version = '1.0.0'
repositories {
mavenCentral()
// Official Hytale Maven repository
maven {
name = 'hytale-release'
url = 'https://maven.hytale.com/release'
}
maven {
name = 'hytale-pre-release'
url = 'https://maven.hytale.com/pre-release'
}
}
dependencies {
// Hytale Server API from official Maven repository
compileOnly 'com.hypixel.hytale:Server:2026.02.19-1a311a592'
// JSR305 annotations (@Nonnull, @Nullable)
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'com.google.code.gson:gson:2.10.1'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(25)
}
}
shadowJar {
archiveClassifier.set('')
// Exclude server classes from the final JAR
dependencies {
exclude(dependency { it.moduleGroup == 'com.hypixel' })
}
}
// Disable the default jar task to avoid conflicts with shadowJar
tasks.named('jar') {
enabled = false
}
tasks.named('build') {
dependsOn shadowJar
}
// Deploy plugin JAR to server mods folder
tasks.register('deployToServer', Copy) {
// Using 'from shadowJar' automatically adds task dependency and proper input tracking
from shadowJar
into 'server/mods'
doLast {
println "Deployed to server/mods/"
}
}
// Watch for changes and auto-rebuild (useful during development)
tasks.register('watch') {
doLast {
println "Watching for changes... Press Ctrl+C to stop."
println "Run 'gradle build --continuous' for auto-rebuild on file changes."
}
}
// ── API Reference Generation ────────────────────────────────────────────────
// Run: ./gradlew apiRef
// Uses HytaleServer.jar to generate plain-text API reference files
// in .hytale-api/ for quick lookup during development.
configurations {
apiDump
}
dependencies {
apiDump 'org.ow2.asm:asm:9.7.1'
apiDump 'org.ow2.asm:asm-tree:9.7.1'
}
tasks.register('dumpServerApi') {
description = 'Generates text-based API reference from libs/HytaleServer.jar'
group = 'api-reference'
def serverJar = file('libs/HytaleServer.jar')
def outputDir = file('.hytale-api')
inputs.file(serverJar)
outputs.dir(outputDir)
doLast {
// Load ASM via the apiDump configuration
def asmUrls = configurations.apiDump.files.collect { it.toURI().toURL() } as URL[]
def asmLoader = new URLClassLoader(asmUrls, getClass().classLoader)
def ClassReader = asmLoader.loadClass('org.objectweb.asm.ClassReader')
def ClassNode = asmLoader.loadClass('org.objectweb.asm.tree.ClassNode')
// ── Helper closures ─────────────────────────────────────────────
def descriptorToType = { String desc ->
int arrayDim = 0
def d = desc
while (d.startsWith('[')) { arrayDim++; d = d.substring(1) }
def base
switch (d) {
case 'V': base = 'void'; break
case 'Z': base = 'boolean'; break
case 'B': base = 'byte'; break
case 'C': base = 'char'; break
case 'S': base = 'short'; break
case 'I': base = 'int'; break
case 'J': base = 'long'; break
case 'F': base = 'float'; break
case 'D': base = 'double'; break
default:
if (d.startsWith('L') && d.endsWith(';')) {
base = d.substring(1, d.length() - 1).replace('/', '.')
} else {
base = d
}
}
return base + ('[]' * arrayDim)
}
def accessToString = { int access ->
def parts = []
if ((access & 0x0001) != 0) parts.add('public')
else if ((access & 0x0004) != 0) parts.add('protected')
else if ((access & 0x0002) != 0) parts.add('private')
if ((access & 0x0008) != 0) parts.add('static')
if ((access & 0x0010) != 0) parts.add('final')
if ((access & 0x0400) != 0) parts.add('abstract')
return parts.join(' ')
}
def getClassKind = { node ->
int access = node.access
if ((access & 0x2000) != 0) return '@interface' // ACC_ANNOTATION
if ((access & 0x4000) != 0) return 'enum' // ACC_ENUM
if ((access & 0x0200) != 0) return 'interface' // ACC_INTERFACE
if ((access & 0x0400) != 0) return 'abstract class'
return 'class'
}
def parseMethodParams = { String descriptor ->
def params = []
def d = descriptor.substring(1) // skip '('
while (!d.startsWith(')')) {
int arrayDim = 0
while (d.startsWith('[')) { arrayDim++; d = d.substring(1) }
if (d.startsWith('L')) {
int end = d.indexOf(';')
params.add(d.substring(1, end).replace('/', '.') + ('[]' * arrayDim))
d = d.substring(end + 1)
} else {
def base
switch (d.charAt(0)) {
case 'Z': base = 'boolean'; break
case 'B': base = 'byte'; break
case 'C': base = 'char'; break
case 'S': base = 'short'; break
case 'I': base = 'int'; break
case 'J': base = 'long'; break
case 'F': base = 'float'; break
case 'D': base = 'double'; break
default: base = String.valueOf(d.charAt(0))
}
params.add(base + ('[]' * arrayDim))
d = d.substring(1)
}
}
return params
}
def getReturnType = { String descriptor ->
descriptorToType(descriptor.substring(descriptor.indexOf(')') + 1))
}
def getParamNames = { methodNode, int paramCount ->
def localVars = methodNode.localVariables
if (localVars) {
def isStatic = (methodNode.access & 0x0008) != 0
def startIdx = isStatic ? 0 : 1
def paramVars = localVars.findAll { it.index >= startIdx && it.index < startIdx + paramCount }
.sort { it.index }
if (paramVars.size() == paramCount) {
return paramVars.collect { it.name }
}
}
return (0..<paramCount).collect { "arg${it}" }
}
// ── Read all classes from the jar ───────────────────────────────
def classes = []
new java.util.jar.JarFile(serverJar).withCloseable { jar ->
jar.entries().each { entry ->
if (entry.name.endsWith('.class') && !entry.name.startsWith('META-INF/')) {
try {
jar.getInputStream(entry).withStream { is ->
def reader = ClassReader.getConstructor(InputStream).newInstance(is)
def node = ClassNode.getDeclaredConstructor().newInstance()
reader.invokeMethod('accept', [node, 0] as Object[])
if (node.name.startsWith('com/hypixel/hytale/')) {
classes.add(node)
}
}
} catch (Exception e) {
// Skip unreadable classes
}
}
}
}
println "Found ${classes.size()} classes in com.hypixel.hytale namespace"
// ── Clean and prepare output directory ──────────────────────────
if (outputDir.exists()) outputDir.deleteDir()
outputDir.mkdirs()
// ── Group by top-level subpackage ───────────────────────────────
def grouped = classes.groupBy { node ->
def parts = node.name.split('/')
parts.length >= 4 ? parts[3] : '_root'
}
// ── Write per-group files ───────────────────────────────────────
grouped.each { groupName, groupClasses ->
def outFile = new File(outputDir, "${groupName}.txt")
outFile.withWriter('UTF-8') { writer ->
writer.writeLine("# Hytale Server API: com.hypixel.hytale.${groupName}")
writer.writeLine("# Generated from HytaleServer.jar")
writer.writeLine("")
groupClasses.sort { it.name }.each { node ->
def className = node.name.replace('/', '.')
def shortName = className.substring(className.lastIndexOf('.') + 1)
// Skip anonymous inner classes
if (shortName.matches('.*\\$\\d+$')) return
def packageName = className.substring(0, className.lastIndexOf('.'))
def kind = getClassKind(node)
// Strip 'abstract' from access — already captured in kind ("abstract class")
def accessStr = accessToString(node.access).replace('abstract ', '').trim()
writer.writeLine('=' * 80)
writer.writeLine("package ${packageName}")
writer.writeLine("${accessStr} ${kind} ${shortName}")
if (node.superName && node.superName != 'java/lang/Object') {
writer.writeLine(" extends ${node.superName.replace('/', '.')}")
}
if (node.interfaces && !node.interfaces.isEmpty()) {
def keyword = (node.access & 0x0200) != 0 ? 'extends' : 'implements'
writer.writeLine(" ${keyword} ${node.interfaces.collect { it.replace('/', '.') }.join(', ')}")
}
writer.writeLine("")
// Enum constants
if ((node.access & 0x4000) != 0) {
def enumConsts = node.fields?.findAll { (it.access & 0x4000) != 0 }
if (enumConsts) {
writer.writeLine(" // Enum constants:")
enumConsts.each { f -> writer.writeLine(" ${f.name}") }
writer.writeLine("")
}
}
// Fields (non-enum, non-synthetic)
def fields = node.fields?.findAll { f ->
(f.access & 0x4000) == 0 && (f.access & 0x1000) == 0
}
if (fields) {
writer.writeLine(" // Fields:")
fields.each { f ->
writer.writeLine(" ${accessToString(f.access)} ${descriptorToType(f.desc)} ${f.name}")
}
writer.writeLine("")
}
// Constructors
def ctors = node.methods?.findAll { it.name == '<init>' && (it.access & 0x1000) == 0 }
if (ctors) {
writer.writeLine(" // Constructors:")
ctors.each { m ->
def params = parseMethodParams(m.desc)
def names = getParamNames(m, params.size())
def paramStr = params.withIndex().collect { type, i -> "${type} ${names[i]}" }.join(', ')
writer.writeLine(" ${accessToString(m.access)} ${shortName}(${paramStr})")
}
writer.writeLine("")
}
// Methods (non-init, non-synthetic, non-bridge)
def methods = node.methods?.findAll { m ->
m.name != '<init>' && m.name != '<clinit>' &&
(m.access & 0x1000) == 0 && (m.access & 0x0040) == 0
}
if (methods) {
writer.writeLine(" // Methods:")
methods.sort { it.name }.each { m ->
def ret = getReturnType(m.desc)
def params = parseMethodParams(m.desc)
def names = getParamNames(m, params.size())
def paramStr = params.withIndex().collect { type, i -> "${type} ${names[i]}" }.join(', ')
writer.writeLine(" ${accessToString(m.access)} ${ret} ${m.name}(${paramStr})")
}
writer.writeLine("")
}
writer.writeLine("")
}
}
println " ${outFile.name}: ${groupClasses.size()} classes"
}
// ── Master index ────────────────────────────────────────────────
def indexFile = new File(outputDir, '_index.txt')
indexFile.withWriter('UTF-8') { writer ->
writer.writeLine("# Hytale Server API Index")
writer.writeLine("# Total classes: ${classes.size()}")
writer.writeLine("")
classes.sort { it.name }.each { node ->
writer.writeLine("${getClassKind(node)} ${node.name.replace('/', '.')}")
}
}
println "API reference generated in ${outputDir}/ (${classes.size()} classes)"
}
}
// Convenience alias
tasks.register('apiRef') {
description = 'Use server jar and generate API reference'
group = 'api-reference'
dependsOn 'dumpServerApi'
}