mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-12 15:07:22 +01:00
92 lines
4.0 KiB
Groovy
92 lines
4.0 KiB
Groovy
// Code copied from https://github.com/Shopkeepers/Shopkeepers/tree/master
|
|
|
|
buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
configurations.create('specialSource')
|
|
|
|
dependencies {
|
|
specialSource 'net.md-5:SpecialSource:1.11.4:shaded'
|
|
}
|
|
}
|
|
|
|
// Spigot server code remapping: https://www.spigotmc.org/threads/spigot-bungeecord-1-17-1-17-1.510208/
|
|
// These dependencies and mappings are installed into the local Maven repository when BuildTools builds the Spigot dependencies.
|
|
def gradleCache = new File(System.getProperty("user.home"), '.gradle/caches/modules-2/files-2.1')
|
|
def findInGradleCache = { group, module, version, fileName ->
|
|
def baseDir = new File(gradleCache, "${group}/${module}/${version}")
|
|
|
|
if (!baseDir.exists()) {
|
|
throw new Exception("Failed to resolve ${baseDir} when trying to load ${fileName}. Cache missing");
|
|
}
|
|
|
|
def result = baseDir.listFiles()?.findAll { it.isDirectory() }?.collectMany({ it.listFiles().flatten() })?.find { it.name == fileName }?.path
|
|
|
|
if (result == null) {
|
|
throw new Exception("Failed to resolve ${baseDir}/<cache key>/${fileName}");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
def specialSource = buildscript.configurations.specialSource.resolvedConfiguration.getFirstLevelModuleDependencies().find {
|
|
it.moduleGroup == 'net.md-5' && it.moduleName == 'SpecialSource'
|
|
}.moduleArtifacts.first().file.path
|
|
|
|
// Converts from Mojang's mappings to Minecraft's obfuscated mappings.
|
|
ext.remapMojangToObfuscated = { inputFile, outputFile, craftbukkitVersion ->
|
|
def remappedMojang = findInGradleCache("org.spigotmc", "spigot", craftbukkitVersion, "spigot-${craftbukkitVersion}-remapped-mojang.jar")
|
|
def mojangMappings = findInGradleCache("org.spigotmc", "minecraft-server", craftbukkitVersion, "minecraft-server-${craftbukkitVersion}-maps-mojang.txt")
|
|
|
|
println '> remapMojangToObfuscated'
|
|
println ' Input: ' + inputFile.path
|
|
println ' Output: ' + outputFile.path
|
|
println ' CraftBukkit version: ' + craftbukkitVersion
|
|
def classpathSeparator = System.properties['path.separator']
|
|
exec {
|
|
commandLine 'java',
|
|
'-cp', "${specialSource}${classpathSeparator}${remappedMojang}".replace('{craftbukkitVersion}', craftbukkitVersion),
|
|
'net.md_5.specialsource.SpecialSource',
|
|
'--live',
|
|
'-i', inputFile.path,
|
|
'-o', outputFile.path,
|
|
'-m', mojangMappings,
|
|
'--reverse'
|
|
}
|
|
}
|
|
|
|
// Converts from Minecraft's obfuscated mappings to Spigot's mappings.
|
|
ext.remapObfuscatedToSpigot = { inputFile, outputFile, craftbukkitVersion ->
|
|
def spigotMappings = findInGradleCache("org.spigotmc", "minecraft-server", craftbukkitVersion, "minecraft-server-${craftbukkitVersion}-maps-spigot.csrg")
|
|
def remappedObf = findInGradleCache("org.spigotmc", "spigot", craftbukkitVersion, "spigot-${craftbukkitVersion}-remapped-obf.jar")
|
|
|
|
println '> remapObfuscatedToSpigot'
|
|
println ' Input: ' + inputFile.path
|
|
println ' Output: ' + outputFile.path
|
|
println ' CraftBukkit version: ' + craftbukkitVersion
|
|
def classpathSeparator = System.properties['path.separator']
|
|
exec {
|
|
commandLine 'java',
|
|
'-cp', "${specialSource}${classpathSeparator}${remappedObf}".replace('{craftbukkitVersion}', craftbukkitVersion),
|
|
'net.md_5.specialsource.SpecialSource',
|
|
'--live',
|
|
'-i', inputFile.path,
|
|
'-o', outputFile.path,
|
|
'-m', spigotMappings
|
|
}
|
|
}
|
|
|
|
// Converts from Mojang's mappings to Spigot's mappings.
|
|
ext.remapMojangToSpigot = { inputFile, intermediateFile, outputFile, craftbukkitVersion ->
|
|
println '> remapMojangToSpigot'
|
|
println ' Input: ' + inputFile.path
|
|
println ' Intermediate: ' + intermediateFile.path
|
|
println ' Output: ' + outputFile.path
|
|
println ' CraftBukkit version: ' + craftbukkitVersion
|
|
remapMojangToObfuscated(inputFile, intermediateFile, craftbukkitVersion)
|
|
remapObfuscatedToSpigot(intermediateFile, outputFile, craftbukkitVersion)
|
|
}
|