Utilities
Text and colours, items and heads, Bedrock checks, number formatting and other helpers.
Docs updated · What changed
Text: ColorUtil and MessageUtilLink to this section
All text accepts MiniMessage (<red>, <gradient:gold:red>) and legacy codes (&c, &l, &#ff8800, &x&f&f&8&8&0&0).
MessageUtil.send(sender, "&aSaved!")
MessageUtil.sendWithPAPI(player, "&7Rank: %luckperms_prefix%")
MessageUtil.actionBar(player, "&e+25 XP")
MessageUtil.sendTitle(player, "&6Level up!", "&7Level 12", fadeIn = 200, stay = 2000, fadeOut = 300) // ms
MessageUtil.broadcast("&dA boss spawned!", permission = null)
val component = ColorUtil.parse("&bHello <bold>there")
val plain = ColorUtil.toPlainText("&bHello") // "Hello"
val safe = ColorUtil.escape(chatMessage) // player text: always escapeItems and headsLink to this section
val sword = ItemBuilder(Material.DIAMOND_SWORD)
.name("&bStarter Sword")
.lore("&7Damage: &c5", "&7Tier: &aE")
.glow()
.unbreakable()
.data(key, PersistentDataType.STRING, "starter")
.build()
val head = HeadUtil.fromBase64(texture) // also fromPlayerName(name), fromPlayer(offlinePlayer)Names and lore are not italic by default. Pass a player (name(player, text)) to fill in placeholders. ignoreAlbLore() marks items that ALBLore should leave alone.
Bedrock playersLink to this section
BedrockUtil.isBedrock(player) is true for players who joined through Geyser/Floodgate (found by reflection, so neither is a dependency). Send them plain text instead of custom font glyphs, hover text or text displays, which Bedrock cannot show.
NumbersLink to this section
| Call | Result |
|---|---|
NumberUtil.formatNumber(1500L) | 1.5K |
NumberUtil.formatNumber(1234.5) | 1.23K |
NumberUtil.formatNumber(999_950L) | 1M |
NumberUtil.formatComma(1234567L) | 1,234,567 |
NumberUtil.parseNumber("2.5m") | 2500000 (null if invalid) |
Other helpersLink to this section
| Call | What it does |
|---|---|
SoundUtil.play(player, "minecraft:entity.player.levelup", 1f, 1.2f) | Play a sound by key (vanilla or resource pack). |
AnimationUtil.animateTitleNumber(player, title = "&a+%amount% coins", to = 500) | Count-up title. |
ShulkerUtil.process(items) { canSell(it) } | Split items, including shulker contents, into sell and return lists. |
PriceRegistry.set(plugin, Material.WHEAT, 2.5), getAverage(material, player) | Item prices shared between plugins. |
future.thenSync(plugin) { }, future.logFailure(logger, msg) | Future helpers. |