Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
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
Dieser Commit ist enthalten in:
Ursprung
fcf5ad157f
Commit
830b1d4798
3
.gitignore
vendored
3
.gitignore
vendored
@ -130,4 +130,5 @@ gradle-app.setting
|
|||||||
logs/
|
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,23 @@ 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 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 url, List<String> authors, List<Dependency> dependencies, String main) {
|
||||||
this(id, author, main, version, ImmutableList.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
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.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 +36,66 @@ 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.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 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(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, 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 + '\'' +
|
||||||
|
", 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,13 @@ public @interface Plugin {
|
|||||||
*/
|
*/
|
||||||
String version() default "";
|
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.
|
* 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,45 @@ 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 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,17 @@ 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<>();
|
||||||
|
|
||||||
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
|
if (description.getDependencies() != null) {
|
||||||
dependencies.add(toDependencyMeta(dependency));
|
for (SerializedPluginDescription.Dependency dependency : description.getDependencies()) {
|
||||||
|
dependencies.add(toDependencyMeta(dependency));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JavaVelocityPluginDescription(
|
return new JavaVelocityPluginDescription(
|
||||||
description.getId(),
|
description.getId(),
|
||||||
|
description.getName(),
|
||||||
description.getVersion(),
|
description.getVersion(),
|
||||||
|
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,20 @@ 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 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 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.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 +41,18 @@ 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> getUrl() {
|
||||||
|
return Optional.ofNullable(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,14 +10,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, String name, String version, String url, List<String> authors,
|
||||||
super(id, version, authors, dependencies, source);
|
Collection<PluginDependency> dependencies, Path source, Class<?> mainClass) {
|
||||||
|
super(id, name, version, 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,23 @@ 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 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 url, List<String> authors, List<Dependency> dependencies, String main) {
|
||||||
this(id, authors, main, version, ImmutableList.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
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.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 +36,66 @@ 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.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 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(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, 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 + '\'' +
|
||||||
|
", 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