Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Minecraft Chat API #205

Closed
1 of 17 tasks
CoasterFreakDE opened this issue Mar 28, 2022 · 2 comments · Fixed by #212
Closed
1 of 17 tasks

Minecraft Chat API #205

CoasterFreakDE opened this issue Mar 28, 2022 · 2 comments · Fixed by #212
Assignees
Labels
From: user Created / Reported from user In: MoltenKT-Paper Affecting the MoltenKT-Paper / Paper-Server Target In: MoltenKT-Waterfall Affecting the MoltenKT-Waterfall / PaperMC Waterfall Target Relates: v1.0 Relates to the v1.0 Version/Release State: verified Verified, checked if true / real Type: enhancement New feature or request Type: ticket A ticket, to track something

Comments

@CoasterFreakDE
Copy link
Collaborator

CoasterFreakDE commented Mar 28, 2022

It should be possible to easily create texts for the 1.16+ mojang chat format based on the current environment (waterfall or paper).

There should be dsl fuctions for every aspect of the chat api with rgb hex color(static and gradient) support out of the box.
For rgb reference you can take a look at https://github.com/CoasterFreakDE/minecraft-spigot-rgb-chat-support (Feel free to include and/or edit the code for your needs)

Currently the Bungee Chat API supports most of the features but is hard to use ( https://www.spigotmc.org/wiki/the-chat-component-api/ )

To test all vanilla features you can use the following website: https://minecraft.tools/en/tellraw.php

An example dsl text could look like this:
image


Tasks:

  • Create a multi-plattform compatible structure
  • Create "adapters" for each platform (Paper, Bungee, Velocity)
  • Support common colors, but also a unifying
  • Kotlin JSON Support
  • Adventure!
  • ComponentTypes
    • Formatting
      • Color support
      • Hover & Action support
    • Special Components
      • Text
      • Translate
      • Keybind
      • Score
      • Selector
      • nbt
@CoasterFreakDE
Copy link
Collaborator Author

Working code snippet:

fun copy(text: String): ClickEvent {
    return ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text)
}

fun Array<BaseComponent>.click(function: () -> ClickEvent) {
    forEach { it.clickEvent = function() }
}

fun Array<BaseComponent>.hover(text: String) {
    forEach { it.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(text.build())) }
}

fun text(function: Array<BaseComponent>.() -> Array<BaseComponent>): Array<BaseComponent> {
    return function.invoke(arrayOf())
}

fun text(text: String): Array<BaseComponent> {
    return text.build()
}

fun Array<BaseComponent>.text(text: String): Array<BaseComponent> {
    return this + text.build()
}

fun text(text: String, function: Array<BaseComponent>.() -> Unit): Array<BaseComponent> {
    val message = text.build()
    return message.apply(function)
}

Works for hover & click to copy:

val message: Array<BaseComponent> = text {
        text("#d2dae2Username: ") +
        text("#fbc531${sender.name}") {
            hover("#fbc531Click to copy")
            click {
                copy(sender.name)
            }
        } +
        text(" #d2dae2Password: ") +
        text("#fbc531Hidden") {
            hover("#fbc531Click to copy")
            click {
                copy("ABC123")
            }
        }
    }
    sender.sendMessage(*message)

@TheFruxz TheFruxz added Type: enhancement New feature or request State: verified Verified, checked if true / real Relates: v1.0 Relates to the v1.0 Version/Release From: user Created / Reported from user In: MoltenKT-Paper Affecting the MoltenKT-Paper / Paper-Server Target In: MoltenKT-Waterfall Affecting the MoltenKT-Waterfall / PaperMC Waterfall Target Type: ticket A ticket, to track something labels Mar 30, 2022
@TheFruxz TheFruxz added this to the Stable Release | v1.0 milestone Mar 30, 2022
@TheFruxz
Copy link
Owner

Seems like a cool and flexible idea! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
From: user Created / Reported from user In: MoltenKT-Paper Affecting the MoltenKT-Paper / Paper-Server Target In: MoltenKT-Waterfall Affecting the MoltenKT-Waterfall / PaperMC Waterfall Target Relates: v1.0 Relates to the v1.0 Version/Release State: verified Verified, checked if true / real Type: enhancement New feature or request Type: ticket A ticket, to track something
Projects
No open projects
Status: 🍩Done
Development

Successfully merging a pull request may close this issue.

2 participants