Interface Document

All Superinterfaces:
DomQueryable, EventTarget

public interface Document extends EventTarget, DomQueryable
  • Field Details

    • ACTIVE_TICKS

      static final int ACTIVE_TICKS
      Amount of ticks an element remains 'active' for after being clicked
      See Also:
  • Method Details

    • getView

      DocumentView getView()
      Gets the document view.
      Returns:
      Document view, or null, if the document hasn't been shown to a player yet.
    • getOption

      @Nullable @Nullable String getOption(String optionKey)
      Gets the value of the option
      Parameters:
      optionKey - Option key
      Returns:
      Option value, or null, if the option has no set value.
    • setOption

      void setOption(@NotNull @NotNull String optionKey, @Nullable @Nullable String value)
      Set an option's value

      If the option value is null or empty, then this acts the same as calling removeOption(String)

      Will trigger an EventTypes.MODIFY_OPTION event after changing the value.

      Parameters:
      optionKey - Option key
      value - Option value
      Throws:
      NullPointerException - if optionKey is null
    • removeOption

      void removeOption(@NotNull @NotNull String optionKey)
      Removes an option's value.

      If the option already has no set value, this method does nothing. Otherwise, it will trigger an EventTypes.MODIFY_OPTION event after changing the value.

      Parameters:
      optionKey - Option key
      Throws:
      NullPointerException - if optionKey is null
    • getOptionKeys

      Set<String> getOptionKeys()
      Gets a set of all option keys.
      Returns:
      Unmodifiable option key set
    • createElement

      Element createElement(@NotNull @NotNull String tagName)
      Parameters:
      tagName - Element's tag name.
      Returns:
      Created element
      Throws:
      NullPointerException - if tagName is null
    • createItemElement

      ItemElement createItemElement()
      Create an <item> element.
      Returns:
      Created item element.
    • createText

      TextNode createText()
      Creates an empty text node
      Returns:
      Empty text node
    • createText

      TextNode createText(@Nullable @Nullable String content)
      Creates a text node with the specified content
      Parameters:
      content - Node content
      Returns:
      Created text node
    • createComponent

      ComponentElement createComponent()
      Creates a component node.

      Component nodes differ from TextNodes by the fact they use a fully-styled, Component. It is not recommended to use this, because it can conflict with document styling.

      Components are required in certain instances, like in item tooltips, where it's not possible to dissect each line of the tooltip, and instead, a component node is used for the content.

      Returns:
      Created component node
    • createComponent

      ComponentElement createComponent(@Nullable @Nullable net.kyori.adventure.text.Component component)
      Create a component node.

      Component nodes differ from TextNodes by the fact they use a fully-styled, Component. It is not recommended to use this, because it can conflict with document styling.

      Components are required in certain instances, like in item tooltips, where it's not possible to dissect each line of the tooltip, and instead, a component node is used for the content.

      Parameters:
      component - Node content
      Returns:
      Created component node
    • newCustomEvent

      CustomEvent newCustomEvent(@NotNull @NotNull String eventType)
      Create a new custom event.

      Allows for creating and listening to custom event types with custom event properties.

      Before the event can be dispatched, it must be initialized with CustomEvent.initEvent(Element, boolean, boolean, Map).

      Parameters:
      eventType - Event Type
      Returns:
      Created event
      Throws:
      NullPointerException - If eventType is null
      IllegalArgumentException - If eventType is an empty string
    • getActiveElement

      @Nullable @Nullable Element getActiveElement()
      Gets the last clicked element that's still active.

      When an element is clicked, it will remain active for ACTIVE_TICKS ticks.

      Returns:
      Active element
    • getHoveredElement

      @Nullable @Nullable Element getHoveredElement()
      Gets the element the viewer's cursor is currently hovered over
      Returns:
      Hovered element
    • getBody

      BodyElement getBody()
      Gets the body element of the document.

      The body element contains all the content of a document

      Returns:
      Document body
    • getDocumentElement

      DelphiElement getDocumentElement()
      Get the root document element.
      Returns:
      Root document element
    • getHead

      HeadElement getHead()
      Get the <head> element
      Returns:
      Head element, or null, if no header was declared.
    • getElementById

      @Nullable @Nullable Element getElementById(String elementId)
      Gets the first descendant element of with the specified elementId
      Parameters:
      elementId - ID to search for
      Returns:
      Found element, or null, if no element with the specified id exists
    • getGlobalTarget

      @NotNull @NotNull EventTarget getGlobalTarget()
      Gets the global event target.

      The target returned by this method will be called after an event has finished propagation, unless the event has been cancelled.

      This target will be invoked after ALL events.

      Note that, calling the document's EventTarget.addEventListener(String, EventListener) is not the same as calling the add event listener on the returned event target.

      Returns:
      Global event target
    • adopt

      void adopt(@NotNull @NotNull Node node)
      Adopts a node if it belongs to another document instance.
      Parameters:
      node - Node to adopt.
      Throws:
      NullPointerException - if node is null
    • addStylesheet

      void addStylesheet(@NotNull @NotNull Stylesheet stylesheet)
      Adds a stylesheet to this document.
      Parameters:
      stylesheet - Style sheet
      Throws:
      NullPointerException - if stylesheet is null
    • getStylesheets

      @NotNull @NotNull List<Stylesheet> getStylesheets()
      Gets an unmodifiable list of stylesheets this document has.
      Returns:
      Unmodifiable stylesheet list.
    • createStylesheet

      @NotNull @NotNull StylesheetBuilder createStylesheet()
      Creates a new style sheet builder.

      When StylesheetBuilder.build() is called on the returned sheet, the stylesheet is automatically added to this document's stylesheet list.

      Returns:
      Created stylesheet builder