Various improvements to plugin metadata

- Add plugin (display) name and plugin URL
 - Make everything except plugin ID optional (instead of empty string)
 - Exclude empty properties from generated velocity-plugin.json
 - Make plugin author list immutable
 - Other (minor) cleanup and refactoring
This commit is contained in:
Minecrell
2018-08-21 20:37:10 +02:00
parent fcf5ad157f
commit 830b1d4798
11 changed files with 180 additions and 116 deletions

View File

@@ -21,6 +21,14 @@ public @interface Plugin {
*/
String id();
/**
* The human readable name of the plugin as to be used in descriptions and
* similar things.
*
* @return The plugin name, or an empty string if unknown
*/
String name() default "";
/**
* The version of the plugin.
*
@@ -28,6 +36,13 @@ public @interface Plugin {
*/
String version() default "";
/**
* The URL or website of the plugin.
*
* @return The plugin url, or an empty string if unknown
*/
String url() default "";
/**
* The author of the plugin.
*

View File

@@ -1,5 +1,6 @@
package com.velocitypowered.api.plugin;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.velocitypowered.api.plugin.meta.PluginDependency;
@@ -7,7 +8,6 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
/**
@@ -29,21 +29,45 @@ public interface PluginDescription {
*/
String getId();
/**
* Gets the name of the {@link Plugin} within this container.
*
* @return an {@link Optional} with the plugin name, may be empty
* @see Plugin#name()
*/
default Optional<String> getName() {
return Optional.empty();
}
/**
* Gets the version of the {@link Plugin} within this container.
*
* @return the plugin version
* @return an {@link Optional} with the plugin version, may be empty
* @see Plugin#version()
*/
String getVersion();
default Optional<String> getVersion() {
return Optional.empty();
}
/**
* Gets the url or website of the {@link Plugin} within this container.
*
* @return an {@link Optional} with the plugin url, may be empty
* @see Plugin#url()
*/
default Optional<String> getUrl() {
return Optional.empty();
}
/**
* Gets the authors of the {@link Plugin} within this container.
*
* @return the plugin authors
* @return the plugin authors, may be empty
* @see Plugin#authors()
*/
List<String> getAuthors();
default List<String> getAuthors() {
return ImmutableList.of();
}
/**
* Gets a {@link Collection} of all dependencies of the {@link Plugin} within

View File

@@ -3,6 +3,7 @@ package com.velocitypowered.api.plugin.meta;
import javax.annotation.Nullable;
import java.util.Objects;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -36,11 +37,10 @@ public final class PluginDependency {
/**
* Returns the version this {@link PluginDependency} should match.
*
* @return the plugin version, or {@code null} if unspecified
* @return an {@link Optional} with the plugin version, may be empty
*/
@Nullable
public String getVersion() {
return version;
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
/**