Class Plugin
PluginManager
.
Plugins are JAR files or directories containing class files. A plugin must have a file called plugin.cfg
in its root directory, containing metadata about the plugin.
The metadata file is a list of key-value pairs. Each pair is separated by one or more newline characters. The key must consist only of alphanumeric characters, followed by a
=
, and the value, which has different character restrictions depending on the key. The following keys are defined:
key | Meaning | Required | Allowed characters |
---|---|---|---|
id | The unique ID of the plugin | yes | alphanumeric, - , _ |
name | The name of the plugin | no | alphanumeric, various special characters |
version | A version string | no | alphanumeric, - , _ , . , + |
description | A description | no | any |
mainClass | The main class of the plugin | yes | Java identifier characters |
getAdditionalOption(String)
.- Since:
- 2.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Represents a loaded file with an optionalManifest
andCodeSource
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of an unrecognized option in the metadata file.Returns a description provided in the metadata file ornull
if none was provided.getId()
The plugin ID is a string given in the plugin metadata file consisting only of upper- or lowercase letters and numbers.Returns the instance of the main class of thisPlugin
.Class<?>
Returns the type of the main class of thisPlugin
, loaded by the class loader passed in the constructor.getName()
Returns the name of this plugin.Returns the version string set in the metadata file ornull
if none was set.void
init()
Loads the metadata file and main class of thisPlugin
.void
initPluginConfig
(ConfigObject config) Applies the givenconfig
data to this plugin's object.protected abstract Plugin.LoadedClassFile
Loads the file in thisPlugin
's root identified by the given path and stores its data and additional information in the returnedLoadedClassFile
.byte[]
Loads the file in thisPlugin
's root identified by the given path.
-
Constructor Details
-
Plugin
-
-
Method Details
-
loadClass
Loads the file in thisPlugin
's root identified by the given path and stores its data and additional information in the returnedLoadedClassFile
.The file need not be a valid class file. If the file does not exist,
null
is returned.- Parameters:
relativePath
- The relative file path- Returns:
- The
LoadedClassFile
representing the file, ornull
if it does not exist - Throws:
IOException
- If an IO error occurs- Since:
- 2.8
- See Also:
-
loadFile
Loads the file in thisPlugin
's root identified by the given path.If the file does not exist,
null
is returned.- Parameters:
relativePath
- The relative file path- Returns:
- The file content
- Throws:
IOException
- If an IO error occurs- Since:
- 2.8
- See Also:
-
init
public void init()Loads the metadata file and main class of thisPlugin
. -
initPluginConfig
Applies the givenconfig
data to this plugin's object.First,
ConfigObject.populateConfigurationOptions(Object)
is called on this plugin's main class instance. Then, if a method with theExtendedPluginConfiguration
annotation and a single parameter of typeConfigObject
is found, it is called with the givenconfig
.- Parameters:
config
- The configuration data- Throws:
ConfigurationException
- If theExtendedPluginConfiguration
method threw an exceptionConfigurationException
- If a value has the incorrect type, or the value of a required option is missingConfigurationException
- If a reflective operation failsUnsupportedOperationException
- If a field type is unsupported- Since:
- 2.10
-
getId
The plugin ID is a string given in the plugin metadata file consisting only of upper- or lowercase letters and numbers.If a
PluginManager
is used to load multiple plugins, it will ensure that an ID is unique among all plugins.- Returns:
- The unique ID of this plugin
-
getName
Returns the name of this plugin. If no name was set in the metadata file orinit()
was not called, a name will be inferred from the path given in the constructor.- Returns:
- The name of this plugin
-
getVersion
Returns the version string set in the metadata file ornull
if none was set.- Returns:
- The version string
-
getDescription
Returns a description provided in the metadata file ornull
if none was provided.- Returns:
- The description
-
getAdditionalOption
Returns the value of an unrecognized option in the metadata file.- Parameters:
key
- The key- Returns:
- The value
-
getMainClassType
Returns the type of the main class of thisPlugin
, loaded by the class loader passed in the constructor.- Returns:
- The type
- Throws:
IllegalStateException
- Ifinit()
was not called successfully prior to calling this method
-
getMainClassInstance
Returns the instance of the main class of thisPlugin
.- Returns:
- The instance
- Throws:
IllegalStateException
- Ifinit()
was not called successfully prior to calling this method
-