geforkt von Mirrors/Velocity
Merge pull request #44 from Minecrell/meta-cleanup
Various improvements to plugin metadata
Dieser Commit ist enthalten in:
Commit
9c4e43e1b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -131,3 +131,4 @@ logs/
|
|||||||
/velocity.toml
|
/velocity.toml
|
||||||
server-icon.png
|
server-icon.png
|
||||||
/bin/
|
/bin/
|
||||||
|
run/
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package com.velocitypowered.api.plugin.ap;
|
package com.velocitypowered.api.plugin.ap;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
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 com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -11,22 +12,26 @@ import java.util.Objects;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SerializedPluginDescription {
|
public class SerializedPluginDescription {
|
||||||
|
// @Nullable is used here to make GSON skip these in the serialized file
|
||||||
private final String id;
|
private final String id;
|
||||||
private final List<String> authors;
|
private final @Nullable String name;
|
||||||
|
private final @Nullable String version;
|
||||||
|
private final @Nullable String description;
|
||||||
|
private final @Nullable String url;
|
||||||
|
private final @Nullable List<String> authors;
|
||||||
|
private final @Nullable List<Dependency> dependencies;
|
||||||
private final String main;
|
private final String main;
|
||||||
private final String version;
|
|
||||||
private final List<Dependency> dependencies;
|
|
||||||
|
|
||||||
public SerializedPluginDescription(String id, List<String> author, String main, String version) {
|
public SerializedPluginDescription(String id, String name, String version, String description, String url,
|
||||||
this(id, author, main, version, ImmutableList.of());
|
List<String> authors, List<Dependency> dependencies, String main) {
|
||||||
}
|
|
||||||
|
|
||||||
public SerializedPluginDescription(String id, List<String> authors, String main, String version, List<Dependency> dependencies) {
|
|
||||||
this.id = Preconditions.checkNotNull(id, "id");
|
this.id = Preconditions.checkNotNull(id, "id");
|
||||||
this.authors = Preconditions.checkNotNull(authors, "authors");
|
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;
|
||||||
this.main = Preconditions.checkNotNull(main, "main");
|
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) {
|
public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) {
|
||||||
@ -34,54 +39,73 @@ public class SerializedPluginDescription {
|
|||||||
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
||||||
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
|
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.description(), plugin.url(),
|
||||||
|
Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAuthors() {
|
public @Nullable String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable List<String> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable List<Dependency> getDependencies() {
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMain() {
|
public String getMain() {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Dependency> getDependencies() {
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
||||||
return Objects.equals(id, that.id) &&
|
return Objects.equals(id, that.id) &&
|
||||||
Objects.equals(authors, that.authors) &&
|
Objects.equals(name, that.name) &&
|
||||||
Objects.equals(main, that.main) &&
|
|
||||||
Objects.equals(version, that.version) &&
|
Objects.equals(version, that.version) &&
|
||||||
Objects.equals(dependencies, that.dependencies);
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(url, that.url) &&
|
||||||
|
Objects.equals(authors, that.authors) &&
|
||||||
|
Objects.equals(dependencies, that.dependencies) &&
|
||||||
|
Objects.equals(main, that.main);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, authors, main, version, dependencies);
|
return Objects.hash(id, name, version, description, url, authors, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SerializedPluginDescription{" +
|
return "SerializedPluginDescription{" +
|
||||||
"id='" + id + '\'' +
|
"id='" + id + '\'' +
|
||||||
", authors='" + authors + '\'' +
|
", name='" + name + '\'' +
|
||||||
", main='" + main + '\'' +
|
|
||||||
", version='" + version + '\'' +
|
", version='" + version + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", url='" + url + '\'' +
|
||||||
|
", authors=" + authors +
|
||||||
", dependencies=" + dependencies +
|
", dependencies=" + dependencies +
|
||||||
|
", main='" + main + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,14 @@ public @interface Plugin {
|
|||||||
*/
|
*/
|
||||||
String id();
|
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.
|
* The version of the plugin.
|
||||||
*
|
*
|
||||||
@ -28,6 +36,20 @@ public @interface Plugin {
|
|||||||
*/
|
*/
|
||||||
String version() default "";
|
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.
|
||||||
|
*
|
||||||
|
* @return The plugin url, or an empty string if unknown
|
||||||
|
*/
|
||||||
|
String url() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The author of the plugin.
|
* The author of the plugin.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.velocitypowered.api.plugin;
|
package com.velocitypowered.api.plugin;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
||||||
|
|
||||||
@ -7,7 +8,6 @@ import java.nio.file.Path;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,21 +29,55 @@ public interface PluginDescription {
|
|||||||
*/
|
*/
|
||||||
String getId();
|
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.
|
* 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()
|
* @see Plugin#version()
|
||||||
*/
|
*/
|
||||||
String getVersion();
|
default Optional<String> getVersion() {
|
||||||
|
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<String> getDescription() {
|
||||||
|
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.
|
* Gets the authors of the {@link Plugin} within this container.
|
||||||
*
|
*
|
||||||
* @return the plugin authors
|
* @return the plugin authors, may be empty
|
||||||
* @see Plugin#authors()
|
* @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
|
* Gets a {@link Collection} of all dependencies of the {@link Plugin} within
|
||||||
|
@ -3,6 +3,7 @@ package com.velocitypowered.api.plugin.meta;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -36,11 +37,10 @@ public final class PluginDependency {
|
|||||||
/**
|
/**
|
||||||
* Returns the version this {@link PluginDependency} should match.
|
* 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 Optional<String> getVersion() {
|
||||||
public String getVersion() {
|
return Optional.ofNullable(version);
|
||||||
return version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,14 +77,7 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
Injector injector = Guice.createInjector(new VelocityPluginModule(server, javaDescription, baseDirectory));
|
Injector injector = Guice.createInjector(new VelocityPluginModule(server, javaDescription, baseDirectory));
|
||||||
Object instance = injector.getInstance(javaDescription.getMainClass());
|
Object instance = injector.getInstance(javaDescription.getMainClass());
|
||||||
|
|
||||||
return new VelocityPluginContainer(
|
return new VelocityPluginContainer(description, instance);
|
||||||
description.getId(),
|
|
||||||
description.getVersion(),
|
|
||||||
description.getAuthors(),
|
|
||||||
description.getDependencies(),
|
|
||||||
source.get(),
|
|
||||||
instance
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<SerializedPluginDescription> getSerializedPluginInfo(Path source) throws Exception {
|
private Optional<SerializedPluginDescription> getSerializedPluginInfo(Path source) throws Exception {
|
||||||
@ -105,13 +98,18 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
private VelocityPluginDescription createDescription(SerializedPluginDescription description, Path source, Class mainClass) {
|
private VelocityPluginDescription createDescription(SerializedPluginDescription description, Path source, Class mainClass) {
|
||||||
Set<PluginDependency> dependencies = new HashSet<>();
|
Set<PluginDependency> dependencies = new HashSet<>();
|
||||||
|
|
||||||
|
if (description.getDependencies() != null) {
|
||||||
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
|
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
|
||||||
dependencies.add(toDependencyMeta(dependency));
|
dependencies.add(toDependencyMeta(dependency));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new JavaVelocityPluginDescription(
|
return new JavaVelocityPluginDescription(
|
||||||
description.getId(),
|
description.getId(),
|
||||||
|
description.getName(),
|
||||||
description.getVersion(),
|
description.getVersion(),
|
||||||
|
description.getDescription(),
|
||||||
|
description.getUrl(),
|
||||||
description.getAuthors(),
|
description.getAuthors(),
|
||||||
dependencies,
|
dependencies,
|
||||||
source,
|
source,
|
||||||
|
@ -2,24 +2,21 @@ package com.velocitypowered.proxy.plugin.loader;
|
|||||||
|
|
||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
import com.velocitypowered.api.plugin.PluginDescription;
|
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;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class VelocityPluginContainer extends VelocityPluginDescription implements PluginContainer {
|
public class VelocityPluginContainer implements PluginContainer {
|
||||||
|
private final PluginDescription description;
|
||||||
private final Object instance;
|
private final Object instance;
|
||||||
|
|
||||||
public VelocityPluginContainer(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source, Object instance) {
|
public VelocityPluginContainer(PluginDescription description, Object instance) {
|
||||||
super(id, version, authors, dependencies, source);
|
this.description = description;
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluginDescription getDescription() {
|
public PluginDescription getDescription() {
|
||||||
return this;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.velocitypowered.proxy.plugin.loader;
|
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.google.common.collect.Maps;
|
||||||
import com.velocitypowered.api.plugin.PluginDescription;
|
import com.velocitypowered.api.plugin.PluginDescription;
|
||||||
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -14,15 +17,22 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
public class VelocityPluginDescription implements PluginDescription {
|
public class VelocityPluginDescription implements PluginDescription {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String version;
|
private final @Nullable String name;
|
||||||
|
private final @Nullable String version;
|
||||||
|
private final @Nullable String description;
|
||||||
|
private final @Nullable String url;
|
||||||
private final List<String> authors;
|
private final List<String> authors;
|
||||||
private final Map<String, PluginDependency> dependencies;
|
private final Map<String, PluginDependency> dependencies;
|
||||||
private final Path source;
|
private final Path source;
|
||||||
|
|
||||||
public VelocityPluginDescription(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source) {
|
public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url,
|
||||||
|
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source) {
|
||||||
this.id = checkNotNull(id, "id");
|
this.id = checkNotNull(id, "id");
|
||||||
this.version = checkNotNull(version, "version");
|
this.name = Strings.emptyToNull(name);
|
||||||
this.authors = checkNotNull(authors, "authors");
|
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);
|
this.dependencies = Maps.uniqueIndex(dependencies, PluginDependency::getId);
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
@ -33,8 +43,23 @@ public class VelocityPluginDescription implements PluginDescription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public Optional<String> getName() {
|
||||||
return version;
|
return Optional.ofNullable(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getVersion() {
|
||||||
|
return Optional.ofNullable(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getDescription() {
|
||||||
|
return Optional.ofNullable(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> getUrl() {
|
||||||
|
return Optional.ofNullable(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,8 +86,11 @@ public class VelocityPluginDescription implements PluginDescription {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "VelocityPluginDescription{" +
|
return "VelocityPluginDescription{" +
|
||||||
"id='" + id + '\'' +
|
"id='" + id + '\'' +
|
||||||
|
", name='" + name + '\'' +
|
||||||
", version='" + version + '\'' +
|
", version='" + version + '\'' +
|
||||||
", authors='" + authors + '\'' +
|
", description='" + description + '\'' +
|
||||||
|
", url='" + url + '\'' +
|
||||||
|
", authors=" + authors +
|
||||||
", dependencies=" + dependencies +
|
", dependencies=" + dependencies +
|
||||||
", source=" + source +
|
", source=" + source +
|
||||||
'}';
|
'}';
|
||||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.plugin.loader.java;
|
|||||||
|
|
||||||
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
import com.velocitypowered.api.plugin.meta.PluginDependency;
|
||||||
import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
|
import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -10,14 +11,15 @@ import java.util.List;
|
|||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public class JavaVelocityPluginDescription extends VelocityPluginDescription {
|
public class JavaVelocityPluginDescription extends VelocityPluginDescription {
|
||||||
private final Class mainClass;
|
private final Class<?> mainClass;
|
||||||
|
|
||||||
public JavaVelocityPluginDescription(String id, String version, List<String> authors, Collection<PluginDependency> dependencies, Path source, Class mainClass) {
|
public JavaVelocityPluginDescription(String id, @Nullable String name, @Nullable String version, @Nullable String description, @Nullable String url,
|
||||||
super(id, version, authors, dependencies, source);
|
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source, Class<?> mainClass) {
|
||||||
|
super(id, name, version, description, url, authors, dependencies, source);
|
||||||
this.mainClass = checkNotNull(mainClass);
|
this.mainClass = checkNotNull(mainClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getMainClass() {
|
public Class<?> getMainClass() {
|
||||||
return mainClass;
|
return mainClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package com.velocitypowered.proxy.plugin.loader.java;
|
package com.velocitypowered.proxy.plugin.loader.java;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
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 com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -11,22 +12,26 @@ import java.util.Objects;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SerializedPluginDescription {
|
public class SerializedPluginDescription {
|
||||||
|
// @Nullable is used here to make GSON skip these in the serialized file
|
||||||
private final String id;
|
private final String id;
|
||||||
private final List<String> authors;
|
private final @Nullable String name;
|
||||||
|
private final @Nullable String version;
|
||||||
|
private final @Nullable String description;
|
||||||
|
private final @Nullable String url;
|
||||||
|
private final @Nullable List<String> authors;
|
||||||
|
private final @Nullable List<Dependency> dependencies;
|
||||||
private final String main;
|
private final String main;
|
||||||
private final String version;
|
|
||||||
private final List<Dependency> dependencies;
|
|
||||||
|
|
||||||
public SerializedPluginDescription(String id, List<String> authors, String main, String version) {
|
public SerializedPluginDescription(String id, String name, String version, String description, String url,
|
||||||
this(id, authors, main, version, ImmutableList.of());
|
List<String> authors, List<Dependency> dependencies, String main) {
|
||||||
}
|
|
||||||
|
|
||||||
public SerializedPluginDescription(String id, List<String> authors, String main, String version, List<Dependency> dependencies) {
|
|
||||||
this.id = Preconditions.checkNotNull(id, "id");
|
this.id = Preconditions.checkNotNull(id, "id");
|
||||||
this.authors = Preconditions.checkNotNull(authors, "author");
|
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;
|
||||||
this.main = Preconditions.checkNotNull(main, "main");
|
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) {
|
public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) {
|
||||||
@ -34,54 +39,73 @@ public class SerializedPluginDescription {
|
|||||||
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) {
|
||||||
dependencies.add(new Dependency(dependency.id(), dependency.optional()));
|
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.description(), plugin.url(),
|
||||||
|
Arrays.stream(plugin.authors()).filter(author -> !author.isEmpty()).collect(Collectors.toList()), dependencies, qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAuthors() {
|
public @Nullable String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable List<String> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable List<Dependency> getDependencies() {
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMain() {
|
public String getMain() {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Dependency> getDependencies() {
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
SerializedPluginDescription that = (SerializedPluginDescription) o;
|
||||||
return Objects.equals(id, that.id) &&
|
return Objects.equals(id, that.id) &&
|
||||||
Objects.equals(authors, that.authors) &&
|
Objects.equals(name, that.name) &&
|
||||||
Objects.equals(main, that.main) &&
|
|
||||||
Objects.equals(version, that.version) &&
|
Objects.equals(version, that.version) &&
|
||||||
Objects.equals(dependencies, that.dependencies);
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(url, that.url) &&
|
||||||
|
Objects.equals(authors, that.authors) &&
|
||||||
|
Objects.equals(dependencies, that.dependencies) &&
|
||||||
|
Objects.equals(main, that.main);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, authors, main, version, dependencies);
|
return Objects.hash(id, name, version, description, url, authors, dependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SerializedPluginDescription{" +
|
return "SerializedPluginDescription{" +
|
||||||
"id='" + id + '\'' +
|
"id='" + id + '\'' +
|
||||||
", authors='" + authors + '\'' +
|
", name='" + name + '\'' +
|
||||||
", main='" + main + '\'' +
|
|
||||||
", version='" + version + '\'' +
|
", version='" + version + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", url='" + url + '\'' +
|
||||||
|
", authors=" + authors +
|
||||||
", dependencies=" + dependencies +
|
", dependencies=" + dependencies +
|
||||||
|
", main='" + main + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class FakePluginManager implements PluginManager {
|
public class FakePluginManager implements PluginManager {
|
||||||
@ -68,22 +66,7 @@ public class FakePluginManager implements PluginManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull PluginDescription getDescription() {
|
public @NonNull PluginDescription getDescription() {
|
||||||
return new PluginDescription() {
|
return () -> id;
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getAuthors() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren