Add debug message and use InetSocketAddress instead of string

This commit is contained in:
SageSphinx63920 2024-03-31 20:18:14 +02:00
parent c548f22476
commit c9b2c1abe7
2 changed files with 7 additions and 4 deletions

View File

@ -29,15 +29,17 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Cancellable;
import org.geysermc.event.Event;
import java.net.InetSocketAddress;
/**
* Called whenever a client attempts to connect to the server, before the connection is accepted.
*/
public final class ConnectionRequestEvent implements Event, Cancellable {
private boolean cancelled;
private final String ip;
private final InetSocketAddress ip;
public ConnectionRequestEvent(@NonNull String ip) {
public ConnectionRequestEvent(@NonNull InetSocketAddress ip) {
this.ip = ip;
}
@ -45,7 +47,7 @@ public final class ConnectionRequestEvent implements Event, Cancellable {
* @return the IP address of the client attempting to connect.
*/
@NonNull
public String getIp() {
public InetSocketAddress getInetSocketAddress() {
return ip;
}

View File

@ -235,9 +235,10 @@ public final class GeyserServer {
ip = "<IP address withheld>";
}
ConnectionRequestEvent requestEvent = new ConnectionRequestEvent(ip);
ConnectionRequestEvent requestEvent = new ConnectionRequestEvent(inetSocketAddress);
geyser.eventBus().fire(requestEvent);
if (requestEvent.isCancelled()) {
geyser.getLogger().debug("Connection request from " + ip + " was cancelled using the API!");
return false;
}