When creating plugins/projects for myself, I usually create libraries that can be re-used for different parts of the plugin. For example, I recently created an annotation powered command API in Kotlin. In addition to that, I’ve also created an input library using the trick I described earlier. It allows me to very easily listen for player keyup/keydown events as well as attach/remove the listener/mount entity for the player, without having to write out the messy packet code every time.
I’m also a big fan of unification in my projects – if I have to write something out twice, maintenance of that code becomes twice as hard. While this specific case isn’t code, it does help to easily fill in details for my plugin. Bukkit (and subsequently Spigot) requires all plugins to contain a plugin.yml file in the root directory of the jar.
It contains information used by the server for logging and showing information to admins. There are three required fields, as well as many others which are optional. The first required field is the name of the plugin, usually in the format of UpperCamelCase (no spaces). It’s used as the prefix for commands registered by the command (when a prefix has to be supplied), part of every message logged by your plugin, and generally allows administrators to find problem plugins from exceptions.
The second required field is package path to the plugin main class, the class which is loaded by the server and contains a few utility functions. A typical main path might look like “com.scarabcoder.example.
Example” where the last section is the class name itself. The final required field is the version of the plugin, which is usually paired with the plugin name during exceptions and helps when a consumer needs to report a plugin error.With the possible exception of the main class, all those are readily available in the Maven build file (pom.xml), and should normally match exactly.
There are also other optional fields in the plugin.yml, such as description or a list of authors, all of which can be taken from the Maven build file (<description>, <developers>, etc). After a bit of googling around, I found a basic intro to writing a Maven plugin in Java (though I adapted it to Kotlin). I had to look around a few open source plugins to find out how to get data from the Maven build file as well as add to the final compiled package, but after an hour or so I had it working.
At the moment, it generates the following plugin.yml fields:name: Taken from the <name> specified in pom, if none is found it’s taken from the artifact IDmain: Can be overriden manually, otherwise it’s set to <group>.<artifiact ID>.<name> (what I would recommend the path to be for a main class file).
version: Taken from the <version> property in <properties>description: Taken from the <description> tagwebsite: Taken from the <organization> tagdevelopers (list): Taken from all the developers listed in <developers>Additionally, you can specify Spigot plugins your plugin relies on inside the <configuration> tag the Maven plugin, as well as plugins it should load before or soft depends on.