Package org.spongepowered.plugin.meta
Class PluginMetadata
java.lang.Object
org.spongepowered.plugin.meta.PluginMetadata
- All Implemented Interfaces:
Consumer<PluginMetadata>
Represents additional metadata for a specific version of a plugin.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionPluginMetadata
(String id) Constructs a newPluginMetadata
with the specified plugin ID. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(PluginMetadata other) Replaces the properties in thisPluginMetadata
with all properties of the specifiedPluginMetadata
that are not empty.void
Adds an author to theList
of authors for this plugin.void
addAuthors
(String... authors) Adds the authors to theList
of authors for this plugin.void
addDependencies
(PluginDependency... dependencies) Adds the list ofPluginDependency
to thisPluginMetadata
.void
addDependency
(PluginDependency dependency) Adds a newPluginDependency
to thisPluginMetadata
.authors()
Returns a mutableList
of authors for this plugin.Collects all dependencies of thisPluginMetadata
that are not optional.Returns aCollection
with all dependencies of the plugin represented by thisPluginMetadata
.Returns aMap
with all dependencies grouped by their plugin ID.dependency
(String id) Returns thePluginDependency
that is currently associated with the specified plugin ID.Returns the plugin description.Returns aMap
with additional properties for thisPluginMetadata
.<T> @Nullable T
getExtension
(String key) Returns the value for a specific extension.Groups the dependencies of thisPluginMetadata
based on theirPluginDependency.LoadOrder
.id()
Returns the plugin ID that is represented by thisPluginMetadata
.name()
Returns the plugin name.boolean
removeAuthor
(String author) Removes an author from theList
of authors for this plugin.boolean
Removes a dependency from thisPluginMetadata
.boolean
removeExtension
(String key) Removes an extension from thisPluginMetadata
.replaceDependency
(PluginDependency dependency) Replaces the currentPluginDependency
with the same plugin ID with a new one.void
setDescription
(@Nullable String description) Sets the plugin description.void
setExtension
(String key, Object extension) Adds the specified extension to thisPluginMetadata
.void
Sets the plugin ID that is represented by thisPluginMetadata
.void
Sets the plugin name.void
Sets a URL where additional information about a plugin may be found.void
setVersion
(@Nullable String version) Sets the plugin version.toString()
url()
Returns a URL where additional information about a plugin may be found.version()
Returns the plugin version.
-
Field Details
-
ID_PATTERN
The pattern plugin IDs must match. Plugin IDs must be lower case, and start with an alphabetic character. It may only contain alphanumeric characters, dashes or underscores. It must be at least 2 characters, and cannot be longer than 64 characters.
-
-
Constructor Details
-
PluginMetadata
Constructs a newPluginMetadata
with the specified plugin ID.- Parameters:
id
- The plugin ID- Throws:
IllegalArgumentException
- If the plugin ID is empty
-
-
Method Details
-
id
Returns the plugin ID that is represented by thisPluginMetadata
.- Returns:
- The plugin ID
-
setId
Sets the plugin ID that is represented by thisPluginMetadata
.- Parameters:
id
- The plugin ID- Throws:
IllegalArgumentException
- If the plugin ID is empty
-
name
Returns the plugin name.- Returns:
- The plugin name or
null
if unknown
-
setName
Sets the plugin name.- Parameters:
name
- The plugin name ornull
to reset
-
version
Returns the plugin version.- Returns:
- The plugin version or
null
if unknown
-
setVersion
Sets the plugin version.- Parameters:
version
- The plugin version ornull
to reset
-
description
Returns the plugin description.- Returns:
- The plugin description or
null
if unknown
-
setDescription
Sets the plugin description.- Parameters:
description
- The plugin description ornull
to reset
-
url
Returns a URL where additional information about a plugin may be found.- Returns:
- The URL or
null
if unknown
-
setUrl
Sets a URL where additional information about a plugin may be found.- Parameters:
url
- The URL ornull
to reset
-
authors
Returns a mutableList
of authors for this plugin.The returned list can be used to remove an author from the metadata.
- Returns:
- The list of authors, can be empty
-
addAuthor
Adds an author to theList
of authors for this plugin.- Parameters:
author
- The author to add- Throws:
IllegalArgumentException
- If the author is empty
-
addAuthors
Adds the authors to theList
of authors for this plugin.- Parameters:
authors
- The authors to add- Throws:
IllegalArgumentException
- If the author is empty or has any invalid authors
-
removeAuthor
Removes an author from theList
of authors for this plugin.- Parameters:
author
- The author to remove- Returns:
- True if the operation was successful
-
dependencies
Returns aCollection
with all dependencies of the plugin represented by thisPluginMetadata
.It is possible to remove elements from the returned collection, however new elements must be added using
addDependency(PluginDependency)
.- Returns:
- A collection with all dependencies
-
dependenciesById
Returns aMap
with all dependencies grouped by their plugin ID.- Returns:
- A map with all dependencies and their plugin IDs
-
collectRequiredDependencies
Collects all dependencies of thisPluginMetadata
that are not optional.- Returns:
- An immutable set of all required dependencies
-
groupDependenciesByLoadOrder
Groups the dependencies of thisPluginMetadata
based on theirPluginDependency.LoadOrder
.- Returns:
- An immutable map with all dependencies grouped by their load order
-
dependency
Returns thePluginDependency
that is currently associated with the specified plugin ID.- Parameters:
id
- The plugin ID of the dependency- Returns:
- The dependency or
null
if there is no such dependency
-
addDependency
Adds a newPluginDependency
to thisPluginMetadata
.- Parameters:
dependency
- The dependency to add- Throws:
IllegalArgumentException
- If this plugin already has a dependency with the specified plugin ID
-
addDependencies
Adds the list ofPluginDependency
to thisPluginMetadata
.- Parameters:
dependencies
- The dependencies to add- Throws:
IllegalArgumentException
- If the plugins are null or invalid
-
replaceDependency
Replaces the currentPluginDependency
with the same plugin ID with a new one. UnlikeaddDependency(PluginDependency)
this method doesn't throw an exception if a dependency with the same plugin ID exists already.- Parameters:
dependency
- The dependency to add- Returns:
- The dependency that was previously registered for the plugin ID
or
null
if this is a new dependency
-
removeDependency
Removes a dependency from thisPluginMetadata
.- Parameters:
id
- The plugin ID of the dependency to remove- Returns:
- True if the operation was successful
-
extensions
Returns aMap
with additional properties for thisPluginMetadata
.To serialize arbitrary objects, it may be necessary to register a custom serializer for the extension object.
- Returns:
- An unmodifiable map with additional properties
-
getExtension
Returns the value for a specific extension.Note: This method will not verify if this metadata contains a value with the specified type. A
ClassCastException
will be thrown if the value has a different type.- Type Parameters:
T
- The type to cast the extension to- Parameters:
key
- The key of the extension- Returns:
- The extension or
null
if not set - Throws:
ClassCastException
- If the given type does not match the type of the extension
-
setExtension
Adds the specified extension to thisPluginMetadata
.- Parameters:
key
- The key of the extensionextension
- The extension
-
removeExtension
Removes an extension from thisPluginMetadata
.- Parameters:
key
- The key of the extension- Returns:
- True if the operation was successful
-
accept
Replaces the properties in thisPluginMetadata
with all properties of the specifiedPluginMetadata
that are not empty.- Specified by:
accept
in interfaceConsumer<PluginMetadata>
- Parameters:
other
- The plugin metadata to apply- Throws:
IllegalArgumentException
- If the plugin IDs don't match
-
toString
-