The Spigot plugin provides you to:
-
Generate 'plugin.yml' with less configuration.
-
Shortcuts for dependency and repository.
-
Tasks for run server with your plugin for debug.
The plugin requires Gradle 5.4.2+, recommends the latest.
To update your gradle wrapper:
gradlew wrapper --gradle-version 6.9.1 --distribution-type all
Groovy DSL
plugins {
id 'kr.entree.spigradle' version '2.4.5'
}Kotlin DSL
plugins {
id("kr.entree.spigradle") version "2.4.5"
}Groovy Legacy
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'kr.entree:spigradle:2.4.5'
}
}
apply plugin: 'kr.entree.spigradle'Kotlin Legacy
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("kr.entree:spigradle:2.4.5")
}
}
apply(plugin = "kr.entree.spigradle")The plugin.yml file will be generated by task generateSpigotDescription based on the configuration of spigot, included into output jars automatically.
Basically the properties 'main', 'name' and 'version' defaults to auto-detected main, project.name, project.version respectively. So if we create a simple plugin that just needs those properties, we don't need any configuration. Only pay attention to your unique implementation.
You can configure all properties of plugin.yml in spigot {} block.
The plugin automatically finds the main class extends JavaPlugin, and set the 'main' property to the class found.
You may present the main class using @SpigotMain or @PluginMain:
import kr.entree.spigradle.annotations.SpigotPlugin;
@SpigotPlugin
public class SamplePlugin extends JavaPlugin { }@SpigotPlugin
class SamplePlugin : JavaPlugin()Run your plugin with just execute single gradle task.
The debugSpigot performs to build Spigot using BuildTools, copy it with your plugins into the default path debug/spigot/server.jar, and run it.
The debugPaper performs to download Paperclip, copy it with your plugins into the same path debug/spigot/server.jar, and run it.
These tasks copy your plugin and its dependency plugins.
You can pass (jvm)arguments:
spigot {
debug {
args '--nojline', '--max-players', '100'
jvmArgs '-Xmx16G'
serverPort 25564
}
}This affects both tasks debugSpigot, debugPaper, also to IDEA RunConfigurations RunSpigot, RunPaper.
More information: Tasks
If you want to exclude some plugins, this is an example,
Kotlin:
tasks {
prepareSpigotPlugins {
exclude("**/worldedit*.jar")
exclude("**/worldguard*.jar")
}
}Groovy:
prepareSpigotPlugins {
exclude '**/worldedit*.jar' // or exclude 'worldedit*.jar'?
exclude '**/worldguard*.jar'
}Then WorldEdit and WorldGuard will be excluded by the prepareSpigotPlugins which a Copy task, you can use all the Copy features.
spigot - SpigotExtension
The description of your plugin for a plugin.yml.
The 'main' property will be set to the class auto-detected or presented by @kr.entree.spigradle.annotations.SpigotMain.
About the plugin.yml, See plugin-yml wiki
Groovy Example
spigot {
authors 'Me'
depends 'ProtocolLib', 'Vault'
softDepends 'WorldEdit'
apiVersion '1.15'
load STARTUP
commands {
give {
aliases 'giv', 'i'
description 'Give command.'
permission 'test.foo'
permissionMessage 'You do not have the permission!'
usage '/<command> [item] [amount]'
}
}
permissions {
'test.foo' {
description 'Allows foo command'
defaults 'true'
}
'test.*' {
description 'Wildcard permission'
defaults 'op'
children = ['test.foo': true]
}
}
}Kotlin Example
spigot {
authors = listOf("Me")
depends = listOf("ProtocolLib")
softDepends = listOf("WorldEdit")
apiVersion = "1.15"
load = Load.STARTUP
commands {
create("give") {
aliases = listOf("i")
description = "Give command."
permission = "test.foo"
permissionMessage = "You do not have permission!"
usage = "/<command> [test|stop]"
}
}
permissions {
create("test.foo") {
description = "Allows foo command"
defaults = "true"
}
create("test.*") {
description = "Wildcard permission"
defaults = "op"
children = mapOf("test.foo" to true)
}
}
}Without type-safe accessors:
configure<SpigotExtension> {
authors = listOf("Me")
// ...
}All tasks supports UP-TO-DATE check.
Configuration Guide
Groovy:
runSpigot {
jvmArgs('-Xmx8G')
}Kotlin with type-safe accessors:
tasks {
runSpigot {
jvmArgs("-Xmx8G")
}
}Kotlin without type-safe accessors:
tasks {
named<JavaExec>("runSpigot") {
jvmArgs("-Xmx8G")
}
}Kotlin with property delegation
tasks {
val runSpigot by existing(JavaExec::clas) {
jvmArgs("-Xmx8G")
}
// Do something with 'runSpigot'
}detectSpigotMain - SubclassDetection
Finds the main class extends org.bukkit.plugin.java.JavaPlugin.
generateSpigotDescription - YamlGenerate
Depends on: detectSpigotMain
Generates the description file 'plugin.yml'.
Depends on: prepareSpigotPlugins, prepareSpigot, runSpigot
Builds Spigot and runs it with your plugin and dependency plugins.
Depends on: prepareSpigotPlugins, downloadPaper, runSpigot
Runs Paper with your plugin and dependency plugins.
prepareSpigotPlugins - Copy
Depends on: build
Copies project plugin jar and its dependency plugins into the server plugins directory.
prepareSpigot - Copy
Depends on: downloadSpigotBuildTools, buildSpigot
Prepares Spigot for ready to run.
runSpigot - JavaExec
*Depends on: acceptSpigotEula, configSpigot
Just runs the server jar at configured path even there's no executable file.
NOTE: Use debugSpigot or debugPaper instead of runSpigot if you need prepare process like download server jar, copy plugins.
downloadSpigotBuildTools - Download
Downloads Spigot BuildTools.
buildSpigot - JavaExec
Builds Spigot using BuildTools.
Accepts the Mojang EULA, used in runSpigot task and IDEA RunConfiguration.
Configure the spigot.yml, used to set settings.restart-on-crash to false as default.
downloadPaper - Download
Downloads Paperclip.
Deletes all build outputs created by Spigot BuildTools.
Deletes all server files.
@Plugin(name = "SamplePlugin", version = "1.0-SNAPSHOT")
@Commands(@Command(name = "foo", desc = "Foo command", aliases = ["foobar", "fubar"], permission = "test.foo", permissionMessage = "You do not have permission!", usage = "/<command> [test|stop]"))
@Permission(name = "test.foo", desc = "Allows foo command", defaultValue = PermissionDefault.OP)
class SamplePlugin : JavaPlugin()If you use Gradle, the following reasons why no spigot-annotations:
- Duplicate information of the
nameandversion, these already provided inbuild.gradleandsettings.gradle. - The Annotation doesn't suit for providing complex information like
commandsandpermissions. - Using Gradle, we can configure all things programmatically.
Replacement on build.gradle:
spigot {
// The 'name' and 'version' will be set to project.version and project.name,
// But we may set those manually.
name = 'Manual name'
version = 'Manual version'
commands {
foo {
aliases = ['foobar', 'fubar']
description = 'Foo command'
permission = 'test.foo'
permissionMessage = 'You do not have permission!'
usage = '/<command> [test|stop]'
}
}
permissions {
'test.foo' {
description = 'Allows foo command'
defaults = 'op'
}
}
}With Spigradle 1.3.0+, you can use the MockBukkit without any special code.
If you use less than 1.3.0, add it in build.gradle:
task copyPluginYaml(type: Copy, dependsOn: spigotPluginYaml) {
from(new File(spigotPluginYaml.temporaryDir, 'plugin.yml'))
into(sourceSets.test.output.resourcesDir)
}
tasks.test.dependsOn(copyPluginYaml)- The task
spigotPluginYamlrenamed togenerateSpigotDescription - The annotation
@Pluginrepackaged to@kr.entree.spigradle.annotations.Plugin.
spigot-plugin-template by @Silthus
BukkitJavaGradle by @portlek