13
0
geforkt von Mirrors/Velocity

Full Checkstyle compliance at last.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-30 03:28:45 -05:00
Ursprung 20c3966f6f
Commit abc5ef7f5e
16 geänderte Dateien mit 158 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -104,18 +104,11 @@ public class VelocityServer implements ProxyServer {
}
public KeyPair getServerKeyPair() {
if (serverKeyPair == null) {
throw new AssertionError();
}
return serverKeyPair;
return ensureInitialized(serverKeyPair);
}
public VelocityConfiguration getConfiguration() {
VelocityConfiguration cfg = this.configuration;
if (cfg == null) {
throw new IllegalStateException("Configuration not initialized!");
}
return cfg;
return ensureInitialized(this.configuration);
}
@Override
@ -250,6 +243,12 @@ public class VelocityServer implements ProxyServer {
return shutdown;
}
/**
* Reloads the proxy's configuration.
*
* @return {@code true} if successful, {@code false} if we can't read the configuration
* @throws IOException if we can't read {@code velocity.toml}
*/
public boolean reloadConfiguration() throws IOException {
Path configPath = Paths.get("velocity.toml");
VelocityConfiguration newConfiguration = VelocityConfiguration.read(configPath);
@ -331,6 +330,11 @@ public class VelocityServer implements ProxyServer {
return true;
}
/**
* Shuts down the proxy.
*
* @param explicitExit whether the user explicitly shut down the proxy
*/
public void shutdown(boolean explicitExit) {
if (eventManager == null || pluginManager == null || cm == null || scheduler == null) {
throw new AssertionError();
@ -365,19 +369,25 @@ public class VelocityServer implements ProxyServer {
}
public NettyHttpClient getHttpClient() {
if (httpClient == null) {
throw new IllegalStateException("HTTP client not initialized");
}
return httpClient;
return ensureInitialized(httpClient);
}
public Ratelimiter getIpAttemptLimiter() {
if (ipAttemptLimiter == null) {
throw new IllegalStateException("Ratelimiter not initialized");
}
return ipAttemptLimiter;
return ensureInitialized(ipAttemptLimiter);
}
private static <T> T ensureInitialized(T o) {
if (o == null) {
throw new IllegalStateException("The proxy isn't fully initialized.");
}
return o;
}
/**
* Attempts to register the {@code connection} with the proxy.
* @param connection the connection to register
* @return {@code true} if we registered the connection, {@code false} if not
*/
public boolean registerConnection(ConnectedPlayer connection) {
String lowerName = connection.getUsername().toLowerCase(Locale.US);
if (connectionsByName.putIfAbsent(lowerName, connection) != null) {

Datei anzeigen

@ -266,6 +266,11 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
return motd;
}
/**
* Returns the proxy's MOTD.
*
* @return the MOTD
*/
public Component getMotdComponent() {
if (motdAsComponent == null) {
if (motd.startsWith("{")) {

Datei anzeigen

@ -95,7 +95,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
}
if (PluginMessageUtil.isMcBrand(packet)) {
PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion());
PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
server.getVersion());
serverConn.getPlayer().getConnection().write(rewritten);
return true;
}

Datei anzeigen

@ -212,6 +212,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
return true;
}
/**
* Indicates that we have completed the plugin process.
*/
public void completeJoin() {
if (!hasCompletedJoin) {
hasCompletedJoin = true;

Datei anzeigen

@ -296,6 +296,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
}
}
/**
* Handles the {@code JoinGame} packet. This function is responsible for handling the client-side
* switching servers in Velocity.
* @param joinGame the join game packet
*/
public void handleBackendJoinGame(JoinGame joinGame) {
VelocityServerConnection serverConn = player.getConnectedServer();
if (serverConn == null) {
@ -387,6 +392,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
return knownChannels;
}
/**
* Handles additional tab complete for 1.12 and lower clients.
*
* @param response the tab complete response from the backend
*/
public void handleTabCompleteResponse(TabCompleteResponse response) {
if (outstandingTabComplete != null) {
if (!outstandingTabComplete.isAssumeCommand()

Datei anzeigen

@ -296,6 +296,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
connectionInFlight = null;
}
/**
* Handles unexpected disconnects.
* @param server the server we disconnected from
* @param throwable the exception
*/
public void handleConnectionException(RegisteredServer server, Throwable throwable) {
if (throwable == null) {
throw new NullPointerException("throwable");
@ -321,6 +326,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
handleConnectionException(server, null, TextComponent.of(userMessage, TextColor.RED));
}
/**
* Handles unexpected disconnects.
* @param server the server we disconnected from
* @param disconnect the disconnect packet
*/
public void handleConnectionException(RegisteredServer server, Disconnect disconnect) {
Component disconnectReason = ComponentSerializers.JSON.deserialize(disconnect.getReason());
String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason);
@ -382,6 +392,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
}
}
/**
* Finds another server to attempt to log into, if we were unexpectedly disconnected from the
* server.
* @return the next server to try
*/
public Optional<RegisteredServer> getNextServerToTry() {
if (serversToTry == null) {
String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString).orElse("");
@ -402,6 +417,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return server.getServer(toTryName);
}
/**
* Sets the player's new connected server and clears the in-flight connection.
*
* @param serverConnection the new server connection
*/
public void setConnectedServer(@Nullable VelocityServerConnection serverConnection) {
this.connectedServer = serverConnection;
this.tryIndex = 0; // reset since we got connected to a server

Datei anzeigen

@ -1,13 +1,12 @@
package com.velocitypowered.proxy.console;
import static com.velocitypowered.api.permission.PermissionFunction.*;
import static com.velocitypowered.api.permission.PermissionFunction.ALWAYS_TRUE;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.ConsoleCommandSource;
import com.velocitypowered.proxy.VelocityServer;
import java.io.PrintWriter;
import java.util.List;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
@ -44,11 +43,17 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
return this.permissionFunction.getPermissionValue(permission);
}
/**
* Sets up {@code System.out} and {@code System.err} to redirect to log4j.
*/
public void setupStreams() {
System.setOut(IoBuilder.forLogger(logger).setLevel(Level.INFO).buildPrintStream());
System.setErr(IoBuilder.forLogger(logger).setLevel(Level.ERROR).buildPrintStream());
}
/**
* Sets up permissions for the console.
*/
public void setupPermissions() {
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE);
// we can safely block here, this is before any listeners fire

Datei anzeigen

@ -36,6 +36,11 @@ public final class ConnectionManager {
private final DnsAddressResolverGroup resolverGroup;
/**
* Initalizes the {@code ConnectionManager}.
*
* @param server a reference to the Velocity server
*/
public ConnectionManager(VelocityServer server) {
this.server = server;
this.transportType = TransportType.bestType();
@ -52,6 +57,11 @@ public final class ConnectionManager {
Natives.compress.getLoadedVariant(), Natives.cipher.getLoadedVariant());
}
/**
* Binds a Minecraft listener to the specified {@code address}.
*
* @param address the address to bind to
*/
public void bind(final InetSocketAddress address) {
final ServerBootstrap bootstrap = new ServerBootstrap()
.channel(this.transportType.serverSocketChannelClass)
@ -73,6 +83,12 @@ public final class ConnectionManager {
});
}
/**
* Binds a GS4 listener to the specified {@code hostname} and {@code port}.
*
* @param hostname the hostname to bind to
* @param port the port to bind to
*/
public void queryBind(final String hostname, final int port) {
InetSocketAddress address = new InetSocketAddress(hostname, port);
final Bootstrap bootstrap = new Bootstrap()
@ -92,6 +108,11 @@ public final class ConnectionManager {
});
}
/**
* Creates a TCP {@link Bootstrap} using Velocity's event loops.
*
* @return a new {@link Bootstrap}
*/
public Bootstrap createWorker() {
return new Bootstrap()
.channel(this.transportType.socketChannelClass)
@ -102,6 +123,11 @@ public final class ConnectionManager {
.resolver(this.resolverGroup);
}
/**
* Closes the specified {@code oldBind} endpoint.
*
* @param oldBind the endpoint to close
*/
public void close(InetSocketAddress oldBind) {
Channel serverChannel = endpoints.remove(oldBind);
Preconditions.checkState(serverChannel != null, "Endpoint %s not registered", oldBind);
@ -109,6 +135,9 @@ public final class ConnectionManager {
serverChannel.close().syncUninterruptibly();
}
/**
* Closes all endpoints.
*/
public void shutdown() {
for (final Channel endpoint : this.endpoints.values()) {
try {

Datei anzeigen

@ -27,6 +27,11 @@ public class NettyHttpClient {
private final ChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap;
private final String userAgent;
/**
* Initializes the HTTP client.
*
* @param server the Velocity server
*/
public NettyHttpClient(VelocityServer server) {
this.userAgent = server.getVersion().getName() + "/" + server.getVersion().getVersion();
Bootstrap bootstrap = server.initializeGenericBootstrap();

Datei anzeigen

@ -44,6 +44,11 @@ public class VelocityEventManager implements EventManager {
private final ExecutorService service;
private final PluginManager pluginManager;
/**
* Initializes the Velocity event manager.
*
* @param pluginManager a reference to the Velocity plugin manager
*/
public VelocityEventManager(PluginManager pluginManager) {
// Expose the event executors to the plugins - required in order for the generated ASM classes
// to work.

Datei anzeigen

@ -46,6 +46,11 @@ public class VelocityPluginManager implements PluginManager {
}
}
/**
* Loads all plugins from the specified {@code directory}.
* @param directory the directory to load from
* @throws IOException if we could not open the directory
*/
public void loadPlugins(Path directory) throws IOException {
checkNotNull(directory, "directory");
checkArgument(directory.toFile().isDirectory(), "provided path isn't a directory");

Datei anzeigen

@ -25,6 +25,17 @@ public class VelocityPluginDescription implements PluginDescription {
private final Map<String, PluginDependency> dependencies;
private final Path source;
/**
* Creates a new plugin description.
* @param id the ID
* @param name the name of the plugin
* @param version the plugin version
* @param description a description of the plugin
* @param url the website for the plugin
* @param authors the authors of this plugin
* @param dependencies the dependencies for this plugin
* @param source the original source for the plugin
*/
public VelocityPluginDescription(String id, @Nullable String name, @Nullable String version,
@Nullable String description, @Nullable String url,
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source) {

Datei anzeigen

@ -35,7 +35,8 @@ public class PluginDependencyUtils {
.allowsSelfLoops(false)
.expectedNodeCount(candidates.size())
.build();
Map<String, PluginDescription> candidateMap = Maps.uniqueIndex(candidates, PluginDescription::getId);
Map<String, PluginDescription> candidateMap = Maps.uniqueIndex(candidates,
PluginDescription::getId);
for (PluginDescription description : candidates) {
graph.addNode(description);

Datei anzeigen

@ -17,6 +17,11 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf> {
private StateRegistry state;
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
/**
* Creates a new {@code MinecraftDecoder} decoding packets from the specified {@code direction}.
*
* @param direction the direction from which we decode from
*/
public MinecraftDecoder(ProtocolUtils.Direction direction) {
this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = direction

Datei anzeigen

@ -15,6 +15,11 @@ public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> {
private StateRegistry state;
private StateRegistry.PacketRegistry.ProtocolRegistry registry;
/**
* Creates a new {@code MinecraftEncoder} encoding packets for the specified {@code direction}.
*
* @param direction the direction to encode to
*/
public MinecraftEncoder(ProtocolUtils.Direction direction) {
this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = direction

Datei anzeigen

@ -1,5 +1,8 @@
package com.velocitypowered.proxy.scheduler;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
@ -29,6 +32,11 @@ public class VelocityScheduler implements Scheduler {
private final Multimap<Object, ScheduledTask> tasksByPlugin = Multimaps.synchronizedMultimap(
Multimaps.newSetMultimap(new IdentityHashMap<>(), HashSet::new));
/**
* Initalizes the scheduler.
*
* @param pluginManager the Velocity plugin manager
*/
public VelocityScheduler(PluginManager pluginManager) {
this.pluginManager = pluginManager;
this.taskService = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true)
@ -40,13 +48,17 @@ public class VelocityScheduler implements Scheduler {
@Override
public TaskBuilder buildTask(Object plugin, Runnable runnable) {
Preconditions.checkNotNull(plugin, "plugin");
Preconditions.checkNotNull(runnable, "runnable");
Preconditions
.checkArgument(pluginManager.fromInstance(plugin).isPresent(), "plugin is not registered");
checkNotNull(plugin, "plugin");
checkNotNull(runnable, "runnable");
checkArgument(pluginManager.fromInstance(plugin).isPresent(), "plugin is not registered");
return new TaskBuilderImpl(plugin, runnable);
}
/**
* Shuts down the Velocity scheduler.
* @return {@code true} if all tasks finished, {@code false} otherwise
* @throws InterruptedException if the current thread was interrupted
*/
public boolean shutdown() throws InterruptedException {
Collection<ScheduledTask> terminating;
synchronized (tasksByPlugin) {
@ -121,7 +133,7 @@ public class VelocityScheduler implements Scheduler {
this.repeat = repeat;
}
public void schedule() {
void schedule() {
if (repeat == 0) {
this.future = timerExecutionService.schedule(this, delay, TimeUnit.MILLISECONDS);
} else {