Interface PlayerLoginAttemptEvent
- All Superinterfaces:
Cancellable, Event
Listeners can refuse the connection with refuse(Component). This is preferred over
setCancelled(boolean), which does not allow you to say why. To decide from a cookie, such as one
stored by the server that transferred the player here, use retrieveCookie(Key, Consumer): the
login waits for the client's answer.
- Since:
- 0.1.0
-
Method Summary
Modifier and TypeMethodDescriptionaddress()Gets the address the client is connecting from.booleanChecks whether this identity was actually verified.profile()Gets the identity the client is connecting with.refusal()Gets the reason the connection was refused.voidRefuses the connection, disconnecting the client with the given reason.voidretrieveCookie(Key key, Consumer<Optional<byte[]>> action) Asks the client for a cookie, and holds the login until it answers.voidsetCancelled(boolean cancelled) Refuses or re-allows the connection.booleanChecks whether the client was sent here by another server, with a transfer.Methods inherited from interface Cancellable
isCancelled
-
Method Details
-
profile
PlayerProfile profile()Gets the identity the client is connecting with.- Returns:
- the profile
- Since:
- 0.1.0
-
address
String address()Gets the address the client is connecting from.When a proxy sits in front of the server, this is the address the proxy forwarded, not the proxy's own.
- Returns:
- the client address
- Since:
- 0.1.0
-
authenticated
boolean authenticated()Checks whether this identity was actually verified.falsemeans the server is running in offline mode and the uuid was derived from the name the client asked for, so it proves nothing. Treat anything security-sensitive accordingly.- Returns:
trueif the identity was verified- Since:
- 0.1.0
-
transferred
boolean transferred()Checks whether the client was sent here by another server, with a transfer.Only clients the server accepts transfers from get this far: with
network.accepts-transfersoff, they are turned away before this event. The flag is whatever the client announced, so it does not prove which server sent it.- Returns:
trueif the client announced a transfer- Since:
- 0.1.0
-
retrieveCookie
Asks the client for a cookie, and holds the login until it answers.actionreceives the content of the cookie, or an empty optional if the client has none, and can still refuse the connection: the server decides once every cookie asked for has been answered. Call this while handling the event, or from the action of another cookie; the action runs on the network thread, so it must not block. If it throws, the connection is refused.event.retrieveCookie(TICKET, ticket -> { if (ticket.isEmpty() || !tickets.verify(ticket.get())) { event.refuse(Component.text("Join through the lobby")); } });Clients only keep cookies through a transfer: a client connecting directly has none. The client can send back anything, so sign the cookies you need to trust.
- Parameters:
key- the identifier of the cookieaction- what to do with the cookie, once the client has answered- Throws:
IllegalArgumentException- ifkeyoractionis null- Since:
- 0.1.0
- See Also:
-
refuse
Refuses the connection, disconnecting the client with the given reason.- Parameters:
reason- the message shown to the client- Throws:
IllegalArgumentException- ifreasonis null- Since:
- 0.1.0
-
refusal
Gets the reason the connection was refused.- Returns:
- the reason, or empty when none was given - including when the event was cancelled
through
setCancelled(boolean) - Since:
- 0.1.0
-
setCancelled
void setCancelled(boolean cancelled) Refuses or re-allows the connection.Prefer
refuse(Component), which lets you say why. Re-allowing a connection another listener refused also drops the reason it gave.- Specified by:
setCancelledin interfaceCancellable- Parameters:
cancelled- whether the connection should be refused- Since:
- 0.1.0
-