Class PlayerChatEvent

java.lang.Object
net.minestom.server.event.player.PlayerChatEvent
All Implemented Interfaces:
Event, CancellableEvent, EntityEvent, EntityInstanceEvent, InstanceEvent, PlayerEvent, PlayerInstanceEvent

public class PlayerChatEvent extends Object implements PlayerInstanceEvent, CancellableEvent
Called every time a Player writes and sends something in the chat. The event can be cancelled to not send anything, and the final message can be changed.
  • Constructor Details

    • PlayerChatEvent

      public PlayerChatEvent(@NotNull @NotNull Player player, @NotNull @NotNull Collection<Player> recipients, @NotNull @NotNull String rawMessage)
  • Method Details

    • getRecipients

      @NotNull public @NotNull Collection<Player> getRecipients()
      Returns the players who will receive the message.

      It can be modified to add and remove recipients.

      Returns:
      a modifiable list of the message's targets
    • getRawMessage

      @NotNull public @NotNull String getRawMessage()
      Gets the original message content sent by the player.
      Returns:
      the sender's message
    • getFormattedMessage

      public Component getFormattedMessage()
      Gets the final message component that will be sent.
      Returns:
      the chat message component
    • setFormattedMessage

      public void setFormattedMessage(@NotNull @NotNull Component message)
      Used to change the final message component.
      Parameters:
      message - the new message component
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: CancellableEvent
      Gets if the Event should be cancelled or not.
      Specified by:
      isCancelled in interface CancellableEvent
      Returns:
      true if the event should be cancelled
    • setCancelled

      public void setCancelled(boolean cancel)
      Description copied from interface: CancellableEvent
      Marks the Event as cancelled or not.
      Specified by:
      setCancelled in interface CancellableEvent
      Parameters:
      cancel - true if the event should be cancelled, false otherwise
    • getPlayer

      @NotNull public @NotNull Player getPlayer()
      Description copied from interface: PlayerEvent
      Gets the player.
      Specified by:
      getPlayer in interface PlayerEvent
      Returns:
      the player