Checker Framework integration (#126)

This commit is contained in:
Andrew Steinborn
2018-10-27 21:45:42 -04:00
committed by GitHub
parent dccf688da8
commit 32829c5637
106 changed files with 1170 additions and 708 deletions

View File

@@ -4,6 +4,8 @@ plugins {
id 'maven-publish'
}
apply from: '../gradle/checkerframework.gradle'
sourceSets {
ap {
compileClasspath += main.compileClasspath + main.output
@@ -17,7 +19,7 @@ dependencies {
compile 'com.moandjiezana.toml:toml4j:0.7.2'
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile 'com.google.inject:guice:4.2.0'
compile 'org.checkerframework:checker-qual:2.5.4'
compile "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.api.plugin.ap;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -29,8 +30,8 @@ public class SerializedPluginDescription {
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.authors = authors == null || authors.isEmpty() ? ImmutableList.of() : authors;
this.dependencies = dependencies == null || dependencies.isEmpty() ? ImmutableList.of() : dependencies;
this.main = Preconditions.checkNotNull(main, "main");
}
@@ -63,12 +64,12 @@ public class SerializedPluginDescription {
return url;
}
public @Nullable List<String> getAuthors() {
return authors;
public List<String> getAuthors() {
return authors == null ? ImmutableList.of() : authors;
}
public @Nullable List<Dependency> getDependencies() {
return dependencies;
public List<Dependency> getDependencies() {
return dependencies == null ? ImmutableList.of() : dependencies;
}
public String getMain() {

View File

@@ -15,7 +15,7 @@ public interface Command {
* @param source the source of this command
* @param args the arguments for this command
*/
void execute(@NonNull CommandSource source, @NonNull String[] args);
void execute(CommandSource source, String @NonNull [] args);
/**
* Provides tab complete suggestions for a command for a specified {@link CommandSource}.
@@ -23,7 +23,7 @@ public interface Command {
* @param currentArgs the current, partial arguments for this command
* @return tab complete suggestions
*/
default List<String> suggest(@NonNull CommandSource source, @NonNull String[] currentArgs) {
default List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
return ImmutableList.of();
}
@@ -38,7 +38,7 @@ public interface Command {
* @param args the arguments for this command
* @return whether the source has permission
*/
default boolean hasPermission(@NonNull CommandSource source, @NonNull String[] args) {
default boolean hasPermission(CommandSource source, String @NonNull [] args) {
return true;
}
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.command;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents an interface to register a command executor with the proxy.
*/
@@ -11,13 +9,13 @@ public interface CommandManager {
* @param command the command to register
* @param aliases the alias to use
*/
void register(@NonNull Command command, String... aliases);
void register(Command command, String... aliases);
/**
* Unregisters a command.
* @param alias the command alias to unregister
*/
void unregister(@NonNull String alias);
void unregister(String alias);
/**
* Attempts to execute a command from the specified {@code cmdLine}.
@@ -25,5 +23,5 @@ public interface CommandManager {
* @param cmdLine the command to run
* @return true if the command was found and executed, false if it was not
*/
boolean execute(@NonNull CommandSource source, @NonNull String cmdLine);
boolean execute(CommandSource source, String cmdLine);
}

View File

@@ -2,7 +2,6 @@ package com.velocitypowered.api.command;
import com.velocitypowered.api.permission.PermissionSubject;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents something that can be used to run a {@link Command}.
@@ -12,5 +11,5 @@ public interface CommandSource extends PermissionSubject {
* Sends the specified {@code component} to the invoker.
* @param component the text component to send
*/
void sendMessage(@NonNull Component component);
void sendMessage(Component component);
}

View File

@@ -1,12 +1,10 @@
package com.velocitypowered.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents an interface to perform direct dispatch of an event. This makes integration easier to achieve with platforms
* such as RxJava.
*/
@FunctionalInterface
public interface EventHandler<E> {
void execute(@NonNull E event);
void execute(E event);
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.CompletableFuture;
/**
@@ -13,7 +11,7 @@ public interface EventManager {
* @param plugin the plugin to associate with the listener
* @param listener the listener to register
*/
void register(@NonNull Object plugin, @NonNull Object listener);
void register(Object plugin, Object listener);
/**
* Requests that the specified {@code handler} listen for events and associate it with the {@code plugin}.
@@ -22,7 +20,7 @@ public interface EventManager {
* @param handler the handler to register
* @param <E> the event type to handle
*/
default <E> void register(@NonNull Object plugin, @NonNull Class<E> eventClass, @NonNull EventHandler<E> handler) {
default <E> void register(Object plugin, Class<E> eventClass, EventHandler<E> handler) {
register(plugin, eventClass, PostOrder.NORMAL, handler);
}
@@ -34,7 +32,7 @@ public interface EventManager {
* @param handler the handler to register
* @param <E> the event type to handle
*/
<E> void register(@NonNull Object plugin, @NonNull Class<E> eventClass, @NonNull PostOrder postOrder, @NonNull EventHandler<E> handler);
<E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder, EventHandler<E> handler);
/**
* Fires the specified event to the event bus asynchronously. This allows Velocity to continue servicing connections
@@ -42,13 +40,13 @@ public interface EventManager {
* @param event the event to fire
* @return a {@link CompletableFuture} representing the posted event
*/
@NonNull <E> CompletableFuture<E> fire(@NonNull E event);
<E> CompletableFuture<E> fire(E event);
/**
* Posts the specified event to the event bus and discards the result.
* @param event the event to fire
*/
default void fireAndForget(@NonNull Object event) {
default void fireAndForget(Object event) {
fire(event);
}
@@ -56,14 +54,14 @@ public interface EventManager {
* Unregisters all listeners for the specified {@code plugin}.
* @param plugin the plugin to deregister listeners for
*/
void unregisterListeners(@NonNull Object plugin);
void unregisterListeners(Object plugin);
/**
* Unregisters a specific listener for a specific plugin.
* @param plugin the plugin associated with the listener
* @param listener the listener to deregister
*/
void unregisterListener(@NonNull Object plugin, @NonNull Object listener);
void unregisterListener(Object plugin, Object listener);
/**
* Unregisters a specific event handler for a specific plugin.
@@ -71,5 +69,5 @@ public interface EventManager {
* @param handler the handler to register
* @param <E> the event type to handle
*/
<E> void unregister(@NonNull Object plugin, @NonNull EventHandler<E> handler);
<E> void unregister(Object plugin, EventHandler<E> handler);
}

View File

@@ -22,7 +22,7 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
* Sets the result of this event. The result must be non-null.
* @param result the new result
*/
void setResult(@NonNull R result);
void setResult(R result);
/**
* Represents a result for an event.
@@ -106,7 +106,7 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
return ALLOWED;
}
public static ComponentResult denied(@NonNull Component reason) {
public static ComponentResult denied(Component reason) {
Preconditions.checkNotNull(reason, "reason");
return new ComponentResult(false, reason);
}

View File

@@ -2,15 +2,14 @@ package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.InboundConnection;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* This event is fired when a handshake is established between a client and Velocity.
*/
public final class ConnectionHandshakeEvent {
private final @NonNull InboundConnection connection;
private final InboundConnection connection;
public ConnectionHandshakeEvent(@NonNull InboundConnection connection) {
public ConnectionHandshakeEvent(InboundConnection connection) {
this.connection = Preconditions.checkNotNull(connection, "connection");
}

View File

@@ -2,16 +2,15 @@ package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* This event is fired when a player disconnects from the proxy. Operations on the provided player, aside from basic
* data retrieval operations, may behave in undefined ways.
*/
public final class DisconnectEvent {
private @NonNull final Player player;
private final Player player;
public DisconnectEvent(@NonNull Player player) {
public DisconnectEvent(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
}

View File

@@ -3,7 +3,6 @@ package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* This event is fired once the player has been authenticated but before they connect to a server on the proxy.
@@ -12,7 +11,7 @@ public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentRe
private final Player player;
private ComponentResult result;
public LoginEvent(@NonNull Player player) {
public LoginEvent(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
this.result = ComponentResult.allowed();
}
@@ -27,7 +26,7 @@ public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentRe
}
@Override
public void setResult(@NonNull ComponentResult result) {
public void setResult(ComponentResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}

View File

@@ -36,7 +36,7 @@ public final class PluginMessageEvent implements ResultedEvent<PluginMessageEven
}
@Override
public void setResult(@NonNull ForwardResult result) {
public void setResult(ForwardResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}

View File

@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.InboundConnection;
import net.kyori.text.Component;
import net.kyori.text.serializer.ComponentSerializers;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -62,11 +61,11 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
private static final PreLoginComponentResult FORCE_OFFLINEMODE = new PreLoginComponentResult(Result.FORCE_OFFLINE, null);
private final Result result;
private final Optional<Component> reason;
private final @Nullable Component reason;
private PreLoginComponentResult(Result result, @Nullable Component reason) {
this.result = result;
this.reason = Optional.ofNullable(reason);
this.reason = reason;
}
@Override
@@ -75,7 +74,7 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
}
public Optional<Component> getReason() {
return reason;
return Optional.ofNullable(reason);
}
public boolean isOnlineModeAllowed() {
@@ -88,19 +87,16 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
@Override
public String toString() {
if (isForceOfflineMode()) {
return "allowed with force offline mode";
switch (result) {
case ALLOWED:
return "allowed";
case FORCE_OFFLINE:
return "allowed with force offline mode";
case FORCE_ONLINE:
return "allowed with online mode";
default:
return "denied";
}
if (isOnlineModeAllowed()) {
return "allowed with online mode";
}
if (isAllowed()) {
return "allowed";
}
if (reason.isPresent()) {
return "denied: " + ComponentSerializers.PLAIN.serialize(reason.get());
}
return "denied";
}
/**

View File

@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.PermissionProvider;
import com.velocitypowered.api.permission.PermissionSubject;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -22,7 +21,7 @@ public final class PermissionsSetupEvent {
this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider");
}
public @NonNull PermissionSubject getSubject() {
public PermissionSubject getSubject() {
return this.subject;
}
@@ -33,11 +32,11 @@ public final class PermissionsSetupEvent {
* @param subject the subject
* @return the obtained permission function
*/
public @NonNull PermissionFunction createFunction(PermissionSubject subject) {
public PermissionFunction createFunction(PermissionSubject subject) {
return this.provider.createFunction(subject);
}
public @NonNull PermissionProvider getProvider() {
public PermissionProvider getProvider() {
return this.provider;
}

View File

@@ -14,7 +14,7 @@ public final class GameProfileRequestEvent {
private final InboundConnection connection;
private final GameProfile originalProfile;
private final boolean onlineMode;
private GameProfile gameProfile;
private @Nullable GameProfile gameProfile;
public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, boolean onlineMode) {
this.connection = Preconditions.checkNotNull(connection, "connection");

View File

@@ -36,7 +36,7 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
}
@Override
public void setResult(@NonNull ChatResult result) {
public void setResult(ChatResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}

View File

@@ -17,7 +17,6 @@ public final class PlayerSettingsChangedEvent {
return player;
}
//New settings
public PlayerSettings getPlayerSettings() {
return playerSettings;
}

View File

@@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Optional;
@@ -33,7 +32,7 @@ public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConne
}
@Override
public void setResult(@NonNull ServerResult result) {
public void setResult(ServerResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@@ -54,19 +53,17 @@ public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConne
* Represents the result of the {@link ServerPreConnectEvent}.
*/
public static class ServerResult implements ResultedEvent.Result {
private static final ServerResult DENIED = new ServerResult(false, null);
private static final ServerResult DENIED = new ServerResult(null);
private final boolean allowed;
private final RegisteredServer server;
private final @Nullable RegisteredServer server;
private ServerResult(boolean allowed, @Nullable RegisteredServer server) {
this.allowed = allowed;
private ServerResult(@Nullable RegisteredServer server) {
this.server = server;
}
@Override
public boolean isAllowed() {
return allowed;
return server != null;
}
public Optional<RegisteredServer> getServer() {
@@ -75,10 +72,10 @@ public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConne
@Override
public String toString() {
if (!allowed) {
return "denied";
if (server != null) {
return "allowed: connect to " + server.getServerInfo().getName();
}
return "allowed: connect to " + server.getServerInfo().getName();
return "denied";
}
public static ServerResult denied() {
@@ -87,7 +84,7 @@ public final class ServerPreConnectEvent implements ResultedEvent<ServerPreConne
public static ServerResult allowed(RegisteredServer server) {
Preconditions.checkNotNull(server, "server");
return new ServerResult(true, server);
return new ServerResult(server);
}
}
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.permission;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Function that calculates the permission settings for a given
* {@link PermissionSubject}.
@@ -29,5 +27,5 @@ public interface PermissionFunction {
* @param permission the permission
* @return the value the permission is set to
*/
@NonNull Tristate getPermissionValue(@NonNull String permission);
Tristate getPermissionValue(String permission);
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.permission;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Provides {@link PermissionFunction}s for {@link PermissionSubject}s.
*/
@@ -13,5 +11,5 @@ public interface PermissionProvider {
* @param subject the subject
* @return the function
*/
@NonNull PermissionFunction createFunction(@NonNull PermissionSubject subject);
PermissionFunction createFunction(PermissionSubject subject);
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.permission;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents a object that has a set of queryable permissions.
*/
@@ -12,7 +10,7 @@ public interface PermissionSubject {
* @param permission the permission to check for
* @return whether or not the subject has the permission
*/
default boolean hasPermission(@NonNull String permission) {
default boolean hasPermission(String permission) {
return getPermissionValue(permission).asBoolean();
}
@@ -22,5 +20,5 @@ public interface PermissionSubject {
* @param permission the permission
* @return the value the permission is set to
*/
@NonNull Tristate getPermissionValue(@NonNull String permission);
Tristate getPermissionValue(String permission);
}

View File

@@ -37,7 +37,7 @@ public enum Tristate {
* @param val the boolean value
* @return {@link #TRUE} or {@link #FALSE}, if the value is <code>true</code> or <code>false</code>, respectively.
*/
public static @NonNull Tristate fromBoolean(boolean val) {
public static Tristate fromBoolean(boolean val) {
return val ? TRUE : FALSE;
}
@@ -51,7 +51,7 @@ public enum Tristate {
* @return {@link #UNDEFINED}, {@link #TRUE} or {@link #FALSE}, if the value
* is <code>null</code>, <code>true</code> or <code>false</code>, respectively.
*/
public static @NonNull Tristate fromNullableBoolean(@Nullable Boolean val) {
public static Tristate fromNullableBoolean(@Nullable Boolean val) {
return val == null ? UNDEFINED : val ? TRUE : FALSE;
}

View File

@@ -1,7 +1,5 @@
package com.velocitypowered.api.plugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Optional;
/**
@@ -13,7 +11,7 @@ public interface PluginContainer {
*
* @return the plugin's description
*/
@NonNull PluginDescription getDescription();
PluginDescription getDescription();
/**
* Returns the created plugin if it is available.

View File

@@ -1,16 +1,12 @@
package com.velocitypowered.api.plugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;
import java.util.logging.Logger;
/**
* The class that manages plugins. This manager can retrieve
* {@link PluginContainer}s from {@link Plugin} instances, getting
* {@link Logger}s, etc.
* Manages plugins loaded on the proxy. This manager can retrieve {@link PluginContainer}s from plugin instances
* and inject arbitrary JAR files into the plugin classpath with {@link #addToClasspath(Object, Path)}.
*/
public interface PluginManager {
/**
@@ -19,7 +15,7 @@ public interface PluginManager {
* @param instance the instance
* @return the container
*/
@NonNull Optional<PluginContainer> fromInstance(@NonNull Object instance);
Optional<PluginContainer> fromInstance(Object instance);
/**
* Retrieves a {@link PluginContainer} based on its ID.
@@ -27,22 +23,22 @@ public interface PluginManager {
* @param id the plugin ID
* @return the plugin, if available
*/
@NonNull Optional<PluginContainer> getPlugin(@NonNull String id);
Optional<PluginContainer> getPlugin(String id);
/**
* Gets a {@link Collection} of all {@link PluginContainer}s.
*
* @return the plugins
*/
@NonNull Collection<PluginContainer> getPlugins();
Collection<PluginContainer> getPlugins();
/**
* Checks if a plugin is loaded based on its ID.
*
* @param id the id of the {@link Plugin}
* @param id the id of the plugin
* @return {@code true} if loaded
*/
boolean isLoaded(@NonNull String id);
boolean isLoaded(String id);
/**
* Adds the specified {@code path} to the plugin classpath.
@@ -51,5 +47,5 @@ public interface PluginManager {
* @param path the path to the JAR you want to inject into the classpath
* @throws UnsupportedOperationException if the operation is not applicable to this plugin
*/
void addToClasspath(@NonNull Object plugin, @NonNull Path path);
void addToClasspath(Object plugin, Path path);
}

View File

@@ -1,6 +1,7 @@
package com.velocitypowered.api.plugin.meta;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
import java.util.Optional;
@@ -13,7 +14,8 @@ import static com.google.common.base.Strings.emptyToNull;
*/
public final class PluginDependency {
private final String id;
@Nullable private final String version;
@Nullable
private final String version;
private final boolean optional;
@@ -53,7 +55,7 @@ public final class PluginDependency {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PluginDependency that = (PluginDependency) o;

View File

@@ -13,7 +13,6 @@ import com.velocitypowered.api.util.title.Title;
import java.util.List;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Optional;
import java.util.UUID;
@@ -62,7 +61,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* Sends a chat message to the player's client.
* @param component the chat message to send
*/
default void sendMessage(@NonNull Component component) {
default void sendMessage(Component component) {
sendMessage(component, MessagePosition.CHAT);
}
@@ -71,14 +70,14 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* @param component the chat message to send
* @param position the position for the message
*/
void sendMessage(@NonNull Component component, @NonNull MessagePosition position);
void sendMessage(Component component, MessagePosition position);
/**
* Creates a new connection request so that the player can connect to another server.
* @param server the server to connect to
* @return a new connection request
*/
ConnectionRequestBuilder createConnectionRequest(@NonNull RegisteredServer server);
ConnectionRequestBuilder createConnectionRequest(RegisteredServer server);
/**
* Gets the player's profile properties.

View File

@@ -9,6 +9,7 @@ import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.scheduler.Scheduler;
import com.velocitypowered.api.util.ProxyVersion;
import net.kyori.text.Component;
import java.net.InetSocketAddress;
@@ -131,4 +132,10 @@ public interface ProxyServer {
* @return the proxy config
* */
ProxyConfig getConfiguration();
/**
* Returns the version of the proxy.
* @return the proxy version
*/
ProxyVersion getVersion();
}

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.api.proxy.messages;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
@@ -27,7 +28,7 @@ public final class LegacyChannelIdentifier implements ChannelIdentifier {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LegacyChannelIdentifier that = (LegacyChannelIdentifier) o;

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.api.proxy.messages;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
import java.util.regex.Pattern;
@@ -54,11 +55,11 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
@Override
public String toString() {
return getId() + " (modern)";
return namespace + ":" + name + " (modern)";
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MinecraftChannelIdentifier that = (MinecraftChannelIdentifier) o;

View File

@@ -3,6 +3,7 @@ package com.velocitypowered.api.proxy.player;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.util.GameProfile;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Optional;
@@ -47,5 +48,5 @@ public interface TabList {
// Necessary because the TabListEntry implementation isn't in the api
@Deprecated
TabListEntry buildEntry(GameProfile profile, Component displayName, int latency, int gameMode);
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode);
}

View File

@@ -1,9 +1,7 @@
package com.velocitypowered.api.proxy.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.util.GameProfile;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Optional;
@@ -16,7 +14,7 @@ public interface TabListEntry {
* Returns the parent {@link TabList} of this {@code this} {@link TabListEntry}.
* @return parent {@link TabList}
*/
@NonNull TabList getTabList();
TabList getTabList();
/**
* Returns the {@link GameProfile} of the entry, which uniquely identifies the entry
@@ -24,14 +22,14 @@ public interface TabListEntry {
* as the player head in the tab list.
* @return {@link GameProfile} of the entry
*/
@NonNull GameProfile getProfile();
GameProfile getProfile();
/**
* Returns {@link Optional} text {@link Component}, which if present is the text displayed for
* {@code this} entry in the {@link TabList}, otherwise {@link GameProfile#getName()} is shown.
* @return {@link Optional} text {@link Component} of name displayed in the tab list
*/
@NonNull Optional<Component> getDisplayName();
Optional<Component> getDisplayName();
/**
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}.
@@ -39,7 +37,7 @@ public interface TabListEntry {
* @param displayName to show in the {@link TabList} for {@code this} entry
* @return {@code this}, for chaining
*/
@NonNull TabListEntry setDisplayName(@Nullable Component displayName);
TabListEntry setDisplayName(@Nullable Component displayName);
/**
* Returns the latency for {@code this} entry.
@@ -63,7 +61,7 @@ public interface TabListEntry {
* @param latency to changed to
* @return {@code this}, for chaining
*/
@NonNull TabListEntry setLatency(int latency);
TabListEntry setLatency(int latency);
/**
* Gets the game mode {@code this} entry has been set to.
@@ -99,9 +97,9 @@ public interface TabListEntry {
* @see TabListEntry
*/
class Builder {
private TabList tabList;
private GameProfile profile;
private Component displayName;
private @Nullable TabList tabList;
private @Nullable GameProfile profile;
private @Nullable Component displayName;
private int latency = 0;
private int gameMode = 0;
@@ -167,9 +165,12 @@ public interface TabListEntry {
* @return the constructed {@link TabListEntry}
*/
public TabListEntry build() {
Preconditions.checkState(tabList != null, "The Tablist must be set when building a TabListEntry");
Preconditions.checkState(profile != null, "The GameProfile must be set when building a TabListEntry");
if (tabList == null) {
throw new IllegalStateException("The Tablist must be set when building a TabListEntry");
}
if (profile == null) {
throw new IllegalStateException("The GameProfile must be set when building a TabListEntry");
}
return tabList.buildEntry(profile, displayName, latency, gameMode);
}
}

View File

@@ -1,7 +1,7 @@
package com.velocitypowered.api.proxy.server;
import com.google.common.base.Preconditions;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.net.InetSocketAddress;
import java.util.Objects;
@@ -10,24 +10,24 @@ import java.util.Objects;
* ServerInfo represents a server that a player can connect to. This object is immutable and safe for concurrent access.
*/
public final class ServerInfo {
private final @NonNull String name;
private final @NonNull InetSocketAddress address;
private final String name;
private final InetSocketAddress address;
/**
* Creates a new ServerInfo object.
* @param name the name for the server
* @param address the address of the server to connect to
*/
public ServerInfo(@NonNull String name, @NonNull InetSocketAddress address) {
public ServerInfo(String name, InetSocketAddress address) {
this.name = Preconditions.checkNotNull(name, "name");
this.address = Preconditions.checkNotNull(address, "address");
}
public final @NonNull String getName() {
public final String getName() {
return name;
}
public final @NonNull InetSocketAddress getAddress() {
public final InetSocketAddress getAddress() {
return address;
}
@@ -40,7 +40,7 @@ public final class ServerInfo {
}
@Override
public final boolean equals(Object o) {
public final boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServerInfo that = (ServerInfo) o;

View File

@@ -14,7 +14,7 @@ import java.util.*;
*/
public final class ServerPing {
private final Version version;
private final Players players;
private final @Nullable Players players;
private final Component description;
private final @Nullable Favicon favicon;
private final @Nullable ModInfo modinfo;
@@ -89,14 +89,14 @@ public final class ServerPing {
* A builder for {@link ServerPing} objects.
*/
public static final class Builder {
private Version version;
private Version version = new Version(0, "Unknown");
private int onlinePlayers;
private int maximumPlayers;
private final List<SamplePlayer> samplePlayers = new ArrayList<>();
private String modType;
private String modType = "FML";
private final List<ModInfo.Mod> mods = new ArrayList<>();
private Component description;
private Favicon favicon;
private @Nullable Component description;
private @Nullable Favicon favicon;
private boolean nullOutPlayers;
private boolean nullOutModinfo;
@@ -165,6 +165,12 @@ public final class ServerPing {
}
public ServerPing build() {
if (this.version == null) {
throw new IllegalStateException("version not specified");
}
if (this.description == null) {
throw new IllegalStateException("no server description supplied");
}
return new ServerPing(version, nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers),
description, favicon, nullOutModinfo ? null : new ModInfo(modType, mods));
}
@@ -185,12 +191,12 @@ public final class ServerPing {
return samplePlayers;
}
public Component getDescription() {
return description;
public Optional<Component> getDescription() {
return Optional.ofNullable(description);
}
public Favicon getFavicon() {
return favicon;
public Optional<Favicon> getFavicon() {
return Optional.ofNullable(favicon);
}
public String getModType() {

View File

@@ -1,5 +1,8 @@
package com.velocitypowered.api.scheduler;
import org.checkerframework.common.value.qual.IntRange;
import org.checkerframework.common.value.qual.IntRangeFromNonNegative;
import java.util.concurrent.TimeUnit;
/**
@@ -24,7 +27,7 @@ public interface Scheduler {
* @param unit the unit of time for {@code time}
* @return this builder, for chaining
*/
TaskBuilder delay(long time, TimeUnit unit);
TaskBuilder delay(@IntRange(from = 0) long time, TimeUnit unit);
/**
* Specifies that the task should continue running after waiting for the specified amount, until it is cancelled.
@@ -32,7 +35,7 @@ public interface Scheduler {
* @param unit the unit of time for {@code time}
* @return this builder, for chaining
*/
TaskBuilder repeat(long time, TimeUnit unit);
TaskBuilder repeat(@IntRange(from = 0) long time, TimeUnit unit);
/**
* Clears the delay on this task.

View File

@@ -1,7 +1,7 @@
package com.velocitypowered.api.util;
import com.google.common.base.Preconditions;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
@@ -25,7 +25,7 @@ public final class Favicon {
* of functions.
* @param base64Url the url for use with this favicon
*/
public Favicon(@NonNull String base64Url) {
public Favicon(String base64Url) {
this.base64Url = Preconditions.checkNotNull(base64Url, "base64Url");
}
@@ -38,7 +38,7 @@ public final class Favicon {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Favicon favicon = (Favicon) o;
@@ -62,7 +62,7 @@ public final class Favicon {
* @param image the image to use for the favicon
* @return the created {@link Favicon} instance
*/
public static Favicon create(@NonNull BufferedImage image) {
public static Favicon create(BufferedImage image) {
Preconditions.checkNotNull(image, "image");
Preconditions.checkArgument(image.getWidth() == 64 && image.getHeight() == 64, "Image does not have" +
" 64x64 dimensions (found %sx%s)", image.getWidth(), image.getHeight());
@@ -81,7 +81,7 @@ public final class Favicon {
* @return the created {@link Favicon} instance
* @throws IOException if the file could not be read from the path
*/
public static Favicon create(@NonNull Path path) throws IOException {
public static Favicon create(Path path) throws IOException {
try (InputStream stream = Files.newInputStream(path)) {
return create(ImageIO.read(stream));
}

View File

@@ -2,7 +2,6 @@ package com.velocitypowered.api.util;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
import java.util.UUID;
@@ -15,7 +14,7 @@ public final class GameProfile {
private final String name;
private final List<Property> properties;
public GameProfile(@NonNull String id, @NonNull String name, @NonNull List<Property> properties) {
public GameProfile(String id, String name, List<Property> properties) {
this.id = Preconditions.checkNotNull(id, "id");
this.name = Preconditions.checkNotNull(name, "name");
this.properties = ImmutableList.copyOf(properties);
@@ -42,7 +41,7 @@ public final class GameProfile {
* @param username the username to use
* @return the new offline-mode game profile
*/
public static GameProfile forOfflinePlayer(@NonNull String username) {
public static GameProfile forOfflinePlayer(String username) {
Preconditions.checkNotNull(username, "username");
String id = UuidUtils.toUndashed(UuidUtils.generateOfflinePlayerUuid(username));
return new GameProfile(id, username, ImmutableList.of());
@@ -62,7 +61,7 @@ public final class GameProfile {
private final String value;
private final String signature;
public Property(@NonNull String name, @NonNull String value, @NonNull String signature) {
public Property(String name, String value, String signature) {
this.name = Preconditions.checkNotNull(name, "name");
this.value = Preconditions.checkNotNull(value, "value");
this.signature = Preconditions.checkNotNull(signature, "signature");

View File

@@ -0,0 +1,57 @@
package com.velocitypowered.api.util;
import com.google.common.base.Preconditions;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Objects;
/**
* Provides a version object for the proxy.
*/
public final class ProxyVersion {
private final String name;
private final String vendor;
private final String version;
public ProxyVersion(String name, String vendor, String version) {
this.name = Preconditions.checkNotNull(name, "name");
this.vendor = Preconditions.checkNotNull(vendor, "vendor");
this.version = Preconditions.checkNotNull(version, "version");
}
public String getName() {
return name;
}
public String getVendor() {
return vendor;
}
public String getVersion() {
return version;
}
@Override
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProxyVersion that = (ProxyVersion) o;
return Objects.equals(name, that.name) &&
Objects.equals(vendor, that.vendor) &&
Objects.equals(version, that.version);
}
@Override
public int hashCode() {
return Objects.hash(name, vendor, version);
}
@Override
public String toString() {
return "ProxyVersion{" +
"name='" + name + '\'' +
", vendor='" + vendor + '\'' +
", version='" + version + '\'' +
'}';
}
}

View File

@@ -2,7 +2,6 @@ package com.velocitypowered.api.util;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
@@ -21,7 +20,7 @@ public final class UuidUtils {
* @param string the string to convert
* @return the UUID object
*/
public static @NonNull UUID fromUndashed(final @NonNull String string) {
public static UUID fromUndashed(final String string) {
Objects.requireNonNull(string, "string");
Preconditions.checkArgument(string.length() == 32, "Length is incorrect");
return new UUID(
@@ -35,7 +34,7 @@ public final class UuidUtils {
* @param uuid the UUID to convert
* @return the undashed UUID
*/
public static @NonNull String toUndashed(final @NonNull UUID uuid) {
public static String toUndashed(final UUID uuid) {
Preconditions.checkNotNull(uuid, "uuid");
return Strings.padStart(Long.toHexString(uuid.getMostSignificantBits()), 16, '0') +
Strings.padStart(Long.toHexString(uuid.getLeastSignificantBits()), 16, '0');
@@ -46,7 +45,7 @@ public final class UuidUtils {
* @param username the username to use
* @return the offline mode UUID
*/
public static @NonNull UUID generateOfflinePlayerUuid(@NonNull String username) {
public static UUID generateOfflinePlayerUuid(String username) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8));
}
}

View File

@@ -11,8 +11,8 @@ import java.util.Optional;
* Represents a "full" title, including all components. This class is immutable.
*/
public final class TextTitle implements Title {
private final Component title;
private final Component subtitle;
private final @Nullable Component title;
private final @Nullable Component subtitle;
private final int stay;
private final int fadeIn;
private final int fadeOut;
@@ -94,7 +94,7 @@ public final class TextTitle implements Title {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TextTitle textTitle = (TextTitle) o;
@@ -193,12 +193,12 @@ public final class TextTitle implements Title {
return this;
}
public Component getTitle() {
return title;
public Optional<Component> getTitle() {
return Optional.ofNullable(title);
}
public Component getSubtitle() {
return subtitle;
public Optional<Component> getSubtitle() {
return Optional.ofNullable(subtitle);
}
public int getStay() {