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 classRepresents a loaded file with an optionalManifestandCodeSource. -
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 ornullif 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 ornullif none was set.voidinit()Loads the metadata file and main class of thisPlugin.voidinitPluginConfig(ConfigObject config) Applies the givenconfigdata to this plugin's object.protected abstract Plugin.LoadedClassFileLoads 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,
nullis returned.- Parameters:
relativePath- The relative file path- Returns:
- The
LoadedClassFilerepresenting the file, ornullif 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,
nullis 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 givenconfigdata to this plugin's object.First,
ConfigObject.populateConfigurationOptions(Object)is called on this plugin's main class instance. Then, if a method with theExtendedPluginConfigurationannotation and a single parameter of typeConfigObjectis found, it is called with the givenconfig.- Parameters:
config- The configuration data- Throws:
ConfigurationException- If theExtendedPluginConfigurationmethod 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
PluginManageris 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 ornullif none was set.- Returns:
- The version string
-
getDescription
Returns a description provided in the metadata file ornullif 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
-