Class PlayerPrefixEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.player.PlayerEvent
dev.plex.api.event.PlayerPrefixEvent

public final class PlayerPrefixEvent extends org.bukkit.event.player.PlayerEvent
Supplies additive prefixes before Plex renders a player's chat line or tab-list entry.

PlayerPrefixEvent.Target.TAB: Plex calls this synchronous event on the player's owning region at join and every 20 ticks.

PlayerPrefixEvent.Target.CHAT: Plex calls this event for each rendered chat line. The event is asynchronous when Plex renders a normal chat message. The event is synchronous when a module calls MessageApi.chatLine on a thread that can read the player.

For both targets, read cached state only. Do not perform database or network work. Each event starts with no prefixes. Add active prefixes on each call; Plex does not store them. Check getTarget() to contribute to one target only. Unregister listeners when their plugin or module stops.

Plex renders prefixes in listener order, then the tag, then the name. Plex inserts one space after each nonempty prefix and tag. In chat, the prefixes and the tag fill the <prefix> placeholder of chat.format, and the format supplies the space before the name. The base tag and name are read-only so independent plugins cannot replace them through this event.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Output that Plex renders with the prefixes.

    Nested classes/interfaces inherited from class org.bukkit.event.Event

    org.bukkit.event.Event.Result
  • Field Summary

    Fields inherited from class org.bukkit.event.player.PlayerEvent

    player
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlayerPrefixEvent(@NotNull org.bukkit.entity.Player player, @NotNull PlayerPrefixEvent.Target target, @NotNull net.kyori.adventure.text.Component name, @NotNull net.kyori.adventure.text.Component tag, boolean async)
    Creates a fresh prefix request.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPrefix(@NotNull net.kyori.adventure.text.Component prefix)
    Adds a prefix after prefixes from earlier listeners, before the tag.
    static @NotNull org.bukkit.event.HandlerList
    Returns the handler list for this event.
    @NotNull org.bukkit.event.HandlerList
     
    @NotNull net.kyori.adventure.text.Component
    Returns the base name.
    @NotNull List<net.kyori.adventure.text.Component>
    Returns the prefixes contributed so far.
    @NotNull net.kyori.adventure.text.Component
    Returns the base tag.
    Returns the output that Plex will render.

    Methods inherited from class org.bukkit.event.player.PlayerEvent

    getPlayer

    Methods inherited from class org.bukkit.event.Event

    callEvent, getEventName, isAsynchronous

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PlayerPrefixEvent

      public PlayerPrefixEvent(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull PlayerPrefixEvent.Target target, @NotNull @NotNull net.kyori.adventure.text.Component name, @NotNull @NotNull net.kyori.adventure.text.Component tag, boolean async)
      Creates a fresh prefix request.
      Parameters:
      player - player whose chat line or tab-list entry Plex will render
      target - output that Plex will render
      name - name that Plex renders after the tag
      tag - tag that Plex renders after the prefixes, or an empty component when no tag is set
      async - true when Plex calls the event off the server thread
  • Method Details

    • getTarget

      @NotNull public @NotNull PlayerPrefixEvent.Target getTarget()
      Returns the output that Plex will render.
      Returns:
      chat or tab target
    • getName

      @NotNull public @NotNull net.kyori.adventure.text.Component getName()
      Returns the base name.

      For PlayerPrefixEvent.Target.TAB, this is the display name or the rank-colored username. For PlayerPrefixEvent.Target.CHAT, this is the display name.

      Returns:
      base name
    • getTag

      @NotNull public @NotNull net.kyori.adventure.text.Component getTag()
      Returns the base tag.

      For PlayerPrefixEvent.Target.TAB, this is the custom tag. For PlayerPrefixEvent.Target.CHAT, this is the custom tag, or the rank prefix when no custom tag is set.

      Returns:
      tag without a separator, or an empty component
    • addPrefix

      public void addPrefix(@NotNull @NotNull net.kyori.adventure.text.Component prefix)
      Adds a prefix after prefixes from earlier listeners, before the tag.
      Parameters:
      prefix - prefix without a trailing separator; an empty component is ignored
    • getPrefixes

      @NotNull public @NotNull List<net.kyori.adventure.text.Component> getPrefixes()
      Returns the prefixes contributed so far.
      Returns:
      immutable snapshot of prefixes in rendering order
    • getHandlers

      @NotNull public @NotNull org.bukkit.event.HandlerList getHandlers()
      Specified by:
      getHandlers in class org.bukkit.event.Event
    • getHandlerList

      @NotNull public static @NotNull org.bukkit.event.HandlerList getHandlerList()
      Returns the handler list for this event.
      Returns:
      handler list for this event