This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from TheFruxz/feature/unfold
Add JET-Unfold - Structured component build way
- Loading branch information
Showing
16 changed files
with
194 additions
and
23 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
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
2 changes: 1 addition & 1 deletion
2
JET-Paper/src/main/kotlin/de/jet/paper/extension/display/Transmission.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
kotlin("jvm") | ||
kotlin("plugin.serialization") | ||
} | ||
|
||
repositories { | ||
|
||
mavenCentral() | ||
|
||
} | ||
|
||
dependencies { | ||
|
||
implementation(project(":JET-JVM")) | ||
testImplementation(kotlin("test")) | ||
implementation(kotlin("reflect")) | ||
|
||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0") | ||
|
||
implementation("io.ktor:ktor-client-serialization:1.6.8") | ||
implementation("io.ktor:ktor-client-core:1.6.8") | ||
implementation("io.ktor:ktor-client-cio:1.6.8") | ||
|
||
implementation("net.kyori:adventure-api:4.10.1") | ||
implementation("net.kyori:adventure-text-serializer-legacy:4.10.1") | ||
implementation("net.kyori:adventure-text-minimessage:4.10.1") | ||
|
||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
tasks { | ||
|
||
withType<KotlinCompile> { | ||
kotlinOptions.jvmTarget = "17" | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
JET-Unfold/src/main/kotlin/de/jet/unfold/MoltenComponent.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,17 @@ | ||
package de.jet.unfold | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TextComponent | ||
import java.util.function.Consumer | ||
|
||
object MoltenComponent { | ||
|
||
@JvmStatic | ||
fun construct(process: Consumer<TextComponent.Builder>): Component = text(process::accept) | ||
|
||
@JvmStatic | ||
fun fromString(text: String) = text { | ||
text(text) | ||
} | ||
|
||
} |
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,11 @@ | ||
package de.jet.unfold | ||
|
||
interface MoltenContext<T> { | ||
|
||
companion object { | ||
|
||
fun <X> contextOf() = object : MoltenContext<X> { } | ||
|
||
} | ||
|
||
} |
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,78 @@ | ||
@file:Suppress("unused") // TODO use kotlin context API to avoid 'useless' seeming object extensions | ||
|
||
package de.jet.unfold | ||
|
||
import io.ktor.http.* | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TextComponent | ||
import net.kyori.adventure.text.event.ClickEvent | ||
import net.kyori.adventure.text.event.HoverEventSource | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import java.io.File | ||
import java.net.URL | ||
import java.nio.file.Path | ||
|
||
private fun String.transform() = Component.text().append(MiniMessage.miniMessage().deserialize(this)).build() | ||
|
||
fun text(build: TextComponent.Builder.() -> Unit) = | ||
Component.text().apply(build).build() | ||
|
||
fun text(componentContent: String) = | ||
Component.text().append(componentContent.transform()) | ||
|
||
fun space() = Component.space() | ||
|
||
fun empty() = Component.empty() | ||
|
||
fun newline() = Component.newline() | ||
|
||
fun MoltenContext<HoverEventSource<*>>.text(componentContent: String) = | ||
text { text(componentContent) } | ||
|
||
fun MoltenContext<HoverEventSource<*>>.space() = | ||
text { text(" ") } | ||
|
||
fun MoltenContext<HoverEventSource<*>>.empty() = | ||
text { text("") } | ||
|
||
fun MoltenContext<HoverEventSource<*>>.newline() = | ||
text { text("\n") } | ||
|
||
operator fun TextComponent.Builder.plus(component: Component) = | ||
append(component) | ||
|
||
fun TextComponent.Builder.text(componentContent: String) = | ||
this + componentContent.transform() | ||
|
||
fun TextComponent.Builder.text(componentContent: String, modify: TextComponent.Builder.() -> Unit) = | ||
this.append(componentContent.transform().toBuilder().apply(modify).build()) | ||
|
||
fun TextComponent.Builder.hover(eventSource: MoltenContext<HoverEventSource<*>>.() -> HoverEventSource<*>) = | ||
hoverEvent(eventSource(MoltenContext.contextOf())) | ||
|
||
fun TextComponent.Builder.click(click: MoltenContext<ClickEvent>.() -> ClickEvent) = | ||
clickEvent(click(MoltenContext.contextOf())) | ||
|
||
fun MoltenContext<ClickEvent>.url(url: String) = ClickEvent.openUrl(url) | ||
|
||
fun MoltenContext<ClickEvent>.url(url: URL) = ClickEvent.openUrl(url) | ||
|
||
fun MoltenContext<ClickEvent>.url(url: Url) = ClickEvent.openUrl(url.toString()) | ||
|
||
fun MoltenContext<ClickEvent>.file(file: String) = ClickEvent.openFile(file) | ||
|
||
fun MoltenContext<ClickEvent>.file(path: Path) = file("$path") | ||
|
||
fun MoltenContext<ClickEvent>.file(file: File) = file(file.toPath()) | ||
|
||
fun MoltenContext<ClickEvent>.run(command: String) = ClickEvent.runCommand(command) | ||
|
||
fun MoltenContext<ClickEvent>.suggest(command: String) = ClickEvent.suggestCommand(command) | ||
|
||
fun MoltenContext<ClickEvent>.toPage(page: Int) = ClickEvent.changePage(page) | ||
|
||
fun MoltenContext<ClickEvent>.toPage(page: String) = ClickEvent.changePage(page) | ||
|
||
fun MoltenContext<ClickEvent>.copy(text: String) = ClickEvent.copyToClipboard(text) | ||
|
||
fun MoltenContext<ClickEvent>.click(action: ClickEvent.Action, string: String) = ClickEvent.clickEvent(action, string) |
33 changes: 18 additions & 15 deletions
33
...de/jet/paper/extension/paper/Adventure.kt → ...tlin/de/jet/unfold/extension/Adventure.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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
package de.jet.paper.extension.paper | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TextComponent | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer | ||
|
||
val Component.legacyString: String | ||
get() = LegacyComponentSerializer.legacySection().serialize(this) | ||
|
||
val TextComponent.legacyString: String | ||
get() = LegacyComponentSerializer.legacySection().serialize(this) | ||
|
||
val Any?.adventureComponent: TextComponent | ||
get() = LegacyComponentSerializer.builder().hexColors().extractUrls().build().deserializeOr("$this", Component.text("FAILED", NamedTextColor.RED))!! | ||
package de.jet.unfold.extension | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TextComponent | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer | ||
|
||
val adventureSerializer = LegacyComponentSerializer | ||
.builder().extractUrls().hexColors().build() | ||
|
||
val Component.legacyString: String | ||
get() = adventureSerializer.serialize(this) | ||
|
||
val TextComponent.legacyString: String | ||
get() = adventureSerializer.serialize(this) | ||
|
||
val Any?.adventureComponent: TextComponent | ||
get() = adventureSerializer.deserializeOr("$this", Component.text("FAILED", NamedTextColor.RED))!! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ rootProject.name = "JET" | |
include("JET-JVM") | ||
include("JET-JavaCord") | ||
include("JET-Paper") | ||
include("JET-Unfold") |