类 ComponentBuilder

java.lang.Object
net.md_5.bungee.api.chat.ComponentBuilder

public final class ComponentBuilder extends Object

ComponentBuilder simplifies creating basic messages by allowing the use of a chainable builder.

 new ComponentBuilder("Hello ").color(ChatColor.RED).
 append("World").color(ChatColor.BLUE). append("!").bold(true).create();
 

All methods (excluding append(String) and create() work on the last part appended to the builder, so in the example above "Hello " would be ChatColor.RED and "World" would be ChatColor.BLUE but "!" would be bold and ChatColor.BLUE because append copies the previous part's formatting

  • 构造器详细资料

    • ComponentBuilder

      public ComponentBuilder(ComponentBuilder original)
      Creates a ComponentBuilder from the other given ComponentBuilder to clone it.
      参数:
      original - the original for the new ComponentBuilder.
    • ComponentBuilder

      public ComponentBuilder(String text)
      Creates a ComponentBuilder with the given text as the first part.
      参数:
      text - the first text element
    • ComponentBuilder

      public ComponentBuilder(BaseComponent component)
      Creates a ComponentBuilder with the given component as the first part.
      参数:
      component - the first component element
  • 方法详细资料

    • resetCursor

      public ComponentBuilder resetCursor()
      Resets the cursor to index of the last element.
      返回:
      this ComponentBuilder for chaining
    • setCursor

      public ComponentBuilder setCursor(int pos) throws IndexOutOfBoundsException
      Sets the position of the current component to be modified
      参数:
      pos - the cursor position synonymous to an element position for a list
      返回:
      this ComponentBuilder for chaining
      抛出:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • append

      public ComponentBuilder append(BaseComponent component)
      Appends a component to the builder and makes it the current target for formatting. The component will have all the formatting from previous part.
      参数:
      component - the component to append
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(BaseComponent component, ComponentBuilder.FormatRetention retention)
      Appends a component to the builder and makes it the current target for formatting. You can specify the amount of formatting retained from previous part.
      参数:
      component - the component to append
      retention - the formatting to retain
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(BaseComponent[] components)
      Appends the components to the builder and makes the last element the current target for formatting. The components will have all the formatting from previous part.
      参数:
      components - the components to append
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(BaseComponent[] components, ComponentBuilder.FormatRetention retention)
      Appends the components to the builder and makes the last element the current target for formatting. You can specify the amount of formatting retained from previous part.
      参数:
      components - the components to append
      retention - the formatting to retain
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(String text)
      Appends the text to the builder and makes it the current target for formatting. The text will have all the formatting from previous part.
      参数:
      text - the text to append
      返回:
      this ComponentBuilder for chaining
    • appendLegacy

      public ComponentBuilder appendLegacy(String text)
      Parse text to BaseComponent[] with colors and format, appends the text to the builder and makes it the current target for formatting. The component will have all the formatting from previous part.
      参数:
      text - the text to append
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(String text, ComponentBuilder.FormatRetention retention)
      Appends the text to the builder and makes it the current target for formatting. You can specify the amount of formatting retained from previous part.
      参数:
      text - the text to append
      retention - the formatting to retain
      返回:
      this ComponentBuilder for chaining
    • append

      public ComponentBuilder append(ComponentBuilder.Joiner joiner)
      Allows joining additional components to this builder using the given ComponentBuilder.Joiner and ComponentBuilder.FormatRetention.ALL. Simply executes the provided joiner on this instance to facilitate a chain pattern.
      参数:
      joiner - joiner used for operation
      返回:
      this ComponentBuilder for chaining
    • append

      Allows joining additional components to this builder using the given ComponentBuilder.Joiner. Simply executes the provided joiner on this instance to facilitate a chain pattern.
      参数:
      joiner - joiner used for operation
      retention - the formatting to retain
      返回:
      this ComponentBuilder for chaining
    • removeComponent

      public void removeComponent(int pos) throws IndexOutOfBoundsException
      Remove the component part at the position of given index.
      参数:
      pos - the index to remove at
      抛出:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • getComponent

      public BaseComponent getComponent(int pos) throws IndexOutOfBoundsException
      Gets the component part at the position of given index.
      参数:
      pos - the index to find
      返回:
      the component
      抛出:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
    • getCurrentComponent

      public BaseComponent getCurrentComponent()
      Gets the component at the position of the cursor.
      返回:
      the active component or null if builder is empty
    • color

      public ComponentBuilder color(ChatColor color)
      Sets the color of the current part.
      参数:
      color - the new color
      返回:
      this ComponentBuilder for chaining
    • font

      public ComponentBuilder font(String font)
      Sets the font of the current part.
      参数:
      font - the new font
      返回:
      this ComponentBuilder for chaining
    • bold

      public ComponentBuilder bold(boolean bold)
      Sets whether the current part is bold.
      参数:
      bold - whether this part is bold
      返回:
      this ComponentBuilder for chaining
    • italic

      public ComponentBuilder italic(boolean italic)
      Sets whether the current part is italic.
      参数:
      italic - whether this part is italic
      返回:
      this ComponentBuilder for chaining
    • underlined

      public ComponentBuilder underlined(boolean underlined)
      Sets whether the current part is underlined.
      参数:
      underlined - whether this part is underlined
      返回:
      this ComponentBuilder for chaining
    • strikethrough

      public ComponentBuilder strikethrough(boolean strikethrough)
      Sets whether the current part is strikethrough.
      参数:
      strikethrough - whether this part is strikethrough
      返回:
      this ComponentBuilder for chaining
    • obfuscated

      public ComponentBuilder obfuscated(boolean obfuscated)
      Sets whether the current part is obfuscated.
      参数:
      obfuscated - whether this part is obfuscated
      返回:
      this ComponentBuilder for chaining
    • insertion

      public ComponentBuilder insertion(String insertion)
      Sets the insertion text for the current part.
      参数:
      insertion - the insertion text
      返回:
      this ComponentBuilder for chaining
    • event

      public ComponentBuilder event(ClickEvent clickEvent)
      Sets the click event for the current part.
      参数:
      clickEvent - the click event
      返回:
      this ComponentBuilder for chaining
    • event

      public ComponentBuilder event(HoverEvent hoverEvent)
      Sets the hover event for the current part.
      参数:
      hoverEvent - the hover event
      返回:
      this ComponentBuilder for chaining
    • reset

      public ComponentBuilder reset()
      Sets the current part back to normal settings. Only text is kept.
      返回:
      this ComponentBuilder for chaining
    • retain

      Retains only the specified formatting. Text is not modified.
      参数:
      retention - the formatting to retain
      返回:
      this ComponentBuilder for chaining
    • create

      public BaseComponent[] create()
      Returns the components needed to display the message created by this builder.git
      返回:
      the created components