Class PlayerLoginAttemptEvent

java.lang.Object
fr.fidorial.event.player.PlayerLoginAttemptEvent
All Implemented Interfaces:
Cancellable, Event

public final class PlayerLoginAttemptEvent extends Object implements 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.

Since:
0.1.0
  • Constructor Details

    • PlayerLoginAttemptEvent

      public PlayerLoginAttemptEvent(PlayerProfile profile, String address, boolean authenticated)
      Creates an event.
      Parameters:
      profile - the identity the client is connecting with
      address - the client address
      authenticated - whether the identity was verified, rather than derived from a name
      Since:
      0.1.0
  • Method Details

    • profile

      public PlayerProfile profile()
      Gets the identity the client is connecting with.
      Returns:
      the profile
      Since:
      0.1.0
    • address

      public 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

      public 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
    • refuse

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

      public 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
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Cancellable
    • setCancelled

      public 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