Reimplement #434 but aligned to the Velocity 2.0.0 API

This commit is contained in:
Andrew Steinborn
2021-05-12 09:33:13 -04:00
parent 11928f3737
commit 6fcef41146
7 changed files with 136 additions and 25 deletions

View File

@@ -7,12 +7,27 @@
package com.velocitypowered.api.event.connection;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.ResultedEvent.ComponentResult;
import com.velocitypowered.api.proxy.connection.InboundConnection;
import java.net.InetAddress;
import java.net.SocketAddress;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This event is fired when a handshake is established between a client and the proxy.
*/
public interface ConnectionHandshakeEvent {
public interface ConnectionHandshakeEvent extends ResultedEvent<ComponentResult> {
InboundConnection connection();
String currentHostname();
String originalHostname();
void setCurrentHostname(String hostname);
@Nullable SocketAddress currentRemoteHostAddress();
void setCurrentRemoteHostAddress(@Nullable SocketAddress address);
}

View File

@@ -9,6 +9,9 @@ package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection;
import java.net.InetAddress;
import java.net.SocketAddress;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This event is fired when a handshake is established between a client and the proxy.
@@ -16,9 +19,18 @@ import com.velocitypowered.api.proxy.connection.InboundConnection;
public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEvent {
private final InboundConnection connection;
private final String originalHostname;
private String currentHostname;
private ComponentResult result;
private SocketAddress currentRemoteAddress;
public ConnectionHandshakeEventImpl(InboundConnection connection) {
public ConnectionHandshakeEventImpl(InboundConnection connection,
String originalHostname) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.originalHostname = Preconditions.checkNotNull(originalHostname, "originalHostname");
this.currentHostname = originalHostname;
this.result = ComponentResult.allowed();
this.currentRemoteAddress = connection.remoteAddress();
}
@Override
@@ -26,10 +38,49 @@ public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEv
return connection;
}
@Override
public String currentHostname() {
return currentHostname;
}
@Override
public String originalHostname() {
return originalHostname;
}
@Override
public void setCurrentHostname(String hostname) {
currentHostname = Preconditions.checkNotNull(hostname, "hostname");
}
@Override
public @Nullable SocketAddress currentRemoteHostAddress() {
return currentRemoteAddress;
}
@Override
public void setCurrentRemoteHostAddress(SocketAddress address) {
currentRemoteAddress = address;
}
@Override
public ComponentResult result() {
return result;
}
@Override
public void setResult(ComponentResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "ConnectionHandshakeEvent{"
return "ConnectionHandshakeEventImpl{"
+ "connection=" + connection
+ ", originalHostname='" + originalHostname + '\''
+ ", currentHostname='" + currentHostname + '\''
+ ", result=" + result
+ ", currentRemoteAddress=" + currentRemoteAddress
+ '}';
}
}