Add support for resolving dependencies that require a version range

This commit is contained in:
Andrew Steinborn
2021-05-15 08:16:17 -04:00
parent 348ea4cc23
commit 2a39ddb03e
24 changed files with 258 additions and 58 deletions

View File

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.network;
import java.net.SocketAddress;
/**
* Represents a network listener for the proxy.
*/
public interface NetworkEndpoint {
/**
* The type.
*
* @return the type
*/
ListenerType type();
/**
* The address the listener is listening on.
*
* @return the address
*/
SocketAddress address();
}

View File

@@ -26,6 +26,15 @@ public @interface Dependency {
*/
String id();
/**
* The required version of the dependency. This should be in an NPM-compatible versioning format,
* which you can figure from <a href="https://semver.npmjs.com/">npm's SemVer checker</a>. If
* not specified, this assumes any version is acceptable.
*
* @return the version requirement
*/
String version() default "*";
/**
* Whether or not the dependency is not required to enable this plugin. By default this is
* {@code false}, meaning that the dependency is required to enable this plugin.

View File

@@ -52,8 +52,8 @@ public interface PluginDescription {
* @return a String with the plugin version, may be null
* @see Plugin#version()
*/
default @Nullable String version() {
return null;
default String version() {
return "";
}
/**

View File

@@ -20,7 +20,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class PluginDependency {
private final String id;
private final @Nullable String version;
private final String version;
private final boolean optional;
@@ -30,10 +30,10 @@ public final class PluginDependency {
* @param version an optional version
* @param optional whether or not this dependency is optional
*/
public PluginDependency(String id, @Nullable String version, boolean optional) {
public PluginDependency(String id, String version, boolean optional) {
this.id = checkNotNull(id, "id");
checkArgument(!id.isEmpty(), "id cannot be empty");
this.version = emptyToNull(version);
this.version = checkNotNull(version, "version");
this.optional = optional;
}
@@ -47,11 +47,11 @@ public final class PluginDependency {
}
/**
* Returns the version this {@link PluginDependency} should match.
* Returns the version this {@link PluginDependency} should match in NPM SemVer range format.
*
* @return a String with the plugin version, may be {@code null}
* @return a String with the plugin version, may be empty if no version requirement is present
*/
public @Nullable String version() {
public String version() {
return version;
}

View File

@@ -11,6 +11,7 @@ import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.ConsoleCommandSource;
import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.network.NetworkEndpoint;
import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.proxy.config.ProxyConfig;
import com.velocitypowered.api.proxy.connection.Player;
@@ -179,4 +180,12 @@ public interface ProxyServer extends Audience {
* @return the proxy version
*/
ProxyVersion version();
/**
* Returns all the endpoints the proxy is listening on. This collection is immutable.
*
* @return all the endpoints the proxy is listening on
*/
Collection<NetworkEndpoint> endpoints();
}

View File

@@ -7,6 +7,7 @@
package com.velocitypowered.api.proxy.config;
import com.google.common.annotations.Beta;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.Favicon;
import java.util.List;
@@ -14,8 +15,10 @@ import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Exposes certain proxy configuration information that plugins may use.
* Exposes certain proxy configuration information that plugins may use. Note that this interface
* is in constant flux and should never be considered stable.
*/
@Beta
public interface ProxyConfig {
/**

View File

@@ -33,15 +33,15 @@ public final class ProxyVersion {
this.version = Preconditions.checkNotNull(version, "version");
}
public String getName() {
public String name() {
return name;
}
public String getVendor() {
public String vendor() {
return vendor;
}
public String getVersion() {
public String version() {
return version;
}