13
0
geforkt von Mirrors/Velocity

Add Javadoc and remove all Checkstyle issues from API and natives.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-11-15 19:04:39 -05:00
Ursprung a4cdc4884a
Commit 868976e09c
15 geänderte Dateien mit 149 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -11,7 +11,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Fired when a player is kicked from a server. You may either allow Velocity to kick the player * Fired when a player is kicked from a server. You may either allow Velocity to kick the player
* (with an optional reason override) or redirect the player to a separate server. * (with an optional reason override) or redirect the player to a separate server. By default,
* Velocity will notify the user (if they are already connected to a server) or disconnect them
* (if they are not on a server and no other servers are available).
*/ */
public final class KickedFromServerEvent implements public final class KickedFromServerEvent implements
ResultedEvent<KickedFromServerEvent.ServerKickResult> { ResultedEvent<KickedFromServerEvent.ServerKickResult> {
@ -22,6 +24,14 @@ public final class KickedFromServerEvent implements
private final boolean duringServerConnect; private final boolean duringServerConnect;
private ServerKickResult result; private ServerKickResult result;
/**
* Creates a {@code KickedFromServerEvent} instance.
* @param player the player affected
* @param server the server the player disconnected from
* @param originalReason the reason for being kicked, optional
* @param duringServerConnect whether or not the player was kicked during the connection process
* @param fancyReason a fancy reason for being disconnected, used for the initial result
*/
public KickedFromServerEvent(Player player, RegisteredServer server, public KickedFromServerEvent(Player player, RegisteredServer server,
@Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) { @Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) {
this.player = Preconditions.checkNotNull(player, "player"); this.player = Preconditions.checkNotNull(player, "player");

Datei anzeigen

@ -16,6 +16,11 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
private final String message; private final String message;
private ChatResult result; private ChatResult result;
/**
* Constructs a PlayerChatEvent.
* @param player the player sending the message
* @param message the message being sent
*/
public PlayerChatEvent(Player player, String message) { public PlayerChatEvent(Player player, String message) {
this.player = Preconditions.checkNotNull(player, "player"); this.player = Preconditions.checkNotNull(player, "player");
this.message = Preconditions.checkNotNull(message, "message"); this.message = Preconditions.checkNotNull(message, "message");
@ -57,11 +62,10 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
private static final ChatResult ALLOWED = new ChatResult(true, null); private static final ChatResult ALLOWED = new ChatResult(true, null);
private static final ChatResult DENIED = new ChatResult(false, null); private static final ChatResult DENIED = new ChatResult(false, null);
// The server can not accept formatted text from clients!
private @Nullable String message; private @Nullable String message;
private final boolean status; private final boolean status;
protected ChatResult(boolean status, @Nullable String message) { private ChatResult(boolean status, @Nullable String message) {
this.status = status; this.status = status;
this.message = message; this.message = message;
} }
@ -76,10 +80,18 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
return status ? "allowed" : "denied"; return status ? "allowed" : "denied";
} }
/**
* Allows the message to be sent, without modification.
* @return the allowed result
*/
public static ChatResult allowed() { public static ChatResult allowed() {
return ALLOWED; return ALLOWED;
} }
/**
* Prevents the message from being sent.
* @return the denied result
*/
public static ChatResult denied() { public static ChatResult denied() {
return DENIED; return DENIED;
} }
@ -88,6 +100,11 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
return Optional.ofNullable(message); return Optional.ofNullable(message);
} }
/**
* Allows the message to be sent, but silently replaced with another.
* @param message the message to use instead
* @return a result with a new message
*/
public static ChatResult message(@NonNull String message) { public static ChatResult message(@NonNull String message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
return new ChatResult(true, message); return new ChatResult(true, message);

Datei anzeigen

@ -6,7 +6,7 @@ import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
/** /**
* This event is fired when the players ModInfo is changed. * This event is fired when a Forge client sends its mods to the proxy while connecting to a server.
*/ */
public final class PlayerModInfoEvent { public final class PlayerModInfoEvent {

Datei anzeigen

@ -2,6 +2,8 @@ package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.ConnectionRequestBuilder.Status;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional; import java.util.Optional;
@ -17,6 +19,11 @@ public final class ServerPreConnectEvent implements
private final RegisteredServer originalServer; private final RegisteredServer originalServer;
private ServerResult result; private ServerResult result;
/**
* Creates the ServerPreConnectEvent.
* @param player the player who is connecting to a server
* @param originalServer the server the player was trying to connect to
*/
public ServerPreConnectEvent(Player player, RegisteredServer originalServer) { public ServerPreConnectEvent(Player player, RegisteredServer originalServer) {
this.player = Preconditions.checkNotNull(player, "player"); this.player = Preconditions.checkNotNull(player, "player");
this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer");
@ -80,10 +87,21 @@ public final class ServerPreConnectEvent implements
return "denied"; return "denied";
} }
/**
* Returns a result that will prevent players from connecting to another server. If this result
* is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status
* {@link Status#CONNECTION_CANCELLED}.
* @return a result to deny conneections
*/
public static ServerResult denied() { public static ServerResult denied() {
return DENIED; return DENIED;
} }
/**
* Allows the player to connect to the specified server.
* @param server the new server to connect to
* @return a result to allow the player to connect to the specified server
*/
public static ServerResult allowed(RegisteredServer server) { public static ServerResult allowed(RegisteredServer server) {
Preconditions.checkNotNull(server, "server"); Preconditions.checkNotNull(server, "server");
return new ServerResult(server); return new ServerResult(server);

Datei anzeigen

@ -50,7 +50,16 @@ public interface TabList {
*/ */
Collection<TabListEntry> getEntries(); Collection<TabListEntry> getEntries();
// Necessary because the TabListEntry implementation isn't in the api /**
* Builds a tab list entry.
*
* @deprecated Internal usage. Use {@link TabListEntry.Builder} instead.
* @param profile profile
* @param displayName display name
* @param latency latency
* @param gameMode game mode
* @return entry
*/
@Deprecated @Deprecated
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
int gameMode); int gameMode);

Datei anzeigen

@ -86,7 +86,7 @@ public interface TabListEntry {
int getGameMode(); int getGameMode();
/** /**
* Sets the game mode for {@code this} entry to the specified value * Sets the game mode for {@code this} entry to the specified value.
* *
* @param gameMode to change to * @param gameMode to change to
* @return {@code this}, for chaining * @return {@code this}, for chaining

Datei anzeigen

@ -195,33 +195,63 @@ public final class QueryResponse {
private Builder() { private Builder() {
} }
/**
* Sets the hostname for the response.
* @param hostname the hostname to set
* @return this builder, for chaining
*/
public Builder hostname(String hostname) { public Builder hostname(String hostname) {
this.hostname = Preconditions.checkNotNull(hostname, "hostname"); this.hostname = Preconditions.checkNotNull(hostname, "hostname");
return this; return this;
} }
/**
* Sets the game version for the response.
* @param gameVersion the game version to set
* @return this builder, for chaining
*/
public Builder gameVersion(String gameVersion) { public Builder gameVersion(String gameVersion) {
this.gameVersion = Preconditions.checkNotNull(gameVersion, "gameVersion"); this.gameVersion = Preconditions.checkNotNull(gameVersion, "gameVersion");
return this; return this;
} }
/**
* Sets the map that will appear in the response.
* @param map the map to set
* @return this builder, for chaining
*/
public Builder map(String map) { public Builder map(String map) {
this.map = Preconditions.checkNotNull(map, "map"); this.map = Preconditions.checkNotNull(map, "map");
return this; return this;
} }
/**
* Sets the players that are currently claimed to be online.
* @param currentPlayers a non-negative number representing all players online
* @return this builder, for chaining
*/
public Builder currentPlayers(int currentPlayers) { public Builder currentPlayers(int currentPlayers) {
Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative"); Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative");
this.currentPlayers = currentPlayers; this.currentPlayers = currentPlayers;
return this; return this;
} }
/**
* Sets the maximum number of players this server purportedly can hold.
* @param maxPlayers a non-negative number representing the maximum number of builders
* @return this builder, for chaining
*/
public Builder maxPlayers(int maxPlayers) { public Builder maxPlayers(int maxPlayers) {
Preconditions.checkArgument(maxPlayers >= 0, "maxPlayers cannot be negative"); Preconditions.checkArgument(maxPlayers >= 0, "maxPlayers cannot be negative");
this.maxPlayers = maxPlayers; this.maxPlayers = maxPlayers;
return this; return this;
} }
/**
* Sets the host where this proxy is running.
* @param proxyHost the host where the proxy is running
* @return this instance, for chaining
*/
public Builder proxyHost(String proxyHost) { public Builder proxyHost(String proxyHost) {
this.proxyHost = Preconditions.checkNotNull(proxyHost, "proxyHost"); this.proxyHost = Preconditions.checkNotNull(proxyHost, "proxyHost");
return this; return this;
@ -239,33 +269,62 @@ public final class QueryResponse {
return this; return this;
} }
/**
* Adds the specified players to the player list.
* @param players the players to add
* @return this builder, for chaining
*/
public Builder players(Collection<String> players) { public Builder players(Collection<String> players) {
this.players.addAll(Preconditions.checkNotNull(players, "players")); this.players.addAll(Preconditions.checkNotNull(players, "players"));
return this; return this;
} }
/**
* Adds the specified players to the player list.
* @param players the players to add
* @return this builder, for chaining
*/
public Builder players(String... players) { public Builder players(String... players) {
this.players.addAll(Arrays.asList(Preconditions.checkNotNull(players, "players"))); this.players.addAll(Arrays.asList(Preconditions.checkNotNull(players, "players")));
return this; return this;
} }
/**
* Removes all players from the builder. This does not affect {@link #getCurrentPlayers()}.
* @return this builder, for chaining
*/
public Builder clearPlayers() { public Builder clearPlayers() {
this.players.clear(); this.players.clear();
return this; return this;
} }
/**
* Sets the proxy version.
* @param proxyVersion the proxy version to set
* @return this builder, for chaining
*/
public Builder proxyVersion(String proxyVersion) { public Builder proxyVersion(String proxyVersion) {
this.proxyVersion = Preconditions.checkNotNull(proxyVersion, "proxyVersion"); this.proxyVersion = Preconditions.checkNotNull(proxyVersion, "proxyVersion");
return this; return this;
} }
/**
* Adds the specified plugins to the plugins list.
* @param plugins the plugins to add
* @return this builder, for chaining
*/
public Builder plugins(Collection<PluginInformation> plugins) { public Builder plugins(Collection<PluginInformation> plugins) {
this.plugins.addAll(Preconditions.checkNotNull(plugins, "plugins")); this.plugins.addAll(Preconditions.checkNotNull(plugins, "plugins"));
return this; return this;
} }
/**
* Adds the specified plugins to the plugins list.
* @param plugins the plugins to add
* @return this builder, for chaining
*/
public Builder plugins(PluginInformation... plugins) { public Builder plugins(PluginInformation... plugins) {
this.plugins.addAll(Arrays.asList(Preconditions.checkNotNull(plugins, "plugins"))); this.plugins.addAll(Arrays.asList(plugins));
return this; return this;
} }

Datei anzeigen

@ -29,6 +29,14 @@ public final class ServerPing {
this(version, players, description, favicon, ModInfo.DEFAULT); this(version, players, description, favicon, ModInfo.DEFAULT);
} }
/**
* Constructs a ServerPing instance.
* @param version the version of the server
* @param players the players on the server
* @param description the MOTD for the server
* @param favicon the server's favicon
* @param modinfo the mods this server runs
*/
public ServerPing(Version version, @Nullable Players players, Component description, public ServerPing(Version version, @Nullable Players players, Component description,
@Nullable Favicon favicon, @Nullable ModInfo modinfo) { @Nullable Favicon favicon, @Nullable ModInfo modinfo) {
this.version = Preconditions.checkNotNull(version, "version"); this.version = Preconditions.checkNotNull(version, "version");

Datei anzeigen

@ -11,7 +11,8 @@ import java.util.UUID;
public final class GameProfile { public final class GameProfile {
private final UUID id; private final UUID id;
private final String undashedId, name; private final String undashedId;
private final String name;
private final List<Property> properties; private final List<Property> properties;
public GameProfile(UUID id, String name, List<Property> properties) { public GameProfile(UUID id, String name, List<Property> properties) {
@ -136,12 +137,21 @@ public final class GameProfile {
+ '}'; + '}';
} }
/**
* Represents a Mojang profile property. Just like {@link GameProfile}, this class is immutable.
*/
public static final class Property { public static final class Property {
private final String name; private final String name;
private final String value; private final String value;
private final String signature; private final String signature;
/**
* Creates a profile property entry.
* @param name the name of the property
* @param value the value of the property
* @param signature the Mojang signature for the property
*/
public Property(String name, String value, String signature) { public Property(String name, String value, String signature) {
this.name = Preconditions.checkNotNull(name, "name"); this.name = Preconditions.checkNotNull(name, "name");
this.value = Preconditions.checkNotNull(value, "value"); this.value = Preconditions.checkNotNull(value, "value");

Datei anzeigen

@ -76,10 +76,10 @@ public final class NativeCodeLoader<T> implements Supplier<T> {
} }
static final BooleanSupplier MACOS = () -> static final BooleanSupplier MACOS = () ->
System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X") && System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X")
System.getProperty("os.arch").equals("x86_64"); && System.getProperty("os.arch").equals("x86_64");
static final BooleanSupplier LINUX = () -> static final BooleanSupplier LINUX = () ->
System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux") && System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux")
System.getProperty("os.arch").equals("amd64"); && System.getProperty("os.arch").equals("amd64");
static final BooleanSupplier ALWAYS = () -> true; static final BooleanSupplier ALWAYS = () -> true;
} }

Datei anzeigen

@ -43,7 +43,7 @@ public class Natives {
}; };
} }
public static final NativeCodeLoader<VelocityCompressorFactory> compressor = new NativeCodeLoader<>( public static final NativeCodeLoader<VelocityCompressorFactory> compress = new NativeCodeLoader<>(
ImmutableList.of( ImmutableList.of(
new NativeCodeLoader.Variant<>(NativeCodeLoader.MACOS, new NativeCodeLoader.Variant<>(NativeCodeLoader.MACOS,
copyAndLoadNative("/macosx/velocity-compress.dylib"), "native (macOS)", copyAndLoadNative("/macosx/velocity-compress.dylib"), "native (macOS)",

Datei anzeigen

@ -20,13 +20,13 @@ class VelocityCompressorTest {
@BeforeAll @BeforeAll
static void checkNatives() { static void checkNatives() {
Natives.compressor.getLoadedVariant(); Natives.compress.getLoadedVariant();
} }
@Test @Test
@EnabledOnOs({MAC, LINUX}) @EnabledOnOs({MAC, LINUX})
void nativeIntegrityCheck() throws DataFormatException { void nativeIntegrityCheck() throws DataFormatException {
VelocityCompressor compressor = Natives.compressor.get().create(Deflater.DEFAULT_COMPRESSION); VelocityCompressor compressor = Natives.compress.get().create(Deflater.DEFAULT_COMPRESSION);
if (compressor instanceof JavaVelocityCompressor) { if (compressor instanceof JavaVelocityCompressor) {
compressor.dispose(); compressor.dispose();
fail("Loaded regular compressor"); fail("Loaded regular compressor");

Datei anzeigen

@ -28,7 +28,7 @@ class VelocityCipherTest {
void nativeIntegrityCheck() throws GeneralSecurityException { void nativeIntegrityCheck() throws GeneralSecurityException {
VelocityCipherFactory factory = Natives.cipher.get(); VelocityCipherFactory factory = Natives.cipher.get();
if (factory == JavaVelocityCipher.FACTORY) { if (factory == JavaVelocityCipher.FACTORY) {
fail("Loaded regular compressor"); fail("Loaded regular cipher");
} }
check(factory); check(factory);
} }

Datei anzeigen

@ -248,7 +248,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
} }
int level = server.getConfiguration().getCompressionLevel(); int level = server.getConfiguration().getCompressionLevel();
VelocityCompressor compressor = Natives.compressor.get().create(level); VelocityCompressor compressor = Natives.compress.get().create(level);
MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor); MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor);
MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor); MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor);

Datei anzeigen

@ -39,7 +39,7 @@ public final class ConnectionManager {
public void logChannelInformation() { public void logChannelInformation() {
LOGGER.info("Connections will use {} channels, {} compression, {} ciphers", this.transportType, LOGGER.info("Connections will use {} channels, {} compression, {} ciphers", this.transportType,
Natives.compressor.getLoadedVariant(), Natives.cipher.getLoadedVariant()); Natives.compress.getLoadedVariant(), Natives.cipher.getLoadedVariant());
} }
public void bind(final InetSocketAddress address) { public void bind(final InetSocketAddress address) {