First commit
This commit is contained in:
+206
@@ -0,0 +1,206 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.3'
|
||||
id 'com.gradleup.shadow' version '9.3.1'
|
||||
}
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
ext {
|
||||
if (project.hasProperty('hytale_home')) {
|
||||
hytaleHome = project.findProperty('hytale_home')
|
||||
} else if (System.getenv('HYTALE_HOME')) {
|
||||
hytaleHome = System.getenv('HYTALE_HOME')
|
||||
} else {
|
||||
def os = OperatingSystem.current()
|
||||
if (os.isWindows()) {
|
||||
hytaleHome = "${System.getProperty("user.home")}/AppData/Roaming/Hytale"
|
||||
}
|
||||
else if (os.isMacOsX()) {
|
||||
hytaleHome = "${System.getProperty("user.home")}/Library/Application Support/Hytale"
|
||||
}
|
||||
else if (os.isLinux()) {
|
||||
hytaleHome = "${System.getProperty("user.home")}/.var/app/com.hypixel.HytaleLauncher/data/Hytale"
|
||||
if (!file(hytaleHome).exists()) {
|
||||
hytaleHome = "${System.getProperty("user.home")}/.local/share/Hytale"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def hytaleHomePath = ext.has('hytaleHome') ? hytaleHome : null
|
||||
def hasHytaleHome = (hytaleHomePath != null) && file(hytaleHomePath).exists()
|
||||
if (!hasHytaleHome) {
|
||||
logger.lifecycle("Hytale install not detected; run configs that launch the server will be skipped. Set -Phytale_home=/path/to/Hytale to enable them.")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
// Quiet warnings about missing Javadocs.
|
||||
javadoc {
|
||||
options.addStringOption('Xdoclint:-missing', '-quiet')
|
||||
}
|
||||
|
||||
// Adds the Hytale server as a build dependency, allowing you to reference and
|
||||
// compile against their code without bundling it. When a local install is
|
||||
// present, we still use its jar for launching the server in IDE run configs.
|
||||
dependencies {
|
||||
compileOnly("com.hypixel.hytale:Server:$hytale_build")
|
||||
testCompileOnly("com.hypixel.hytale:Server:$hytale_build")
|
||||
testRuntimeOnly("com.hypixel.hytale:Server:$hytale_build")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
if (hasHytaleHome) {
|
||||
runtimeOnly(files("$hytaleHome/install/$patchline/package/game/latest/Server/HytaleServer.jar"))
|
||||
}
|
||||
|
||||
// Your dependencies here
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "hytale-release"
|
||||
url = uri("https://maven.hytale.com/release")
|
||||
}
|
||||
maven {
|
||||
name = "hytale-pre-release"
|
||||
url = uri("https://maven.hytale.com/pre-release")
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the manifest.json file with the latest properties defined in the
|
||||
// build.properties file. Currently we update the version and if packs are
|
||||
// included with the plugin.
|
||||
tasks.register('updatePluginManifest') {
|
||||
def manifestFile = file('src/main/resources/manifest.json')
|
||||
doLast {
|
||||
if (!manifestFile.exists()) {
|
||||
throw new GradleException("Could not find manifest.json at ${manifestFile.path}!")
|
||||
}
|
||||
def manifestJson = new groovy.json.JsonSlurper().parseText(manifestFile.text)
|
||||
manifestJson.Version = version
|
||||
manifestJson.IncludesAssetPack = includes_pack.toBoolean()
|
||||
manifestFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(manifestJson))
|
||||
}
|
||||
}
|
||||
|
||||
// Makes sure the plugin manifest is up to date.
|
||||
tasks.named('processResources') {
|
||||
dependsOn 'updatePluginManifest'
|
||||
}
|
||||
|
||||
tasks.named('shadowJar') {
|
||||
archiveClassifier.set('')
|
||||
mergeServiceFiles()
|
||||
}
|
||||
|
||||
// Ensure the shaded jar is produced during a normal build.
|
||||
tasks.named('build') {
|
||||
dependsOn 'shadowJar'
|
||||
}
|
||||
|
||||
if (hasHytaleHome) {
|
||||
// Create the working directory to run the server if it does not already exist.
|
||||
def serverRunDir = file("$projectDir/run")
|
||||
if (!serverRunDir.exists()) {
|
||||
serverRunDir.mkdirs()
|
||||
}
|
||||
|
||||
def createServerRunArguments = { String srcDir ->
|
||||
def programParameters = '--allow-op --disable-sentry --assets="' + "${hytaleHome}/install/$patchline/package/game/latest/Assets.zip" + '"'
|
||||
def modPaths = []
|
||||
if (includes_pack.toBoolean()) {
|
||||
modPaths << srcDir
|
||||
}
|
||||
if (load_user_mods.toBoolean()) {
|
||||
modPaths << "${hytaleHome}/UserData/Mods"
|
||||
}
|
||||
if (!modPaths.isEmpty()) {
|
||||
programParameters += ' --mods="' + modPaths.join(',') + '"'
|
||||
}
|
||||
return programParameters
|
||||
}
|
||||
|
||||
def serverJar = file("$hytaleHome/install/$patchline/package/game/latest/Server/HytaleServer.jar")
|
||||
def assetsZip = file("$hytaleHome/install/$patchline/package/game/latest/Assets.zip")
|
||||
def shadowJarTask = tasks.named('shadowJar')
|
||||
|
||||
tasks.register('runServerJar', JavaExec) {
|
||||
dependsOn shadowJarTask
|
||||
mainClass = 'com.hypixel.hytale.Main'
|
||||
classpath = files(serverJar)
|
||||
workingDir = serverRunDir.absolutePath
|
||||
doFirst {
|
||||
def modPaths = [shadowJarTask.get().archiveFile.get().asFile.parentFile.absolutePath]
|
||||
if (load_user_mods.toBoolean()) {
|
||||
modPaths << "${hytaleHome}/UserData/Mods"
|
||||
}
|
||||
def args = [
|
||||
'--allow-op',
|
||||
'--disable-sentry',
|
||||
"--assets=${assetsZip}",
|
||||
"--mod=${modPaths.join(',')}"
|
||||
]
|
||||
logger.lifecycle("Running server with command: java -cp ${serverJar} ${mainClass.get()} ${args.join(' ')}")
|
||||
setArgs(args)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tasks.register('runServer') {
|
||||
|
||||
dependsOn 'runServerJar'
|
||||
}
|
||||
|
||||
// Creates a run configuration in IDEA that will run the Hytale server with
|
||||
// your plugin and the default assets.
|
||||
idea.project.settings.runConfigurations {
|
||||
'HytaleServer'(org.jetbrains.gradle.ext.Application) {
|
||||
mainClass = 'com.hypixel.hytale.Main'
|
||||
moduleName = project.idea.module.name + '.main'
|
||||
programParameters = createServerRunArguments(sourceSets.main.java.srcDirs.first().parentFile.absolutePath)
|
||||
workingDirectory = serverRunDir.absolutePath
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a launch.json file for VSCode with the same configuration
|
||||
tasks.register('generateVSCodeLaunch') {
|
||||
def vscodeDir = file("$projectDir/.vscode")
|
||||
def launchFile = file("$vscodeDir/launch.json")
|
||||
doLast {
|
||||
if (!vscodeDir.exists()) {
|
||||
vscodeDir.mkdirs()
|
||||
}
|
||||
def programParams = createServerRunArguments("\${workspaceFolder}")
|
||||
def launchConfig = [
|
||||
version: "0.2.0",
|
||||
configurations: [
|
||||
[
|
||||
type: "java",
|
||||
name: "HytaleServer",
|
||||
request: "launch",
|
||||
mainClass: "com.hypixel.hytale.Main",
|
||||
args: programParams,
|
||||
cwd: "\${workspaceFolder}/run"
|
||||
]
|
||||
]
|
||||
]
|
||||
launchFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(launchConfig))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tasks.register('generateVSCodeLaunch') {
|
||||
doLast {
|
||||
logger.lifecycle("Skipped VSCode launch configuration because hytale_home is not set or the install path is missing.")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user