-
Notifications
You must be signed in to change notification settings - Fork 0
v5 KamiPlugin
Available in spigot-utils and its inheritors (spigot-jar).
KamiPlugin extends JavaPlugin with lifecycle logging, registration helpers that clean up after
themselves, an automatic config.yml, and access to the rest of KamiCommon.
public class MyPlugin extends KamiPlugin {
@Override
public void onEnableInner() {
// your enable code
}
@Override
public void onDisableInner() {
// your disable code
}
}Use onEnableInner() and onDisableInner(), not onEnable() / onDisable(). KamiPlugin wraps them
so it can time and log startup and shutdown.
If you are shading rather than depending on the KamiCommon plugin, call
SpigotUtilsSource.onEnable(this) / onDisable() (or the PluginSource equivalents) from inside those
same two inner methods. onEnable() and onDisable() themselves are final and cannot be overridden.
See
Modules and Shading.
Anything registered this way is unregistered automatically when the plugin disables.
registerListeners(new MyListener());
registerCommands(new CmdHome());
registerTasks(bukkitTask);
registerDisableables(myDisableable);
unregisterListeners(myListener); unregisterListeners(); // all
unregisterCommands(myCommand); unregisterCommands(); // all
unregisterTasks(myTask); unregisterTasks(); // all
unregisterDisableables(d); unregisterDisableables(); // allregisterCommands and unregisterCommands update the live command map, so changes take effect
immediately rather than at the next restart.
config.yml is created and loaded for you as a KamiConfig:
KamiConfig config = getKamiConfig();Override isAutoLoadKamiConfig() to return false to opt out. JavaPlugin#getConfig() still exists and
still uses Bukkit's own classes.
To react to reloads, register an observer:
getKamiConfig().registerConfigObserver(cfg -> { /* re-read your cached values */ });Migrating from v4:
KamiPlugin#onConfigLoaded(KamiConfig)was removed. Register aConfigObserverinstead. See Configuration System.
getColorComponentLogger().info(serializer.fromMiniMessage("<green>Ready"));getColorComponentLogger() returns a ComponentLogger, which takes VersionedComponents and supports
both legacy colour codes and components. The older string-based logger getter is deprecated in favour of
it.
registerModule(new CustomEnchantsModule());
registerFeature(new ScoreboardFeature());
@Override public String getModuleYmlPath() { return "com/myplugin/modules"; }
@Override public String getFeatureYmlPath() { return "com/myplugin/features"; }Both take instances and are varargs. You must override the two path methods. They return null by
default, and a subsystem resolving its config fails a null check naming the method you need to override.
That failure is caught and logged by the subsystem manager rather than propagating, so the plugin still
enables and the subsystem simply never runs. See
Subsystems.
Migrating from v4:
KamiPlugin#getModule(Class)was removed. Keep your own reference to the instance instead. ThehasItemsAdder(),hasCitizens()andhasMythicMobs()checks were removed along with those integrations; use the plugin manager directly.
Setup
Spigot
Text
Data
Migration
Other versions