プラグインのメタデータ

Adding plugin metadata helps users to identify your plugin more easily by giving them the ability to check the name, version, description, or even the authors of a plugin at runtime. It will also be used when publishing plugins on a plugin portal like Ore.

Currently, Sponge supports the following types of plugin metadata:

  • プラグイン ID, プラグイン名, バージョン

  • 説明

  • URL (Webサイトなど)

  • 作者

  • プラグインの依存関係

Plugin annotation

You can define the additional (optional) plugin metadata on your @Plugin annotation. You can provide all meta information in the annotation, despite only the id being required. A @Plugin annotation which uses all fields available looks like this:

import org.spongepowered.api.plugin.Plugin;

@Plugin(id = "myplugin", name = "My Plugin", version = "1.0",
    description = "This is a very cool plugin I made for me",
    url = "http://example.com",
    authors = {"Spongie", "FLARD"},
    dependencies = {@Dependency(id = "otherplugin", optional = true)})

For every @Dependency you provide, you may also give a version attribute specifying a version range according to Dependency#version(). The optional attribute specifies that your plugin may be loaded even if the dependency is not available. Unless explicitly specified as optional, the absence of any dependency will prevent your plugin from being loaded.

注釈

For both authors and dependencies, the curly brackets may be left out if only one element is supplied, e.g. dependencies = @Dependency(id = "otherplugin", optional = true) in the above example.

ファイルメタデータ

Additionally to plugin metadata defined in the plugin annotation we also recommend plugins to include this metadata in an extra file in the JAR, which has several advantages:

  • Easier integration for build systems (e.g. contributing the version from the build system into plugin metadata)

  • Easier for plugin portals to obtain the plugin metadata (no parsing of class files necessary)

注釈

We strongly recommend public plugins to include file metadata. Plugin portals such as Ore may require file metadata. See Using the Annotation Processor for a simple way to generate it. The implementation may print a warning if a plugin is missing file metadata.

mcmod.info のフォーマット

Sponge プラグインでは、プラグインの JAR のルートに含まれる mcmod.info というファイルを使います。 フォーマットは Forge からのもので、 Minecraft コミュニティのいくつかのプロジェクトで使用されているので、同じものを使用します。

mcmod.info is basically a simple JSON file which defines the plugin metadata as simple fields. Here is an example file that could be used by a Sponge plugin:

[{
    "modid": "myplugin",
    "name": "My Plugin",
    "version": "1.0",
    "description": "This is a very cool plugin I made for me",
    "authorList": [
        "Spongie",
        "FLARD"
    ],
    "dependencies": [
        "otherplugin"
    ]
}]

Using the Annotation Processor

Writing an extra file is quite annoying. Fortunately, usually there is nothing extra you need to do. When compiling your plugin, SpongeAPI is able to generate this file automatically based on the information provided in your @Plugin annotation.

有効化

If you’re using a build system such as Gradle or Maven and have not explicitly disabled annotation processing there is nothing extra you need to do. By default, the annotation processor will automatically run and generate a mcmod.info file based on the contents of your @Plugin annotation.

If you’re not using a build system you need to manually enable annotation processing.

ビルドシステムの調整

If you’re using Gradle, SpongeGradle will provide additional integration for Gradle and plugin metadata. For example, it will automatically include the project version defined in the Gradle build script in your plugin metadata. See Gradle の設定 for details.

注釈

If you’re using the NetBeans IDE make sure you’ve unchecked the Compile On Save option under Project Properties > Build > Compile to make sure the mcmod.info file will be generated correctly.