diff --git a/build.gradle b/build.gradle index 8df6db3..385374f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,9 @@ plugins { } import org.gradle.internal.os.OperatingSystem +import groovy.json.JsonOutput + +version = plugin_version ext { if (project.hasProperty('hytale_home')) { @@ -57,25 +60,38 @@ if (!serverRunDir.exists()) { serverRunDir.mkdirs() } -// 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') +// Generate the manifest.json file with the latest properties defined in the +// build.properties file. +tasks.register('generatePluginManifest') { + group = "hytale" + description = "Generates the manifest.json dynamically in the build directory." + def outputDir = file("${project.layout.buildDirectory.get().asFile}/resources/main") + def manifestFile = file("${outputDir}/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)) + if (!outputDir.exists()) outputDir.mkdirs() + def manifestData = [ + Group: project.findProperty('plugin_group'), + Name: project.findProperty('plugin_name'), + Version: project.findProperty('plugin_version'), + Description: project.findProperty('plugin_description'), + Authors: project.findProperty('plugin_authors')?.split(',')?.collect { [Name: it.trim()] } ?: [], + Website: project.findProperty('plugin_url'), + ServerVersion: project.findProperty('server_version') ?: "*", + Dependencies: new groovy.json.JsonSlurper().parseText(project.findProperty('plugin_dependencies') ?: "{}"), + OptionalDependencies: new groovy.json.JsonSlurper().parseText(project.findProperty('plugin_optional_dependencies') ?: "{}"), + DisabledByDefault: project.findProperty('disabled_by_default')?.toBoolean() ?: false, + Main: project.findProperty('plugin_main_class'), + IncludesAssetPack: project.findProperty('includes_pack')?.toBoolean() ?: false + ] + + manifestFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(manifestData)) + logger.lifecycle("Hytale Manifest generated at: ${manifestFile.path}") } } // Makes sure the plugin manifest is up to date. tasks.named('processResources') { - dependsOn 'updatePluginManifest' + finalizedBy 'generatePluginManifest' } def createServerRunArguments(String srcDir) { @@ -129,3 +145,17 @@ tasks.register('generateVSCodeLaunch') { launchFile.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(launchConfig)) } } + +// Runs the Hytale server directly from the terminal, automatically compiling +// your code and injecting the generated manifest from the build directory. +task runHytale(type: JavaExec) { + group = "hytale" + description = "Run the Hytale server directly from Gradle with current settings." + mainClass = 'com.hypixel.hytale.Main' + classpath = sourceSets.main.runtimeClasspath + workingDir = serverRunDir + standardInput = System.in + def buildResourcesDir = file("${project.layout.buildDirectory.get().asFile}/resources/main") + args = createServerRunArguments(buildResourcesDir.absolutePath).split(' ').collect { it.replace('"', '') } + dependsOn classes, processResources +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e0e99eb..2517547 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,22 @@ -# The current version of your project. Please use semantic versioning! -version=0.0.2 - -# The group ID used for maven publishing. Usually the same as your package name -# but not the same as your plugin group! -maven_group=org.example +################### Environment Properties ################### # The version of Java used by your plugin. The game is built on Java 21 but # actually runs on Java 25. java_version=25 +# Specifies the required Hytale server version for this plugin. +# Use "*" to allow any version or a specific version string like "1.0.0". +server_version=* + # Determines if your plugin should also be loaded as an asset pack. If your # pack contains assets, or you intend to use the in-game asset editor, you # want this to be true. includes_pack=true +# If true, the plugin will be installed but not activated until the user +# manually enables it in the game's plugin manager. +disabled_by_default=false + # The release channel your plugin should be built and ran against. This is # usually release or pre-release. You can verify your settings in the # official launcher. @@ -29,4 +32,41 @@ 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 \ No newline at end of file +# hytale_home=./test-file + +####################### Maven Properties ###################### + +# The group ID used for maven publishing. Usually the same as your package name +# but not the same as your plugin group! +maven_group=org.example + +###################### Plugin Properties ###################### + +# The group ID used for Hytale publishing. +plugin_group=Example + +# The display name of your plugin. +plugin_name=ExamplePlugin + +# The main class of your plugin, used as the entry point. +plugin_main_class=org.example.plugin.ExamplePlugin + +# The current version of your project. Please use semantic versioning! +plugin_version=0.0.2 + +# A comma-separated list of the people or teams who created the plugin. +plugin_authors=YourNameHere, OtherNameHere + +# A short summary of what your plugin does, which will be visible to users. +plugin_description=An example plugin for HyTale! + +# The official website or repository URL for the plugin project. +plugin_url=example.com + +# A JSON object defining other plugins required for this one to function. +# Example: {"hytale.essentials": "1.0.0"} +plugin_dependencies={} + +# A JSON object defining plugins that add extra features if present, +# but are not strictly required for the plugin to run. +plugin_optional_dependencies={} \ No newline at end of file diff --git a/src/main/resources/manifest.json b/src/main/resources/manifest.json deleted file mode 100644 index 169a0cc..0000000 --- a/src/main/resources/manifest.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "Group": "Example", - "Name": "ExamplePlugin", - "Version": "0.0.2", - "Description": "An example plugin for HyTale!", - "Authors": [ - { - "Name": "It's you!" - } - ], - "Website": "example.org", - "ServerVersion": "*", - "Dependencies": { - - }, - "OptionalDependencies": { - - }, - "DisabledByDefault": false, - "Main": "org.example.plugin.ExamplePlugin", - "IncludesAssetPack": true -} \ No newline at end of file