Solved Why TextComponent So Strange?

yap241986

New member
May 20, 2023
6
0
1
Screenshot 2023-08-13 alle 01.06.35.png

My Code:
Java:
class PlayerJoinListener: Listener {
    @EventHandler
    fun playerJoinEvent(event: PlayerJoinEvent) {
        val player = event.player
        val joinMsg = Component.text("§f[§a+§f] §f ${player.name()}")
        event.joinMessage(joinMsg)

        val config = Bukkit.getPluginManager().getPlugin("AlpineMC")?.config!!
        if (config.getBoolean("serverSpawn.enabled")) {
            val worldName = config.getString("serverSpawn.world")
            val world = Bukkit.getWorld(worldName!!)
            val x = config.getDouble("serverSpawn.x")
            val y = config.getDouble("serverSpawn.y")
            val z = config.getDouble("serverSpawn.z")
            val yaw = config.getDouble("serverSpawn.yaw")
            val pitch = config.getDouble("serverSpawn.pitch")
            val location = Location(world, x, y, z, yaw.toFloat(), pitch.toFloat())
            player.teleport(location)
        }
    }
}
 
Version Output
1.20.1 build 117
Solution
You can’t append components like that, it’s currently being cast to a string and then added into your component plain text. You have to add them with Component#append:
Java:
Component.text("§f[§a+§f] §f ").append(player.name())

Also, you’re currently mixing legacy color codes (§) in components. You should properly set the colors via the component instead, see the adventure docs for more info.

Noah

Paper Developer
Staff member
Jan 4, 2022
44
6
16
8
The Netherlands
You can’t append components like that, it’s currently being cast to a string and then added into your component plain text. You have to add them with Component#append:
Java:
Component.text("§f[§a+§f] §f ").append(player.name())

Also, you’re currently mixing legacy color codes (§) in components. You should properly set the colors via the component instead, see the adventure docs for more info.
 
Solution