From 830b1d4798ce5c5c118d33cad752e639f37e4862 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Tue, 21 Aug 2018 20:37:10 +0200 Subject: [PATCH 1/2] 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 --- .gitignore | 3 +- .../ap/SerializedPluginDescription.java | 74 +++++++++++-------- .../velocitypowered/api/plugin/Plugin.java | 15 ++++ .../api/plugin/PluginDescription.java | 34 +++++++-- .../api/plugin/meta/PluginDependency.java | 8 +- .../proxy/plugin/loader/JavaPluginLoader.java | 17 ++--- .../loader/VelocityPluginContainer.java | 13 ++-- .../loader/VelocityPluginDescription.java | 30 ++++++-- .../java/JavaVelocityPluginDescription.java | 9 ++- .../java/SerializedPluginDescription.java | 74 +++++++++++-------- .../proxy/testutil/FakePluginManager.java | 19 +---- 11 files changed, 180 insertions(+), 116 deletions(-) diff --git a/.gitignore b/.gitignore index 3fc46f0ef..6b39e43d9 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,5 @@ gradle-app.setting logs/ /velocity.toml server-icon.png -/bin/ \ No newline at end of file +/bin/ +run/ diff --git a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java index 0458aadfe..12109985e 100644 --- a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java +++ b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java @@ -1,8 +1,9 @@ package com.velocitypowered.api.plugin.ap; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; +import com.google.common.base.Strings; import com.velocitypowered.api.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -11,22 +12,23 @@ import java.util.Objects; import java.util.stream.Collectors; public class SerializedPluginDescription { + // @Nullable is used here to make GSON skip these in the serialized file private final String id; - private final List authors; + private final @Nullable String name; + private final @Nullable String version; + private final @Nullable String url; + private final @Nullable List authors; + private final @Nullable List dependencies; private final String main; - private final String version; - private final List dependencies; - public SerializedPluginDescription(String id, List author, String main, String version) { - this(id, author, main, version, ImmutableList.of()); - } - - public SerializedPluginDescription(String id, List authors, String main, String version, List dependencies) { + public SerializedPluginDescription(String id, String name, String version, String url, List authors, List dependencies, String main) { this.id = Preconditions.checkNotNull(id, "id"); - this.authors = Preconditions.checkNotNull(authors, "authors"); + this.name = Strings.emptyToNull(name); + this.version = Strings.emptyToNull(version); + this.url = Strings.emptyToNull(url); + this.authors = authors == null || authors.isEmpty() ? null : authors; + this.dependencies = dependencies == null || dependencies.isEmpty() ? null : dependencies; this.main = Preconditions.checkNotNull(main, "main"); - this.version = Preconditions.checkNotNull(version, "version"); - this.dependencies = ImmutableList.copyOf(dependencies); } public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) { @@ -34,54 +36,66 @@ public class SerializedPluginDescription { for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { dependencies.add(new Dependency(dependency.id(), dependency.optional())); } - return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies); + return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.url(), + Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName); } public String getId() { return id; } - public List getAuthors() { + public @Nullable String getName() { + return name; + } + + public @Nullable String getVersion() { + return version; + } + + public @Nullable String getUrl() { + return url; + } + + public @Nullable List getAuthors() { return authors; } + public @Nullable List getDependencies() { + return dependencies; + } + public String getMain() { return main; } - public String getVersion() { - return version; - } - - public List getDependencies() { - return dependencies; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerializedPluginDescription that = (SerializedPluginDescription) o; return Objects.equals(id, that.id) && - Objects.equals(authors, that.authors) && - Objects.equals(main, that.main) && + Objects.equals(name, that.name) && Objects.equals(version, that.version) && - Objects.equals(dependencies, that.dependencies); + Objects.equals(url, that.url) && + Objects.equals(authors, that.authors) && + Objects.equals(dependencies, that.dependencies) && + Objects.equals(main, that.main); } @Override public int hashCode() { - return Objects.hash(id, authors, main, version, dependencies); + return Objects.hash(id, name, version, url, authors, dependencies); } - @Override - public String toString() { + @Override public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + - ", authors='" + authors + '\'' + - ", main='" + main + '\'' + + ", name='" + name + '\'' + ", version='" + version + '\'' + + ", url='" + url + '\'' + + ", authors=" + authors + ", dependencies=" + dependencies + + ", main='" + main + '\'' + '}'; } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java b/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java index 98cd165f7..3b0ab9fe2 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java @@ -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. * diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java index 8968ca6b4..78a1b5399 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java @@ -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 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 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 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 getAuthors(); + default List getAuthors() { + return ImmutableList.of(); + } /** * Gets a {@link Collection} of all dependencies of the {@link Plugin} within diff --git a/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java b/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java index eb792b9a8..f63b87c5c 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java @@ -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 getVersion() { + return Optional.ofNullable(version); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java index c91fe36ff..09ba72397 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java @@ -77,14 +77,7 @@ public class JavaPluginLoader implements PluginLoader { Injector injector = Guice.createInjector(new VelocityPluginModule(server, javaDescription, baseDirectory)); Object instance = injector.getInstance(javaDescription.getMainClass()); - return new VelocityPluginContainer( - description.getId(), - description.getVersion(), - description.getAuthors(), - description.getDependencies(), - source.get(), - instance - ); + return new VelocityPluginContainer(description, instance); } private Optional getSerializedPluginInfo(Path source) throws Exception { @@ -105,13 +98,17 @@ public class JavaPluginLoader implements PluginLoader { private VelocityPluginDescription createDescription(SerializedPluginDescription description, Path source, Class mainClass) { Set dependencies = new HashSet<>(); - for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) { - dependencies.add(toDependencyMeta(dependency)); + if (description.getDependencies() != null) { + for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) { + dependencies.add(toDependencyMeta(dependency)); + } } return new JavaVelocityPluginDescription( description.getId(), + description.getName(), description.getVersion(), + description.getUrl(), description.getAuthors(), dependencies, source, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java index f628787c9..d7cea4c4a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java @@ -2,24 +2,21 @@ package com.velocitypowered.proxy.plugin.loader; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginDescription; -import com.velocitypowered.api.plugin.meta.PluginDependency; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; import java.util.Optional; -public class VelocityPluginContainer extends VelocityPluginDescription implements PluginContainer { +public class VelocityPluginContainer implements PluginContainer { + private final PluginDescription description; private final Object instance; - public VelocityPluginContainer(String id, String version, List authors, Collection dependencies, Path source, Object instance) { - super(id, version, authors, dependencies, source); + public VelocityPluginContainer(PluginDescription description, Object instance) { + this.description = description; this.instance = instance; } @Override public PluginDescription getDescription() { - return this; + return this.description; } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java index 79618e56f..769ed3c41 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java @@ -1,8 +1,11 @@ package com.velocitypowered.proxy.plugin.loader; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.velocitypowered.api.plugin.PluginDescription; import com.velocitypowered.api.plugin.meta.PluginDependency; +import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.file.Path; import java.util.Collection; @@ -14,15 +17,20 @@ import static com.google.common.base.Preconditions.checkNotNull; public class VelocityPluginDescription implements PluginDescription { private final String id; - private final String version; + private final @Nullable String name; + private final @Nullable String version; + private final @Nullable String url; private final List authors; private final Map dependencies; private final Path source; - public VelocityPluginDescription(String id, String version, List authors, Collection dependencies, Path source) { + public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String url, + @Nullable List authors, Collection dependencies, Path source) { this.id = checkNotNull(id, "id"); - this.version = checkNotNull(version, "version"); - this.authors = checkNotNull(authors, "authors"); + this.name = Strings.emptyToNull(name); + this.version = Strings.emptyToNull(version); + this.url = Strings.emptyToNull(url); + this.authors = authors == null ? ImmutableList.of() : ImmutableList.copyOf(authors); this.dependencies = Maps.uniqueIndex(dependencies, PluginDependency::getId); this.source = source; } @@ -33,8 +41,18 @@ public class VelocityPluginDescription implements PluginDescription { } @Override - public String getVersion() { - return version; + public Optional getName() { + return Optional.ofNullable(name); + } + + @Override + public Optional getVersion() { + return Optional.ofNullable(version); + } + + @Override + public Optional getUrl() { + return Optional.ofNullable(url); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java index 303afca31..a827dc202 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java @@ -10,14 +10,15 @@ import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; public class JavaVelocityPluginDescription extends VelocityPluginDescription { - private final Class mainClass; + private final Class mainClass; - public JavaVelocityPluginDescription(String id, String version, List authors, Collection dependencies, Path source, Class mainClass) { - super(id, version, authors, dependencies, source); + public JavaVelocityPluginDescription(String id, String name, String version, String url, List authors, + Collection dependencies, Path source, Class mainClass) { + super(id, name, version, url, authors, dependencies, source); this.mainClass = checkNotNull(mainClass); } - public Class getMainClass() { + public Class getMainClass() { return mainClass; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java index f8f2adcb1..9e60f40ef 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java @@ -1,8 +1,9 @@ package com.velocitypowered.proxy.plugin.loader.java; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; +import com.google.common.base.Strings; import com.velocitypowered.api.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -11,22 +12,23 @@ import java.util.Objects; import java.util.stream.Collectors; public class SerializedPluginDescription { + // @Nullable is used here to make GSON skip these in the serialized file private final String id; - private final List authors; + private final @Nullable String name; + private final @Nullable String version; + private final @Nullable String url; + private final @Nullable List authors; + private final @Nullable List dependencies; private final String main; - private final String version; - private final List dependencies; - public SerializedPluginDescription(String id, List authors, String main, String version) { - this(id, authors, main, version, ImmutableList.of()); - } - - public SerializedPluginDescription(String id, List authors, String main, String version, List dependencies) { + public SerializedPluginDescription(String id, String name, String version, String url, List authors, List dependencies, String main) { this.id = Preconditions.checkNotNull(id, "id"); - this.authors = Preconditions.checkNotNull(authors, "author"); + this.name = Strings.emptyToNull(name); + this.version = Strings.emptyToNull(version); + this.url = Strings.emptyToNull(url); + this.authors = authors == null || authors.isEmpty() ? null : authors; + this.dependencies = dependencies == null || dependencies.isEmpty() ? null : dependencies; this.main = Preconditions.checkNotNull(main, "main"); - this.version = Preconditions.checkNotNull(version, "version"); - this.dependencies = ImmutableList.copyOf(dependencies); } public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) { @@ -34,54 +36,66 @@ public class SerializedPluginDescription { for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { dependencies.add(new Dependency(dependency.id(), dependency.optional())); } - return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies); + return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.url(), + Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName); } public String getId() { return id; } - public List getAuthors() { + public @Nullable String getName() { + return name; + } + + public @Nullable String getVersion() { + return version; + } + + public @Nullable String getUrl() { + return url; + } + + public @Nullable List getAuthors() { return authors; } + public @Nullable List getDependencies() { + return dependencies; + } + public String getMain() { return main; } - public String getVersion() { - return version; - } - - public List getDependencies() { - return dependencies; - } - @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; SerializedPluginDescription that = (SerializedPluginDescription) o; return Objects.equals(id, that.id) && - Objects.equals(authors, that.authors) && - Objects.equals(main, that.main) && + Objects.equals(name, that.name) && Objects.equals(version, that.version) && - Objects.equals(dependencies, that.dependencies); + Objects.equals(url, that.url) && + Objects.equals(authors, that.authors) && + Objects.equals(dependencies, that.dependencies) && + Objects.equals(main, that.main); } @Override public int hashCode() { - return Objects.hash(id, authors, main, version, dependencies); + return Objects.hash(id, name, version, url, authors, dependencies); } - @Override - public String toString() { + @Override public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + - ", authors='" + authors + '\'' + - ", main='" + main + '\'' + + ", name='" + name + '\'' + ", version='" + version + '\'' + + ", url='" + url + '\'' + + ", authors=" + authors + ", dependencies=" + dependencies + + ", main='" + main + '\'' + '}'; } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java index 23c83b8b1..86fb450ea 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -8,8 +8,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import java.nio.file.Path; import java.util.Collection; -import java.util.Collections; -import java.util.List; import java.util.Optional; public class FakePluginManager implements PluginManager { @@ -68,22 +66,7 @@ public class FakePluginManager implements PluginManager { @Override public @NonNull PluginDescription getDescription() { - return new PluginDescription() { - @Override - public String getId() { - return id; - } - - @Override - public String getVersion() { - return ""; - } - - @Override - public List getAuthors() { - return Collections.emptyList(); - } - }; + return () -> id; } @Override From c43c6cbea200754f0162fe92891000025da73ab0 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Tue, 21 Aug 2018 21:18:10 +0200 Subject: [PATCH 2/2] Add plugin description --- .../plugin/ap/SerializedPluginDescription.java | 18 ++++++++++++++---- .../com/velocitypowered/api/plugin/Plugin.java | 7 +++++++ .../api/plugin/PluginDescription.java | 10 ++++++++++ .../proxy/plugin/loader/JavaPluginLoader.java | 1 + .../loader/VelocityPluginDescription.java | 14 ++++++++++++-- .../java/JavaVelocityPluginDescription.java | 7 ++++--- .../java/SerializedPluginDescription.java | 18 ++++++++++++++---- 7 files changed, 62 insertions(+), 13 deletions(-) diff --git a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java index 12109985e..925074cc2 100644 --- a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java +++ b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java @@ -16,15 +16,18 @@ public class SerializedPluginDescription { private final String id; private final @Nullable String name; private final @Nullable String version; + private final @Nullable String description; private final @Nullable String url; private final @Nullable List authors; private final @Nullable List dependencies; private final String main; - public SerializedPluginDescription(String id, String name, String version, String url, List authors, List dependencies, String main) { + public SerializedPluginDescription(String id, String name, String version, String description, String url, + List authors, List dependencies, String main) { this.id = Preconditions.checkNotNull(id, "id"); this.name = Strings.emptyToNull(name); this.version = Strings.emptyToNull(version); + this.description = Strings.emptyToNull(description); this.url = Strings.emptyToNull(url); this.authors = authors == null || authors.isEmpty() ? null : authors; this.dependencies = dependencies == null || dependencies.isEmpty() ? null : dependencies; @@ -36,7 +39,7 @@ public class SerializedPluginDescription { for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { dependencies.add(new Dependency(dependency.id(), dependency.optional())); } - return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.url(), + return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.description(), plugin.url(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName); } @@ -52,6 +55,10 @@ public class SerializedPluginDescription { return version; } + public @Nullable String getDescription() { + return description; + } + public @Nullable String getUrl() { return url; } @@ -76,6 +83,7 @@ public class SerializedPluginDescription { return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(version, that.version) && + Objects.equals(description, that.description) && Objects.equals(url, that.url) && Objects.equals(authors, that.authors) && Objects.equals(dependencies, that.dependencies) && @@ -84,14 +92,16 @@ public class SerializedPluginDescription { @Override public int hashCode() { - return Objects.hash(id, name, version, url, authors, dependencies); + return Objects.hash(id, name, version, description, url, authors, dependencies); } - @Override public String toString() { + @Override + public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", version='" + version + '\'' + + ", description='" + description + '\'' + ", url='" + url + '\'' + ", authors=" + authors + ", dependencies=" + dependencies + diff --git a/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java b/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java index 3b0ab9fe2..b3e603f13 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java @@ -36,6 +36,13 @@ public @interface Plugin { */ String version() default ""; + /** + * The description of the plugin, explaining what it can be used for. + * + * @return The plugin description, or an empty string if unknown + */ + String description() default ""; + /** * The URL or website of the plugin. * diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java index 78a1b5399..d789f68c5 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java @@ -49,6 +49,16 @@ public interface PluginDescription { return Optional.empty(); } + /** + * Gets the description of the {@link Plugin} within this container. + * + * @return an {@link Optional} with the plugin description, may be empty + * @see Plugin#description() + */ + default Optional getDescription() { + return Optional.empty(); + } + /** * Gets the url or website of the {@link Plugin} within this container. * diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java index 09ba72397..e1ed51ff8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/JavaPluginLoader.java @@ -108,6 +108,7 @@ public class JavaPluginLoader implements PluginLoader { description.getId(), description.getName(), description.getVersion(), + description.getDescription(), description.getUrl(), description.getAuthors(), dependencies, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java index 769ed3c41..0ee55c112 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java @@ -19,16 +19,18 @@ public class VelocityPluginDescription implements PluginDescription { private final String id; private final @Nullable String name; private final @Nullable String version; + private final @Nullable String description; private final @Nullable String url; private final List authors; private final Map dependencies; private final Path source; - public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String url, + public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url, @Nullable List authors, Collection dependencies, Path source) { this.id = checkNotNull(id, "id"); this.name = Strings.emptyToNull(name); this.version = Strings.emptyToNull(version); + this.description = Strings.emptyToNull(description); this.url = Strings.emptyToNull(url); this.authors = authors == null ? ImmutableList.of() : ImmutableList.copyOf(authors); this.dependencies = Maps.uniqueIndex(dependencies, PluginDependency::getId); @@ -50,6 +52,11 @@ public class VelocityPluginDescription implements PluginDescription { return Optional.ofNullable(version); } + @Override + public Optional getDescription() { + return Optional.ofNullable(description); + } + @Override public Optional getUrl() { return Optional.ofNullable(url); @@ -79,8 +86,11 @@ public class VelocityPluginDescription implements PluginDescription { public String toString() { return "VelocityPluginDescription{" + "id='" + id + '\'' + + ", name='" + name + '\'' + ", version='" + version + '\'' + - ", authors='" + authors + '\'' + + ", description='" + description + '\'' + + ", url='" + url + '\'' + + ", authors=" + authors + ", dependencies=" + dependencies + ", source=" + source + '}'; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java index a827dc202..a73aaec78 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaVelocityPluginDescription.java @@ -2,6 +2,7 @@ package com.velocitypowered.proxy.plugin.loader.java; import com.velocitypowered.api.plugin.meta.PluginDependency; import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription; +import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.file.Path; import java.util.Collection; @@ -12,9 +13,9 @@ import static com.google.common.base.Preconditions.checkNotNull; public class JavaVelocityPluginDescription extends VelocityPluginDescription { private final Class mainClass; - public JavaVelocityPluginDescription(String id, String name, String version, String url, List authors, - Collection dependencies, Path source, Class mainClass) { - super(id, name, version, url, authors, dependencies, source); + public JavaVelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url, + @Nullable List authors, Collection dependencies, Path source, Class mainClass) { + super(id, name, version, description, url, authors, dependencies, source); this.mainClass = checkNotNull(mainClass); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java index 9e60f40ef..b12b1694e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/SerializedPluginDescription.java @@ -16,15 +16,18 @@ public class SerializedPluginDescription { private final String id; private final @Nullable String name; private final @Nullable String version; + private final @Nullable String description; private final @Nullable String url; private final @Nullable List authors; private final @Nullable List dependencies; private final String main; - public SerializedPluginDescription(String id, String name, String version, String url, List authors, List dependencies, String main) { + public SerializedPluginDescription(String id, String name, String version, String description, String url, + List authors, List dependencies, String main) { this.id = Preconditions.checkNotNull(id, "id"); this.name = Strings.emptyToNull(name); this.version = Strings.emptyToNull(version); + this.description = Strings.emptyToNull(description); this.url = Strings.emptyToNull(url); this.authors = authors == null || authors.isEmpty() ? null : authors; this.dependencies = dependencies == null || dependencies.isEmpty() ? null : dependencies; @@ -36,7 +39,7 @@ public class SerializedPluginDescription { for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { dependencies.add(new Dependency(dependency.id(), dependency.optional())); } - return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.url(), + return new SerializedPluginDescription(plugin.id(), plugin.name(), plugin.version(), plugin.description(), plugin.url(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName); } @@ -52,6 +55,10 @@ public class SerializedPluginDescription { return version; } + public @Nullable String getDescription() { + return description; + } + public @Nullable String getUrl() { return url; } @@ -76,6 +83,7 @@ public class SerializedPluginDescription { return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(version, that.version) && + Objects.equals(description, that.description) && Objects.equals(url, that.url) && Objects.equals(authors, that.authors) && Objects.equals(dependencies, that.dependencies) && @@ -84,14 +92,16 @@ public class SerializedPluginDescription { @Override public int hashCode() { - return Objects.hash(id, name, version, url, authors, dependencies); + return Objects.hash(id, name, version, description, url, authors, dependencies); } - @Override public String toString() { + @Override + public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", version='" + version + '\'' + + ", description='" + description + '\'' + ", url='" + url + '\'' + ", authors=" + authors + ", dependencies=" + dependencies +