Class CustomPlayerEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.player.PlayerEvent
net.mathias2246.buildmc.api.event.CustomPlayerEvent
Direct Known Subclasses:
PlayerEnterClaimEvent, PlayerLeaveClaimEvent, PlayerSpawnTeleportPreConditionEvent

public abstract class CustomPlayerEvent extends org.bukkit.event.player.PlayerEvent
Base class for player-related custom events that support metadata.

This class extends PlayerEvent to automatically associate an event instance with a Player, while also providing MetadataHolder-based metadata support for attaching custom contextual data.

Subclasses must define their own static HandlerList and override getHandlers() in accordance with Bukkit’s event system.

See Also:
  • Nested Class Summary

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

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

    Fields
    Modifier and Type
    Field
    Description
    protected final MetadataHolder
    Internal holder for metadata entries.

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

    player
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomPlayerEvent(@NotNull org.bukkit.entity.Player player)
    Constructs a new CustomPlayerEvent for the given player.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract @NotNull org.bukkit.event.HandlerList
    Returns the HandlerList for this event type.
    @NotNull Map<String,Object>
    Returns an unmodifiable view of the metadata map associated with this event.
    void
    putMetadata(@NotNull String key, @NotNull Object value)
    Adds or updates a metadata entry for this event.
    void
    removeMetadata(@NotNull String key)
    Removes a metadata entry associated with the given key.

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

    getPlayer

    Methods inherited from class org.bukkit.event.Event

    getEventName, isAsynchronous

    Methods inherited from class java.lang.Object

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

    • metadataHolder

      protected final MetadataHolder metadataHolder
      Internal holder for metadata entries.
  • Constructor Details

    • CustomPlayerEvent

      public CustomPlayerEvent(@NotNull @NotNull org.bukkit.entity.Player player)
      Constructs a new CustomPlayerEvent for the given player.
      Parameters:
      player - the player associated with this event (must not be null)
      Throws:
      NullPointerException - if player is null
  • Method Details

    • getMetadata

      @NotNull public @NotNull Map<String,Object> getMetadata()
      Returns an unmodifiable view of the metadata map associated with this event.

      The returned map reflects all metadata currently attached to the event. Use putMetadata(String, Object) or removeMetadata(String) to modify entries.

      Returns:
      an unmodifiable map of metadata (never null)
    • putMetadata

      public void putMetadata(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Adds or updates a metadata entry for this event.
      Parameters:
      key - the metadata key (must not be null)
      value - the metadata value (must not be null)
      Throws:
      NullPointerException - if key or value is null
    • removeMetadata

      public void removeMetadata(@NotNull @NotNull String key)
      Removes a metadata entry associated with the given key.

      If no entry exists for the given key, this method does nothing.

      Parameters:
      key - the metadata key to remove (must not be null)
      Throws:
      NullPointerException - if key is null
    • getHandlers

      @NotNull public abstract @NotNull org.bukkit.event.HandlerList getHandlers()
      Returns the HandlerList for this event type.

      Bukkit requires each concrete event class to define its own static HandlerList instance and to return it from this method. This is necessary for Bukkit’s event registration and dispatch system.

      Specified by:
      getHandlers in class org.bukkit.event.Event
      Returns:
      the handler list for this event (never null)