From 804a80b32799fb55686d048857d98ad1c58b2ca7 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot <noreply+git-bukkit@papermc.io> Date: Sat, 23 Dec 2023 12:32:24 +1100 Subject: [PATCH] Add PlayerLoginEvent#getRealAddress Adapted from Spigot commit 05db99ce17aa2ad094c413254c0945e004afe326. By: md_5 <git@md-5.net> --- .../bukkit/event/player/PlayerLoginEvent.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java index 498f0be826..2bc81b0aa7 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerLoginEvent.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.NotNull; public class PlayerLoginEvent extends PlayerEvent { private static final HandlerList handlers = new HandlerList(); private final InetAddress address; + private final InetAddress realAddress; private final String hostname; private Result result = Result.ALLOWED; private String message = ""; @@ -27,11 +28,26 @@ public class PlayerLoginEvent extends PlayerEvent { * @param hostname The hostname that was used to connect to the server * @param address The address the player used to connect, provided for * timing issues + * @param realAddress the actual, unspoofed connecting address */ - public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address) { + public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address, final @NotNull InetAddress realAddress) { super(player); this.hostname = hostname; this.address = address; + this.realAddress = realAddress; + } + + /** + * This constructor defaults message to an empty string, and result to + * ALLOWED + * + * @param player The {@link Player} for this event + * @param hostname The hostname that was used to connect to the server + * @param address The address the player used to connect, provided for + * timing issues + */ + public PlayerLoginEvent(@NotNull final Player player, @NotNull final String hostname, @NotNull final InetAddress address) { + this(player, hostname, address, address); } /** @@ -43,9 +59,10 @@ public class PlayerLoginEvent extends PlayerEvent { * timing issues * @param result The result status for this event * @param message The message to be displayed if result denies login + * @param realAddress the actual, unspoofed connecting address */ - public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final String message) { - this(player, hostname, address); + public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final String message, @NotNull final InetAddress realAddress) { + this(player, hostname, address, realAddress); this.result = result; this.message = message; } @@ -132,6 +149,18 @@ public class PlayerLoginEvent extends PlayerEvent { return address; } + /** + * Gets the connection address of this player, regardless of whether it has + * been spoofed or not. + * + * @return the player's connection address + * @see #getAddress() + */ + @NotNull + public InetAddress getRealAddress() { + return realAddress; + } + @NotNull @Override public HandlerList getHandlers() {