Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ tasks.register('updatePluginManifest') {
def manifestFile = file('src/main/resources/manifest.json')
doLast {
if (!manifestFile.exists()) {
if (early_plugin.toBoolean()) {
// Early plugins do not require a manifest.json file.
// We still want to update the manifest if it exists, because an
// early plugin can also 'contain' and behave as a regular plugin.
return
}
throw new GradleException("Could not find manifest.json at ${manifestFile.path}!")
}
def manifestJson = new groovy.json.JsonSlurper().parseText(manifestFile.text)
Expand All @@ -81,6 +87,17 @@ tasks.named('processResources') {
def createServerRunArguments(String srcDir) {
def programParameters = '--allow-op --disable-sentry --assets="' + "${hytaleHome}/install/$patchline/package/game/latest/Assets.zip" + '"'
def modPaths = []
if (early_plugin.toBoolean()) {
/*
* To enable ClassTransformers, Hytale Server requires that we give it the path
* to a folder that contains ANY jar file.
* The jar file could be empty, or be the server jar itself for all it cares.
* At a point in the future this might get changed, but for now we have to do something like this.
* See EarlyPluginLoader class for more details.
*/
def generatedJarFileParentPath = "${projectDir.absolutePath}/build/libs"
programParameters += " --accept-early-plugins --early-plugins=${generatedJarFileParentPath}"
Comment on lines +98 to +99
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I've done here is use the generated plugin jar to enable ClassTransformer

But this requires us to build the jar before running the server, which is prone to errors. The generated jar directory can easily be modified for example.

What could be done here instead is to use the HytaleServer parent directory:

Suggested change
def generatedJarFileParentPath = "${projectDir.absolutePath}/build/libs"
programParameters += " --accept-early-plugins --early-plugins=${generatedJarFileParentPath}"
def serverJarFileParentPath = "$hytaleHome/install/$patchline/package/game/latest/Server"
programParameters += " --accept-early-plugins --early-plugins=${serverJarFileParentPath }"

We would be sure that at least a jar is contained in the directory, and we would not have to build the plugin jar!
But it could lead to unexpected behavior if another jar is present in the HytaleServer parent directory.

I don't see a perfect solution here, but I'd be interested in hearing alternative approaches

}
if (includes_pack.toBoolean()) {
modPaths << srcDir
}
Expand All @@ -101,13 +118,23 @@ idea.project.settings.runConfigurations {
moduleName = project.idea.module.name + '.main'
programParameters = createServerRunArguments(sourceSets.main.java.srcDirs.first().parentFile.absolutePath)
workingDirectory = serverRunDir.absolutePath
if (early_plugin.toBoolean()) {
// Ensure that the Gradle task to build the jar is run before launching
// so that the early-plugins folder contains a jar file.
beforeRun {
'GradleTask'(org.jetbrains.gradle.ext.GradleTask) {
task = jar
}
}
}
Comment on lines +121 to +129
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If building the plugin jar is not needed anymore

Suggested change
if (early_plugin.toBoolean()) {
// Ensure that the Gradle task to build the jar is run before launching
// so that the early-plugins folder contains a jar file.
beforeRun {
'GradleTask'(org.jetbrains.gradle.ext.GradleTask) {
task = jar
}
}
}

}
}

// 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")
def tasksFile = file("$vscodeDir/tasks.json")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If building the plugin jar is not needed anymore

Suggested change
def tasksFile = file("$vscodeDir/tasks.json")

doLast {
if (!vscodeDir.exists()) {
vscodeDir.mkdirs()
Expand All @@ -126,6 +153,28 @@ tasks.register('generateVSCodeLaunch') {
]
]
]
if (early_plugin.toBoolean()) {
// Ensure that the Gradle task to build the jar is run before launching
// so that the early-plugins folder contains a jar file.
launchConfig.configurations[0].preLaunchTask = "gradle: jar"

def tasksConfig = [
version: "2.0.0",
tasks: [
[
"label": "gradle: jar",
"type": "shell",
"command": "./gradlew",
"args": ["jar"],
"problemMatcher": ["\$gradle"],
"windows": [
"command": "gradlew.bat"
]
]
]
]
tasksFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(tasksConfig))
}
Comment on lines +156 to +177
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If building the plugin jar is not needed anymore

Suggested change
if (early_plugin.toBoolean()) {
// Ensure that the Gradle task to build the jar is run before launching
// so that the early-plugins folder contains a jar file.
launchConfig.configurations[0].preLaunchTask = "gradle: jar"
def tasksConfig = [
version: "2.0.0",
tasks: [
[
"label": "gradle: jar",
"type": "shell",
"command": "./gradlew",
"args": ["jar"],
"problemMatcher": ["\$gradle"],
"windows": [
"command": "gradlew.bat"
]
]
]
]
tasksFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(tasksConfig))
}

launchFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(launchConfig))
}
}
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ load_user_mods=false
# manually. You may also want to use a custom path if you are building in
# a non-standard environment like a build server. The home path should
# the folder that contains the install and UserData folder.
# hytale_home=./test-file
# hytale_home=./test-file

# Determines if the plugin is an early plugin. An early plugin is loaded
# before anything else, allowing it to use bytecode manipulation to change
# core server behaviors.
# Visit https://support.curseforge.com/en/support/solutions/articles/9000273188-bootstrap-early-plugins
# for more information.
early_plugin=false