From c4fdac95919441e6b34986e176e867f33b11fb0f Mon Sep 17 00:00:00 2001 From: kashike Date: Tue, 21 Aug 2018 09:09:48 -0700 Subject: [PATCH] allow more than one author --- .../ap/SerializedPluginDescription.java | 22 +++++++++-------- .../velocitypowered/api/plugin/Plugin.java | 2 +- .../api/plugin/PluginDescription.java | 9 +++---- .../proxy/plugin/loader/JavaPluginLoader.java | 4 ++-- .../loader/VelocityPluginContainer.java | 5 ++-- .../loader/VelocityPluginDescription.java | 13 +++++----- .../java/JavaVelocityPluginDescription.java | 5 ++-- .../java/SerializedPluginDescription.java | 24 ++++++++++--------- .../proxy/testutil/FakePluginManager.java | 6 +++-- 9 files changed, 50 insertions(+), 40 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 d22aeeb16..0458aadfe 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 @@ -5,23 +5,25 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.plugin.Plugin; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class SerializedPluginDescription { private final String id; - private final String author; + private final List authors; private final String main; private final String version; private final List dependencies; - public SerializedPluginDescription(String id, String author, String main, String version) { + public SerializedPluginDescription(String id, List author, String main, String version) { this(id, author, main, version, ImmutableList.of()); } - public SerializedPluginDescription(String id, String author, String main, String version, List dependencies) { + public SerializedPluginDescription(String id, List authors, String main, String version, List dependencies) { this.id = Preconditions.checkNotNull(id, "id"); - this.author = Preconditions.checkNotNull(author, "author"); + this.authors = Preconditions.checkNotNull(authors, "authors"); this.main = Preconditions.checkNotNull(main, "main"); this.version = Preconditions.checkNotNull(version, "version"); this.dependencies = ImmutableList.copyOf(dependencies); @@ -32,15 +34,15 @@ 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.author(), qualifiedName, plugin.version(), dependencies); + return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies); } public String getId() { return id; } - public String getAuthor() { - return author; + public List getAuthors() { + return authors; } public String getMain() { @@ -61,7 +63,7 @@ public class SerializedPluginDescription { if (o == null || getClass() != o.getClass()) return false; SerializedPluginDescription that = (SerializedPluginDescription) o; return Objects.equals(id, that.id) && - Objects.equals(author, that.author) && + Objects.equals(authors, that.authors) && Objects.equals(main, that.main) && Objects.equals(version, that.version) && Objects.equals(dependencies, that.dependencies); @@ -69,14 +71,14 @@ public class SerializedPluginDescription { @Override public int hashCode() { - return Objects.hash(id, author, main, version, dependencies); + return Objects.hash(id, authors, main, version, dependencies); } @Override public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + - ", author='" + author + '\'' + + ", authors='" + authors + '\'' + ", main='" + main + '\'' + ", version='" + version + '\'' + ", 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 4f7ab93ed..98cd165f7 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/Plugin.java @@ -33,7 +33,7 @@ public @interface Plugin { * * @return the plugin's author, or empty if unknown */ - String author() default ""; + String[] authors() default ""; /** * The dependencies required to load before this 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 a61274e8d..8968ca6b4 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java @@ -5,6 +5,7 @@ import com.velocitypowered.api.plugin.meta.PluginDependency; 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; @@ -37,12 +38,12 @@ public interface PluginDescription { String getVersion(); /** - * Gets the author of the {@link Plugin} within this container. + * Gets the authors of the {@link Plugin} within this container. * - * @return the plugin author - * @see Plugin#author() + * @return the plugin authors + * @see Plugin#authors() */ - String getAuthor(); + List getAuthors(); /** * Gets a {@link Collection} of all dependencies of the {@link Plugin} within 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 bcbd0d36a..c91fe36ff 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 @@ -80,7 +80,7 @@ public class JavaPluginLoader implements PluginLoader { return new VelocityPluginContainer( description.getId(), description.getVersion(), - description.getAuthor(), + description.getAuthors(), description.getDependencies(), source.get(), instance @@ -112,7 +112,7 @@ public class JavaPluginLoader implements PluginLoader { return new JavaVelocityPluginDescription( description.getId(), description.getVersion(), - description.getAuthor(), + description.getAuthors(), dependencies, source, mainClass 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 b3cb0454a..f628787c9 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 @@ -6,13 +6,14 @@ 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 { private final Object instance; - public VelocityPluginContainer(String id, String version, String author, Collection dependencies, Path source, Object instance) { - super(id, version, author, dependencies, source); + public VelocityPluginContainer(String id, String version, List authors, Collection dependencies, Path source, Object instance) { + super(id, version, authors, dependencies, source); this.instance = instance; } 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 4aa490180..79618e56f 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 @@ -6,6 +6,7 @@ import com.velocitypowered.api.plugin.meta.PluginDependency; import java.nio.file.Path; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -14,14 +15,14 @@ import static com.google.common.base.Preconditions.checkNotNull; public class VelocityPluginDescription implements PluginDescription { private final String id; private final String version; - private final String author; + private final List authors; private final Map dependencies; private final Path source; - public VelocityPluginDescription(String id, String version, String author, Collection dependencies, Path source) { + public VelocityPluginDescription(String id, String version, List authors, Collection dependencies, Path source) { this.id = checkNotNull(id, "id"); this.version = checkNotNull(version, "version"); - this.author = checkNotNull(author, "author"); + this.authors = checkNotNull(authors, "authors"); this.dependencies = Maps.uniqueIndex(dependencies, PluginDependency::getId); this.source = source; } @@ -37,8 +38,8 @@ public class VelocityPluginDescription implements PluginDescription { } @Override - public String getAuthor() { - return author; + public List getAuthors() { + return authors; } @Override @@ -61,7 +62,7 @@ public class VelocityPluginDescription implements PluginDescription { return "VelocityPluginDescription{" + "id='" + id + '\'' + ", version='" + version + '\'' + - ", author='" + author + '\'' + + ", 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 1b0ce229b..303afca31 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 @@ -5,14 +5,15 @@ import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription; import java.nio.file.Path; import java.util.Collection; +import java.util.List; import static com.google.common.base.Preconditions.checkNotNull; public class JavaVelocityPluginDescription extends VelocityPluginDescription { private final Class mainClass; - public JavaVelocityPluginDescription(String id, String version, String author, Collection dependencies, Path source, Class mainClass) { - super(id, version, author, dependencies, source); + public JavaVelocityPluginDescription(String id, String version, List authors, Collection dependencies, Path source, Class mainClass) { + super(id, version, 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 aeaffc867..f8f2adcb1 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 @@ -5,23 +5,25 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.plugin.Plugin; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; public class SerializedPluginDescription { private final String id; - private final String author; + private final List authors; private final String main; private final String version; private final List dependencies; - public SerializedPluginDescription(String id, String author, String main, String version) { - this(id, author, main, version, ImmutableList.of()); + public SerializedPluginDescription(String id, List authors, String main, String version) { + this(id, authors, main, version, ImmutableList.of()); } - public SerializedPluginDescription(String id, String author, String main, String version, List dependencies) { + public SerializedPluginDescription(String id, List authors, String main, String version, List dependencies) { this.id = Preconditions.checkNotNull(id, "id"); - this.author = Preconditions.checkNotNull(author, "author"); + this.authors = Preconditions.checkNotNull(authors, "author"); this.main = Preconditions.checkNotNull(main, "main"); this.version = Preconditions.checkNotNull(version, "version"); this.dependencies = ImmutableList.copyOf(dependencies); @@ -32,15 +34,15 @@ 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.author(), qualifiedName, plugin.version(), dependencies); + return new SerializedPluginDescription(plugin.id(), Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), qualifiedName, plugin.version(), dependencies); } public String getId() { return id; } - public String getAuthor() { - return author; + public List getAuthors() { + return authors; } public String getMain() { @@ -61,7 +63,7 @@ public class SerializedPluginDescription { if (o == null || getClass() != o.getClass()) return false; SerializedPluginDescription that = (SerializedPluginDescription) o; return Objects.equals(id, that.id) && - Objects.equals(author, that.author) && + Objects.equals(authors, that.authors) && Objects.equals(main, that.main) && Objects.equals(version, that.version) && Objects.equals(dependencies, that.dependencies); @@ -69,14 +71,14 @@ public class SerializedPluginDescription { @Override public int hashCode() { - return Objects.hash(id, author, main, version, dependencies); + return Objects.hash(id, authors, main, version, dependencies); } @Override public String toString() { return "SerializedPluginDescription{" + "id='" + id + '\'' + - ", author='" + author + '\'' + + ", authors='" + authors + '\'' + ", main='" + main + '\'' + ", version='" + version + '\'' + ", dependencies=" + dependencies + 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 5e5a30e40..23c83b8b1 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -8,6 +8,8 @@ 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 { @@ -78,8 +80,8 @@ public class FakePluginManager implements PluginManager { } @Override - public String getAuthor() { - return ""; + public List getAuthors() { + return Collections.emptyList(); } }; }