Class ClickEvent<T extends ClickEvent.Payload>

java.lang.Object
net.kyori.adventure.text.event.ClickEvent<T>
Type Parameters:
T - the payload type
All Implemented Interfaces:
ComponentBuilderApplicable, StyleBuilderApplicable

public final class ClickEvent<T extends ClickEvent.Payload> extends Object implements StyleBuilderApplicable
A click event.

A click event processes an ClickEvent.Action when clicked on.

Since:
4.0.0
  • Method Details

    • openUrl

      public static ClickEvent<ClickEvent.Payload.Text> openUrl(String url)
      Creates a click event that opens a url.

      Since Minecraft: Java Edition 1.21.5 the url will fail to parse if not a http:// or https:// scheme.

      Parameters:
      url - the url to open
      Returns:
      a click event
      Since:
      4.0.0
    • openUrl

      public static ClickEvent<ClickEvent.Payload.Text> openUrl(URL url)
      Creates a click event that opens a url.
      Parameters:
      url - the url to open
      Returns:
      a click event
      Since:
      4.0.0
    • openFile

      public static ClickEvent<ClickEvent.Payload.Text> openFile(String file)
      Creates a click event that opens a file.

      This action is not readable, and may only be used locally on the client.

      Parameters:
      file - the file to open
      Returns:
      a click event
      Since:
      4.0.0
    • runCommand

      public static ClickEvent<ClickEvent.Payload.Text> runCommand(String command)
      Creates a click event that runs a command.
      Parameters:
      command - the command to run
      Returns:
      a click event
      Since:
      4.0.0
    • suggestCommand

      public static ClickEvent<ClickEvent.Payload.Text> suggestCommand(String command)
      Creates a click event that suggests a command.
      Parameters:
      command - the command to suggest
      Returns:
      a click event
      Since:
      4.0.0
    • changePage

      public static ClickEvent<ClickEvent.Payload.Int> changePage(int page)
      Creates a click event that changes to a page.
      Parameters:
      page - the page to change to
      Returns:
      a click event
      Since:
      4.0.0
    • copyToClipboard

      public static ClickEvent<ClickEvent.Payload.Text> copyToClipboard(String text)
      Creates a click event that copies text to the clipboard.
      Parameters:
      text - the text to copy to the clipboard
      Returns:
      a click event
      Since:
      4.0.0
      Since Minecraft:
      1.15
    • callback

      public static ClickEvent<?> callback(ClickCallback<Audience> function)
      Create a click event that, when clicked, will schedule a callback function to be executed on the server.

      By default, this will be a single-use function that expires after the value of ClickCallback.DEFAULT_LIFETIME.

      Parameters:
      function - the function to execute
      Returns:
      a callback click event
      Since:
      4.13.0
    • callback

      public static ClickEvent<?> callback(ClickCallback<Audience> function, ClickCallback.Options options)
      Create a click event that, when clicked, will schedule a callback function to be executed on the server.
      Parameters:
      function - the function to execute
      options - options to control how the callback will be stored on the server.
      Returns:
      a callback click event
      Since:
      4.13.0
    • callback

      public static ClickEvent<?> callback(ClickCallback<Audience> function, Consumer<ClickCallback.Options.Builder> optionsBuilder)
      Create a click event that, when clicked, will schedule a callback function to be executed on the server.
      Parameters:
      function - the function to execute
      optionsBuilder - function that will be called to configure the click callback options
      Returns:
      a callback click event
      Since:
      4.13.0
    • showDialog

      public static ClickEvent<ClickEvent.Payload.Dialog> showDialog(DialogLike dialog)
      Creates a click event that shows a dialog.
      Parameters:
      dialog - the dialog
      Returns:
      the click event
      Since:
      4.22.0
    • custom

      public static ClickEvent<ClickEvent.Payload.Custom> custom(Key key)
      Creates a click event that sends a custom event to the server.
      Parameters:
      key - the key identifying the payload
      Returns:
      the click event
      Since:
      5.0.0
    • custom

      public static ClickEvent<ClickEvent.Payload.Custom> custom(Key key, @Nullable BinaryTagHolder nbt)
      Creates a click event that sends a custom event to the server.

      See BinaryTagHolder.binaryTagHolder(String) for a simple way to create NBT from SNBT. For simple use cases, you can use plain strings directly as SNBT.

      Parameters:
      key - the key identifying the payload
      nbt - the nbt data
      Returns:
      the click event
      Since:
      4.23.0
    • clickEvent

      public static <T extends ClickEvent.Payload> ClickEvent<T> clickEvent(ClickEvent.Action<T> action, T payload)
      Creates a click event with a payload.
      Type Parameters:
      T - the payload type
      Parameters:
      action - the action
      payload - the payload
      Returns:
      a click event
      Throws:
      IllegalArgumentException - if the action does not support that payload, or if the payload is not valid for the action
      Since:
      4.25.0
    • action

      public ClickEvent.Action<T> action()
      Gets the click event action.
      Returns:
      the click event action
      Since:
      4.0.0
    • payload

      public ClickEvent.Payload payload()
      Gets the payload associated with this click event.
      Returns:
      the payload
      Since:
      4.22.0
    • styleApply

      public void styleApply(Style.Builder style)
      Description copied from interface: StyleBuilderApplicable
      Applies to style.
      Specified by:
      styleApply in interface StyleBuilderApplicable
      Parameters:
      style - the style builder
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object