Skip to content

Plugin Structure

Cliven Mitchell edited this page Feb 3, 2019 · 13 revisions

Introduction

This section will explain what plugins are and how they're structured.


What is a plugin?

A plugin is a group of files contained within a single folder that make up a specific piece of content. Plugins are designed to be toggled on and off within the plugin GUI whenever desired; for instance, turning on a "Double XP" plugin during a double xp weekend (and turning it off once the weekend ends).

Plugins are made up of a few different files

  • Script dependencies (.kt files)
  • Scripts (.kts files)
  • Metadata (.toml file)

Script dependency (.kt)

A script dependency is a compiled .kt file that one or more scripts depend on. Script dependencies can interact with any other compiled Kotlin or Java files in the codebase. Although Java classes can retrieve values and functions from script dependencies, they shouldn't because its indicative of bad design. Script dependency class names follow Java class naming conventions.

Script (.kts)

A script is an interpreted .kts file that nothing depends on. It can access all script dependencies and Java files in the codebase. Every script file must have import api.predef.* as the topmost declaration in order to have all scripting functionality within local scope.

Scripts can have class declarations, but they will only be visible to members in the file they're declared in. The file names follow camelCase naming conventions.

Warning: Scripts cannot declare top level values with private or interpretation will fail when the value is accessed. To minimize potential errors, nothing should be declared with private inside scripts.

Also please note that only code within listeners is executed on the game thread. For that reason, all initialization logic should be within a ServerLaunchEvent.

import api.predef.*

// Do this!
on(ServerLaunchEvent::class) {
    world.addNpc(id = 1, x = 3200, y = 3200)
}

// Don't do this...
world.addNpc(id = 1, x = 3200, y = 3200)

Metadata (.toml)

Metadata is a parsed .toml file simply named "plugin." It contains a few placeholders for entering data about the plugin

  • Name: The name of the plugin
  • Description: What does the plugin do?
  • Version: The version of Luna this plugin is compatible with.
  • Authors: Who wrote this plugin?

All plugins must have a metadata file or they won't be loaded.


Continue to next section.