Class SmartString

java.lang.Object
top.magstar.framework.SmartString

public class SmartString extends Object
Converts custom RGB-style markup into Minecraft-supported formatting codes.

Supported formats:

  • <#RRGGBB>text</#> — RGB color
  • <bold>text</bold> — Bold
  • <italic>text</italic> — Italic
  • <underlined>text</underlined> — Underlined
  • <strikethrough>text</strikethrough> — Strikethrough
  • <obfuscated>text</obfuscated> — Obfuscated (magic text)
  • <gradient:#RRGGBB:#RRGGBB:#RRGGBB:...>text</gradient> — Gradient between multiple colors

Advanced formats:

  • <rainbow>text</rainbow> — Rainbow colored text (cannot be nested inside other tags).
  • <progress_bar:{progress}:{length}:{#color1}:{#color2}:...>X</progress_bar> — Progress bar with gradient fill; X must be a single character. (cannot be nested inside other tags).
  • <center:{width}>example</center> — Center-align text (nested tags allowed).
  • <click:{action}:{value}>example</click> — Clickable events supporting actions: change_page, copy, command, suggest. (only color tags can be nested, gradient not allowed).
  • <hover:{action}:{content1}:{content2}:...>example</hover> — Hover events supporting actions: text, item. (only color tags can be nested, gradient not allowed).

This system enables combining rich text formatting with interactive features such as hover and click events, while extending Minecraft's default chat formatting codes.

  • Constructor Details

    • SmartString

      public SmartString(@NotNull @NotNull String s)
    • SmartString

      public SmartString()
    • SmartString

      public SmartString(@NotNull @NotNull String... args)
  • Method Details

    • getString

      @NotNull public @NotNull String getString()
    • toString

      @NotNull public @NotNull String toString()
      Overrides:
      toString in class Object
    • getTranslated

      @NotNull public @NotNull SmartString getTranslated()
    • removeSpace

      @NotNull public @NotNull SmartString removeSpace()
    • parseRGBFormat

      @NotNull public @NotNull SmartString parseRGBFormat()
    • toComponents

      public net.md_5.bungee.api.chat.BaseComponent[] toComponents()
    • getParsedString

      @NotNull public @NotNull String getParsedString()
      便捷方法:直接获取解析后的字符串
    • containsAdvancedTags

      public boolean containsAdvancedTags()
      检查是否包含高级标签
    • containsRGBFormat

      public boolean containsRGBFormat()
      检查字符串是否包含RGB格式标签
    • stripFormatting

      @NotNull public @NotNull SmartString stripFormatting()
      移除所有颜色符号与格式标签,只保留纯文本
    • append

      @NotNull public @NotNull SmartString append(@NotNull @NotNull SmartString... args)
    • append

      @NotNull public @NotNull SmartString append(@NotNull @NotNull String... args)
    • replacePlaceholders

      @NotNull public @NotNull SmartString replacePlaceholders(@NotNull @NotNull String... input)
    • isEmpty

      public boolean isEmpty()
      检查字符串是否为空或仅包含空白字符
      Returns:
      如果字符串为空或仅含空白字符返回true
    • length

      public int length()
      获取字符串长度
      Returns:
      字符串长度
    • contentLength

      public int contentLength()
      获取不含格式代码的纯文本长度
      Returns:
      纯文本长度
    • substring

      @NotNull public @NotNull SmartString substring(int start, int end)
      截取字符串的一部分
      Parameters:
      start - 起始索引
      end - 结束索引
      Returns:
      新的SmartString对象
    • toLowerCase

      @NotNull public @NotNull SmartString toLowerCase()
      转换为小写
      Returns:
      小写形式的SmartString
    • toUpperCase

      @NotNull public @NotNull SmartString toUpperCase()
      转换为大写
      Returns:
      大写形式的SmartString
    • center

      @NotNull public @NotNull SmartString center(int width)
      居中显示文本
      Parameters:
      width - 总宽度
      Returns:
      居中的文本
    • equals

      public boolean equals(Object obj)
      比较两个SmartString的内容是否相等
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      返回字符串的哈希码
      Overrides:
      hashCode in class Object
    • toComponentString

      @NotNull public @NotNull ComponentString toComponentString()
      将SmartString转换为ComponentString,用于高级标签处理
      Returns:
      新的ComponentString对象
    • replace

      public SmartString replace(String s1, String s2)