Interface PlayerLoginAttemptEvent

All Superinterfaces:
Cancellable, Event

public interface PlayerLoginAttemptEvent extends Event, Cancellable
Called when a client attempts to log in.

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 Type
    Method
    Description
    Gets the address the client is connecting from.
    boolean
    Checks whether this identity was actually verified.
    Gets the identity the client is connecting with.
    Gets the reason the connection was refused.
    void
    refuse(Component reason)
    Refuses the connection, disconnecting the client with the given reason.
    void
    retrieveCookie(Key key, Consumer<Optional<byte[]>> action)
    Asks the client for a cookie, and holds the login until it answers.
    void
    setCancelled(boolean cancelled)
    Refuses or re-allows the connection.
    boolean
    Checks 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.

      false means 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:
      true if 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-transfers off, they are turned away before this event. The flag is whatever the client announced, so it does not prove which server sent it.

      Returns:
      true if the client announced a transfer
      Since:
      0.1.0
    • retrieveCookie

      void retrieveCookie(Key key, Consumer<Optional<byte[]>> action)
      Asks the client for a cookie, and holds the login until it answers.

      action receives 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 cookie
      action - what to do with the cookie, once the client has answered
      Throws:
      IllegalArgumentException - if key or action is null
      Since:
      0.1.0
      See Also:
    • refuse

      void refuse(Component reason)
      Refuses the connection, disconnecting the client with the given reason.
      Parameters:
      reason - the message shown to the client
      Throws:
      IllegalArgumentException - if reason is null
      Since:
      0.1.0
    • refusal

      Optional<Component> 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:
      setCancelled in interface Cancellable
      Parameters:
      cancelled - whether the connection should be refused
      Since:
      0.1.0