java.lang.Object
org.spongepowered.plugin.meta.PluginMetadata
All Implemented Interfaces:
Consumer<PluginMetadata>

public final class PluginMetadata extends Object implements Consumer<PluginMetadata>
Represents additional metadata for a specific version of a plugin.
  • Field Details

    • ID_PATTERN

      public static final Pattern 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

  • Method Details

    • id

      public String id()
      Returns the plugin ID that is represented by this PluginMetadata.
      Returns:
      The plugin ID
    • setId

      public void setId(String id)
      Sets the plugin ID that is represented by this PluginMetadata.
      Parameters:
      id - The plugin ID
      Throws:
      IllegalArgumentException - If the plugin ID is empty
    • name

      public @Nullable String name()
      Returns the plugin name.
      Returns:
      The plugin name or null if unknown
    • setName

      public void setName(@Nullable String name)
      Sets the plugin name.
      Parameters:
      name - The plugin name or null to reset
    • version

      public @Nullable String version()
      Returns the plugin version.
      Returns:
      The plugin version or null if unknown
    • setVersion

      public void setVersion(@Nullable String version)
      Sets the plugin version.
      Parameters:
      version - The plugin version or null to reset
    • description

      public @Nullable String description()
      Returns the plugin description.
      Returns:
      The plugin description or null if unknown
    • setDescription

      public void setDescription(@Nullable String description)
      Sets the plugin description.
      Parameters:
      description - The plugin description or null to reset
    • url

      public @Nullable String url()
      Returns a URL where additional information about a plugin may be found.
      Returns:
      The URL or null if unknown
    • setUrl

      public void setUrl(@Nullable String url)
      Sets a URL where additional information about a plugin may be found.
      Parameters:
      url - The URL or null to reset
    • authors

      public List<String> authors()
      Returns a mutable List 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

      public void addAuthor(String author)
      Adds an author to the List of authors for this plugin.
      Parameters:
      author - The author to add
      Throws:
      IllegalArgumentException - If the author is empty
    • addAuthors

      public void addAuthors(String... authors)
      Adds the authors to the List of authors for this plugin.
      Parameters:
      authors - The authors to add
      Throws:
      IllegalArgumentException - If the author is empty or has any invalid authors
    • removeAuthor

      public boolean removeAuthor(String author)
      Removes an author from the List of authors for this plugin.
      Parameters:
      author - The author to remove
      Returns:
      True if the operation was successful
    • dependencies

      public Collection<PluginDependency> dependencies()
      Returns a Collection with all dependencies of the plugin represented by this PluginMetadata.

      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

      public Map<String,PluginDependency> dependenciesById()
      Returns a Map with all dependencies grouped by their plugin ID.
      Returns:
      A map with all dependencies and their plugin IDs
    • collectRequiredDependencies

      public Set<PluginDependency> collectRequiredDependencies()
      Collects all dependencies of this PluginMetadata that are not optional.
      Returns:
      An immutable set of all required dependencies
    • groupDependenciesByLoadOrder

      public Map<PluginDependency.LoadOrder,Set<PluginDependency>> groupDependenciesByLoadOrder()
      Groups the dependencies of this PluginMetadata based on their PluginDependency.LoadOrder.
      Returns:
      An immutable map with all dependencies grouped by their load order
    • dependency

      public @Nullable PluginDependency dependency(String id)
      Returns the PluginDependency 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

      public void addDependency(PluginDependency dependency)
      Adds a new PluginDependency to this PluginMetadata.
      Parameters:
      dependency - The dependency to add
      Throws:
      IllegalArgumentException - If this plugin already has a dependency with the specified plugin ID
    • addDependencies

      public void addDependencies(PluginDependency... dependencies)
      Adds the list of PluginDependency to this PluginMetadata.
      Parameters:
      dependencies - The dependencies to add
      Throws:
      IllegalArgumentException - If the plugins are null or invalid
    • replaceDependency

      public @Nullable PluginDependency replaceDependency(PluginDependency dependency)
      Replaces the current PluginDependency with the same plugin ID with a new one. Unlike addDependency(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

      public boolean removeDependency(String id)
      Removes a dependency from this PluginMetadata.
      Parameters:
      id - The plugin ID of the dependency to remove
      Returns:
      True if the operation was successful
    • extensions

      public Map<String,Object> extensions()
      Returns a Map with additional properties for this PluginMetadata.

      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

      public <T> @Nullable T getExtension(String key)
      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

      public void setExtension(String key, Object extension)
      Adds the specified extension to this PluginMetadata.
      Parameters:
      key - The key of the extension
      extension - The extension
    • removeExtension

      public boolean removeExtension(String key)
      Removes an extension from this PluginMetadata.
      Parameters:
      key - The key of the extension
      Returns:
      True if the operation was successful
    • accept

      public void accept(PluginMetadata other)
      Replaces the properties in this PluginMetadata with all properties of the specified PluginMetadata that are not empty.
      Specified by:
      accept in interface Consumer<PluginMetadata>
      Parameters:
      other - The plugin metadata to apply
      Throws:
      IllegalArgumentException - If the plugin IDs don't match
    • toString

      public String toString()
      Overrides:
      toString in class Object