Class ComponentString

java.lang.Object
top.magstar.framework.ComponentString

public class ComponentString extends Object
Represents an advanced text component builder for Minecraft chat messages.

ComponentString allows developers to construct rich chat messages using an extended placeholder/tag system, which is then parsed into BungeeCord's BaseComponent array.

Supported Features

  • Color and Formatting: Standard § color codes, hex colors, and style modifiers.
  • <rainbow>...</rainbow>: Apply rainbow-colored gradient to enclosed text.
  • <progress_bar:progress:length:colors>char</progress_bar>: Generate a gradient progress bar.
  • <center:width>...</center>: Center-align the content within a given width.
  • <linkify:url>...</linkify>: Create clickable hyperlinks with hover hints.
  • <hover:action:value>...</hover>: Assign hover text or item tooltips.
  • <click:action:value>...</click>: Attach click actions such as running/suggesting commands, copying text, or changing pages.

The class also provides helper builder methods (e.g. withHoverText, withClickCommand, progressBar) that wrap content with the corresponding tags, simplifying construction of formatted messages.

Version:
1.0
Author:
Magstar
  • Constructor Details

    • ComponentString

      public ComponentString(@NotNull @NotNull String content)
      创建一个新的ComponentString
      Parameters:
      content - 内容字符串
  • Method Details

    • getContent

      @NotNull public @NotNull String getContent()
      获取字符串内容
      Returns:
      原始内容
    • toComponents

      @NotNull public @NotNull net.md_5.bungee.api.chat.BaseComponent[] toComponents()
      解析高级标签并返回BaseComponent数组
      Returns:
      解析后的BaseComponent数组
    • withHoverText

      @NotNull public @NotNull ComponentString withHoverText(@NotNull @NotNull String text)
      添加悬停文本
    • withHoverItem

      @NotNull public @NotNull ComponentString withHoverItem(@NotNull @NotNull String itemJson)
      添加物品悬停提示
    • withClickCommand

      @NotNull public @NotNull ComponentString withClickCommand(@NotNull @NotNull String command)
      添加点击执行命令
    • withSuggestCommand

      @NotNull public @NotNull ComponentString withSuggestCommand(@NotNull @NotNull String command)
      添加点击建议命令
    • withCopyText

      @NotNull public @NotNull ComponentString withCopyText(@NotNull @NotNull String text)
      添加点击复制文本
    • withChangePage

      @NotNull public @NotNull ComponentString withChangePage(int page)
      添加点击更改页面
    • center

      @NotNull public @NotNull ComponentString center(int width)
      使内容居中显示
    • linkify

      @NotNull public @NotNull ComponentString linkify(@NotNull @NotNull String url)
      添加链接
    • rainbow

      @NotNull public @NotNull ComponentString rainbow()
      应用彩虹效果
    • progressBar

      @NotNull public static @NotNull ComponentString progressBar(double progress, int length, char barChar, String... colors)
      创建进度条
      Parameters:
      progress - 进度 (0.0-1.0)
      length - 长度
      barChar - 进度条字符
      colors - 颜色列表 (十六进制,不含#),最后一个颜色用于未完成部分
      Returns:
      格式化的进度条