-
Notifications
You must be signed in to change notification settings - Fork 59
Addons API
Addons are no different than normal plugins, however sometimes these isolated softwares are purely designed for kingdoms plugin. If you made a compatbility addon for kingdoms, you can ask me to add it too!
This page only contains information about API that is mostly not found in a normal plugin, so a lot of other information is on the main API page instead.
First, you'd need to implement the Addon
class from kingdoms. This is usually done in the same class that JavaPlugin
is extended.
Before going deeper in the features, there are already many open source addons like Peace Treaties and Outposts that you can take a look at.
First of all, you need to be registering all your Namespace'd values onLoad because you cannot register them later.
Another important thing is to look if the plugin was correctly enabled
You can register new configs like this and optionally register them for file watchers like this.
If you want to complete your config suite, you can optionally add new config validators for config schemas if you have any new data like this.
A very very important thing to remember is that you need to call signalDisable() on your onDisable() if you've registered namespace'd values in the plugin. If you don't do this the plugin can't correctly save data.
If you want to register new placeholders to the plugin, you can do so like this, enums are a pretty easy and common way to register placeholders, even tho they'll never be used within the code itself, if you don't like that approach, all you need to do is to register placeholders using KingdomsPlaceholder.of(name, defaultValue, translator) function which ultimately implements KingdomsPlaceholder class and registers it with KingdomsPlaceholder.register(instance)
.
Finally if you have a main plugin and you want to make an addon for kingdoms compatibility, you can register the addon as an available downloadable content using new AddonRepository(pluginInstance, name, path, metaFileURL, description).register()
where name
is any displayname and path
is the data node (it's not a file or URL path) and metaFileURL
points to a URL
which must point to an accessible .yml
file containing addon information like this one. A direct URL to that file for example would be new URL("https://raw.githubusercontent.com/CryptoMorin/KingdomsX/master/addons/addon-meta.yml")
If you don't have a main plugin, you can simply ask me to add your addon information to the original addon-meta file, but that'd require me to update it every time a new version is out.
This is a completely optional component, but recommended to implement. Please read Data Corruption first for more info. This adds a way to process data when the command is executed so you can do your own corrections for your own addon.
Additionally, you might want to implement a ChunkEditingHandler
instead if you wish to perform operations on chunk block/entity data.
public final class MyDataCheckup extends CheckupHandler {
private static final MyDataCheckup INSTANCE = new MyDataCheckup();
static {
CheckupHandler.addCheckupHandler(INSTANCE);
}
@Override
public void handle(@NotNull CommandAdminFSCK.CheckupProcessor checkupProcessor) {
for (Kingdom kingdom : checkupProcessor.getDataCenter().getKingdomManager().getLoadedData()) { // Everything is already loaded.
if (something == null) {
checkupProcessor.addEntry(new StaticMessenger("{$c}Something is corrupted! %broken%"), settings -> {
settings.raw("broken", something);
});
}
}
}
}
Terminology - Spigot - Discord