-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathAsyncPlayerPreLoginEvent.java
More file actions
377 lines (339 loc) · 11.9 KB
/
AsyncPlayerPreLoginEvent.java
File metadata and controls
377 lines (339 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package org.bukkit.event.player;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.UUID;
import com.destroystokyo.paper.profile.PlayerProfile;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import io.papermc.paper.connection.PlayerLoginConnection;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Stores details for players attempting to log in.
* <p>
* This event is asynchronous, and not run using main thread.
* <p>
* This event is fired after the server has successfully completed
* Mojang authentication. The event is still fired if the server is in offline mode.
* <p>
* When this event is fired, the player's locale is not
* available. Therefore, any translatable component will be
* rendered with the default locale, {@link java.util.Locale#US}.
* <p>
* Consider rendering any translatable yourself with {@link net.kyori.adventure.translation.GlobalTranslator#render}
* if the client's language is known.
*/
public class AsyncPlayerPreLoginEvent extends Event {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final InetAddress ipAddress;
private final SocketAddress rawAddress;
private final String hostname;
private final boolean transferred;
private Result result;
private Component message;
private PlayerProfile profile;
private final PlayerLoginConnection playerLoginConnection;
@ApiStatus.Internal
@Deprecated(since = "1.7.5", forRemoval = true)
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress) {
this(name, ipAddress, null);
}
@ApiStatus.Internal
@Deprecated(since = "1.20.5", forRemoval = true)
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId) {
this(name, ipAddress, uniqueId, false);
}
@ApiStatus.Internal
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId, boolean transferred) {
this(name, ipAddress, uniqueId, transferred, org.bukkit.Bukkit.createProfile(uniqueId, name));
}
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId, boolean transferred, @NotNull com.destroystokyo.paper.profile.PlayerProfile profile) {
this(name, ipAddress, ipAddress, uniqueId, transferred, profile);
}
@ApiStatus.Internal
@Deprecated(forRemoval = true)
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final InetAddress rawAddress, @NotNull final UUID uniqueId, boolean transferred, @NotNull com.destroystokyo.paper.profile.PlayerProfile profile) {
this(name, ipAddress, new InetSocketAddress(rawAddress, 0), uniqueId, transferred, profile, "", null);
}
@ApiStatus.Internal
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final SocketAddress rawAddress, @NotNull final UUID uniqueId, boolean transferred, @NotNull com.destroystokyo.paper.profile.PlayerProfile profile, @NotNull String hostname, final PlayerLoginConnection playerLoginConnection) {
super(true);
this.result = Result.ALLOWED;
this.message = Component.empty();
this.profile = profile;
this.ipAddress = ipAddress;
this.rawAddress = rawAddress;
this.hostname = hostname;
this.transferred = transferred;
this.playerLoginConnection = playerLoginConnection;
}
/**
* Gets the current result of the login, as an enum
*
* @return Current Result of the login
*/
@NotNull
public Result getLoginResult() {
return this.result;
}
/**
* Gets the current result of the login, as an enum
*
* @return Current Result of the login
* @see #getLoginResult()
* @deprecated This method uses a deprecated enum from {@link
* PlayerPreLoginEvent}
*/
@Deprecated(since = "1.3.2")
@NotNull
public PlayerPreLoginEvent.Result getResult() {
return this.result == null ? null : this.result.old(); // todo a lot of nullability issues in this class + player profile
}
/**
* Sets the new result of the login, as an enum
*
* @param result New result to set
*/
public void setLoginResult(@NotNull final Result result) {
this.result = result;
}
/**
* Sets the new result of the login, as an enum
*
* @param result New result to set
* @see #setLoginResult(Result)
* @deprecated This method uses a deprecated enum from {@link
* PlayerPreLoginEvent}
*/
@Deprecated(since = "1.3.2")
public void setResult(@NotNull final PlayerPreLoginEvent.Result result) {
this.result = result == null ? null : Result.valueOf(result.name());
}
/**
* Gets the current kick message that will be used when the outcome is not allowed
*
* @return Current kick message
*/
@NotNull
public Component kickMessage() {
return this.message;
}
/**
* Sets the kick message to display when the outcome is not allowed
*
* @param message New kick message
*/
public void kickMessage(@NotNull final Component message) {
this.message = message;
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
*/
public void disallow(@NotNull final Result result, @NotNull final Component message) {
this.result = result;
this.message = message;
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated This method uses a deprecated enum from {@link
* PlayerPreLoginEvent}
* @see #disallow(Result, String)
*/
@Deprecated
public void disallow(@NotNull final PlayerPreLoginEvent.Result result, @NotNull final net.kyori.adventure.text.Component message) {
this.result = result == null ? null : Result.valueOf(result.name());
this.message = message;
}
/**
* Gets the current kick message that will be used when the outcome is not allowed
*
* @return Current kick message
* @deprecated in favour of {@link #kickMessage()}
*/
@NotNull
@Deprecated
public String getKickMessage() {
return LegacyComponentSerializer.legacySection().serialize(this.message);
}
/**
* Sets the kick message to display when the outcome is not allowed
*
* @param message New kick message
* @deprecated in favour of {@link #kickMessage(Component)}
*/
@Deprecated
public void setKickMessage(@NotNull final String message) {
this.message = LegacyComponentSerializer.legacySection().deserialize(message);
}
/**
* Allows the player to log in
*/
public void allow() {
this.result = Result.ALLOWED;
this.message = Component.empty();
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated in favour of {@link #disallow(org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result, Component)}
*/
@Deprecated
public void disallow(@NotNull final Result result, @NotNull final String message) {
this.result = result;
this.message = LegacyComponentSerializer.legacySection().deserialize(message);
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @see #disallow(Result, String)
* @deprecated This method uses a deprecated enum from {@link
* PlayerPreLoginEvent}
*/
@Deprecated(since = "1.3.2")
public void disallow(@NotNull final PlayerPreLoginEvent.Result result, @NotNull final String message) {
this.result = result == null ? null : Result.valueOf(result.name());
this.message = LegacyComponentSerializer.legacySection().deserialize(message);
}
/**
* Gets the player's name.
*
* @return the player's name
*/
@NotNull
public String getName() {
return this.profile.getName();
}
/**
* Gets the player IP address.
*
* @return The IP address
*/
@NotNull
public InetAddress getAddress() {
return this.ipAddress;
}
/**
* Gets the player's unique ID.
*
* @return The unique ID
*/
@NotNull
public UUID getUniqueId() {
return this.profile.getId();
}
/**
* Gets the PlayerProfile of the player logging in
* @return The Profile
*/
@NotNull
public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
return this.profile;
}
/**
* Changes the PlayerProfile the player will login as
* @param profile The profile to use
*/
public void setPlayerProfile(@NotNull com.destroystokyo.paper.profile.PlayerProfile profile) {
this.profile = profile;
}
/**
* Gets the raw socket address of the player logging in
* @return The socket address
*/
@NotNull
public SocketAddress getRawSocketAddress() {
return this.rawAddress;
}
/**
* Gets the raw address of the player logging in
* @return The address, or the loopback address if the player is connecting
* through a Unix socket
*/
@NotNull
public InetAddress getRawAddress() {
if (this.rawAddress instanceof InetSocketAddress inet) return inet.getAddress();
return InetAddress.getLoopbackAddress();
}
/**
* Gets the hostname that the player used to connect to the server, or
* blank if unknown
*
* @return The hostname
*/
@NotNull
public String getHostname() {
return this.hostname;
}
/**
* Gets if this connection has been transferred from another server.
*
* @return {@code true} if the connection has been transferred
*/
public boolean isTransferred() {
return this.transferred;
}
/**
* Gets the connection for the player logging in.
* @return connection
*/
@ApiStatus.Experimental
@NotNull
public PlayerLoginConnection getConnection() {
return playerLoginConnection;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
/**
* Basic kick reasons for communicating to plugins
*/
public enum Result {
/**
* The player is allowed to log in
*/
ALLOWED,
/**
* The player is not allowed to log in, due to the server being full
*/
KICK_FULL,
/**
* The player is not allowed to log in, due to them being banned
*/
KICK_BANNED,
/**
* The player is not allowed to log in, due to them not being on the
* white list
*/
KICK_WHITELIST,
/**
* The player is not allowed to log in, for reasons undefined
*/
KICK_OTHER;
@Deprecated(since = "1.3.2")
@NotNull
private PlayerPreLoginEvent.Result old() {
return PlayerPreLoginEvent.Result.valueOf(name());
}
}
}