Commits
md_5 authored 0b541e604df
8 8 | /** |
9 9 | * Stores details for players attempting to log in. |
10 10 | * <br> |
11 11 | * Note that this event is called <i>early</i> in the player initialization |
12 12 | * process. It is recommended that most options involving the Player |
13 13 | * <i>entity</i> be postponed to the {@link PlayerJoinEvent} instead. |
14 14 | */ |
15 15 | public class PlayerLoginEvent extends PlayerEvent { |
16 16 | private static final HandlerList handlers = new HandlerList(); |
17 17 | private final InetAddress address; |
18 + | private final InetAddress realAddress; |
18 19 | private final String hostname; |
19 20 | private Result result = Result.ALLOWED; |
20 21 | private String message = ""; |
21 22 | |
22 23 | /** |
23 24 | * This constructor defaults message to an empty string, and result to |
24 25 | * ALLOWED |
25 26 | * |
26 27 | * @param player The {@link Player} for this event |
27 28 | * @param hostname The hostname that was used to connect to the server |
28 29 | * @param address The address the player used to connect, provided for |
29 30 | * timing issues |
31 + | * @param realAddress the actual, unspoofed connecting address |
30 32 | */ |
31 - | public PlayerLoginEvent( final Player player, final String hostname, final InetAddress address) { |
33 + | public PlayerLoginEvent( final Player player, final String hostname, final InetAddress address, final InetAddress realAddress) { |
32 34 | super(player); |
33 35 | this.hostname = hostname; |
34 36 | this.address = address; |
37 + | this.realAddress = realAddress; |
38 + | } |
39 + | |
40 + | /** |
41 + | * This constructor defaults message to an empty string, and result to |
42 + | * ALLOWED |
43 + | * |
44 + | * @param player The {@link Player} for this event |
45 + | * @param hostname The hostname that was used to connect to the server |
46 + | * @param address The address the player used to connect, provided for |
47 + | * timing issues |
48 + | */ |
49 + | public PlayerLoginEvent( final Player player, final String hostname, final InetAddress address) { |
50 + | this(player, hostname, address, address); |
35 51 | } |
36 52 | |
37 53 | /** |
38 54 | * This constructor pre-configures the event with a result and message |
39 55 | * |
40 56 | * @param player The {@link Player} for this event |
41 57 | * @param hostname The hostname that was used to connect to the server |
42 58 | * @param address The address the player used to connect, provided for |
43 59 | * timing issues |
44 60 | * @param result The result status for this event |
45 61 | * @param message The message to be displayed if result denies login |
62 + | * @param realAddress the actual, unspoofed connecting address |
46 63 | */ |
47 - | public PlayerLoginEvent( final Player player, String hostname, final InetAddress address, final Result result, final String message) { |
48 - | this(player, hostname, address); |
64 + | public PlayerLoginEvent( final Player player, String hostname, final InetAddress address, final Result result, final String message, final InetAddress realAddress) { |
65 + | this(player, hostname, address, realAddress); |
49 66 | this.result = result; |
50 67 | this.message = message; |
51 68 | } |
52 69 | |
53 70 | /** |
54 71 | * Gets the current result of the login, as an enum |
55 72 | * |
56 73 | * @return Current Result of the login |
57 74 | */ |
58 75 | |
125 142 | * returning null during PlayerLoginEvent. |
126 143 | * |
127 144 | * @return The address for this player. For legacy compatibility, this may |
128 145 | * be null. |
129 146 | */ |
130 147 | |
131 148 | public InetAddress getAddress() { |
132 149 | return address; |
133 150 | } |
134 151 | |
152 + | /** |
153 + | * Gets the connection address of this player, regardless of whether it has |
154 + | * been spoofed or not. |
155 + | * |
156 + | * @return the player's connection address |
157 + | * @see #getAddress() |
158 + | */ |
159 + | |
160 + | public InetAddress getRealAddress() { |
161 + | return realAddress; |
162 + | } |
163 + | |
135 164 | |
136 165 | |
137 166 | public HandlerList getHandlers() { |
138 167 | return handlers; |
139 168 | } |
140 169 | |
141 170 | |
142 171 | public static HandlerList getHandlerList() { |
143 172 | return handlers; |
144 173 | } |