Skip to content

Latest commit

 

History

History
348 lines (239 loc) · 9.61 KB

File metadata and controls

348 lines (239 loc) · 9.61 KB

Nukkit Plugin

The NukkitX plugin provides you to:

  • Generate 'plugin.yml' with less configuration.

  • Shortcuts for dependency and repository.

  • Tasks for run server with your plugins for debug.

Table of contents

Requirements

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

Usage

Full Example Here

Groovy DSL

plugins {
    id 'kr.entree.spigradle.nukkit' version '2.4.5'
}

Kotlin DSL

plugins {
    id("kr.entree.spigradle.nukkit") version "2.4.5"
}
Groovy Legacy
buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath 'kr.entree:spigradle:2.4.5'
    }
}

apply plugin: 'kr.entree.spigradle.nukkit'
Kotlin Legacy
buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath("kr.entree:spigradle:2.4.5")
    }
}

apply(plugin = "kr.entree.spigradle.nukkit")

Description file generation

The plugin.yml file will be generated by task generateNukkitDescription based on the configuration of nukkit, 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 nukkit {} block.

Main class detection

The plugin automatically finds the main class extends PluginBase, and set the 'main' property to the class found.

You may present the main class using @NukkitPlugin or @PluginMain:

import kr.entree.spigradle.annotations.NukkitPlugin;

@NukkitPlugin
public class SamplePlugin extends PluginBase { }

Debug your plugin

Run your plugin with just execute single gradle task.

The debugNukkit performs to download Nukkit, copy it with your plugins into the default path debug/nukkit, and run it.

These tasks copy your plugin and its dependency plugins.

You can pass (jvm)arguments:

nukkit {
    debug {
        args '--nojline', '--max-players', '100'
        jvmArgs '-Xmx16G'
    }
}

This affects to debugNukkit, also RunNukkit IDEA RunConfiguration.

More information: Tasks

Configuration

The description of your plugin for a 'plugin.yml'.

About the plugin.yml, See Official Sample

Groovy Example
nukkit {
    authors 'Me'
    depends 'ProtocolLib', 'Vault'
    api '1.0.5'
    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
nukkit {
    authors = listOf("Me")
    depends = listOf("SomePlugin")
    api = listOf("1.0.5")
    load = Load.STARTUP
    commands {
        create("give") {
            aliases = listOf("i")
            description = "Give command."
            permission = "test.foo"
            permissionMessage = "You do not have the permission!"
            usage = "/<command> [item] [amount]"
        }
    }
    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<NukkitExtension> {
    description = "A NukkitX plugin."
    // ...
}

Tasks

All tasks supports UP-TO-DATE check.

Configuration Guide

Groovy:

runNukkit {
    jvmArgs('-Xmx8G')
}

Kotlin with type-safe accessors:

tasks {
    runNukkit {
        jvmArgs("-Xmx8G")
    }
}

Kotlin without type-safe accessors:

tasks {
    named<JavaExec>("runNukkit") {
        jvmArgs("-Xmx8G")
    }
}

Kotlin with property delegation

tasks {
    val runNukkit by existing(JavaExec::clas) {
        jvmArgs("-Xmx8G")
    }
    // Do something with 'runNukkit'
}

detectNukkitMain - SubclassDetection

Finds the main class extends cn.nukkit.plugin.PluginBase.

generateNukkitDescription - YamlGenerate

Depends on: detectNukkitMain

Generates the description file 'plugin.yml'.

debugNukkit

Depends on: prepareNukkitPlugins, downloadNukkit, runNukkit

Downloads NukkitX and runs it with your plugin and dependency plugins.

prepareNukkitPlugins - Copy

Depends on: build

Copies project plugin jar and its dependency plugins into the server plugins directory.

downloadNukkit - Download

Downloads NukkitX.

runNukkit - JavaExec

Just runs the NukkitX jar at configured path even there's no executable file.

NOTE: Use debugNukkit instead of runNukkit if you need prepare process like download NukkitX jar, copy plugins.

cleanDebug

Deletes all server files.

See also