-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more Components instead of Strings (#44)
Closes #36
- Loading branch information
Showing
9 changed files
with
89 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/net/axay/kspigot/extensions/bukkit/ComponentExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@file:Suppress("unused") | ||
package net.axay.kspigot.extensions.bukkit | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TranslatableComponent | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer | ||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer | ||
import net.kyori.adventure.translation.GlobalTranslator | ||
import java.util.Locale | ||
|
||
/** | ||
* Returns a [Component] from a [String] | ||
*/ | ||
fun String.toComponent(): Component = Component.text(this) | ||
|
||
/** | ||
* Returns a [TranslatableComponent] with the given [String] as key and [args] | ||
*/ | ||
fun String.asTranslatable(vararg args: Component): TranslatableComponent = Component.translatable(this, *args) | ||
|
||
/** | ||
* Returns a [Component] from a [String] with legacy formatting | ||
*/ | ||
fun String.legacyToComponent(): Component = LegacyComponentSerializer.legacyAmpersand().deserialize(this) | ||
|
||
/** | ||
* Returns a [String] with legacy formatting from a [Component] | ||
* | ||
* Note: Render [TranslatableComponent]s before using this | ||
*/ | ||
fun Component.toLegacyString(): String = LegacyComponentSerializer.legacyAmpersand().serialize(this) | ||
|
||
/** | ||
* Returns a [String] from a [Component] | ||
* | ||
* Note: Render [TranslatableComponent]s before using this | ||
*/ | ||
fun Component.plainText(): String = PlainTextComponentSerializer.plainText().serialize(this) | ||
|
||
/** | ||
* Renders a [TranslatableComponent] with the given [locale] | ||
*/ | ||
fun TranslatableComponent.render(locale: Locale): Component = GlobalTranslator.render(this, locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters