diff --git a/.gitignore b/.gitignore index 0f35681..23de33d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ build/ libs/ *.log* + +# Jetbrains IDE +.idea diff --git a/build.gradle.kts b/build.gradle.kts index 2ebe530..e92493d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,26 +6,23 @@ plugins { configureArtifactory() -repositories { - jcenter() -} - release { tagTemplate = "v\${version}" buildTasks = listOf() } val totalReport = tasks.register("jacocoTotalReport") { - subprojects.forEach { proj -> + for (proj in subprojects) { + proj.apply(plugin = "jacoco") proj.plugins.withId("java") { executionData( fileTree(proj.buildDir.absolutePath).include("**/jacoco/*.exec") ) sourceSets(proj.the().sourceSets["main"]) reports { - xml.isEnabled = true - xml.destination = rootProject.buildDir.resolve("reports/jacoco/report.xml") - html.isEnabled = true + xml.required.set(true) + xml.outputLocation.set(rootProject.buildDir.resolve("reports/jacoco/report.xml")) + html.required.set(true) } dependsOn(proj.tasks.named("test")) } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 13c0b6f..525f573 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,7 +4,6 @@ plugins { } repositories { - jcenter() gradlePluginPortal() maven { name = "EngineHub Repository" @@ -15,7 +14,7 @@ repositories { dependencies { implementation(gradleApi()) implementation(gradleKotlinDsl()) - implementation("org.enginehub.gradle:gradle-codecov-plugin:0.1.0-SNAPSHOT") - implementation("gradle.plugin.net.minecrell:licenser:0.4.1") - implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.13.0") + implementation("org.enginehub.gradle:gradle-codecov-plugin:0.1.0") + implementation("gradle.plugin.org.cadixdev.gradle:licenser:0.6.1") + implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.29.0") } diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index abf3688..8aed8d8 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -4,9 +4,9 @@ object Libs { const val junitEngine = "org.junit.jupiter:junit-jupiter-engine:$junitVersion" const val junitVintageEngine = "org.junit.vintage:junit-vintage-engine:$junitVersion" const val guava = "com.google.guava:guava" - private const val kyoriTextVersion = "3.0.4" - const val kyoriText = "net.kyori:text-api:$kyoriTextVersion" - const val kyoriTextPlain = "net.kyori:text-serializer-plain:$kyoriTextVersion" + private const val kyoriAdventureVersion = "4.14.0" + const val kyoriAdventure = "net.kyori:adventure-api:$kyoriAdventureVersion" + const val kyoriAdventureTextPlain = "net.kyori:adventure-text-serializer-plain:$kyoriAdventureVersion" const val autoCommon = "com.google.auto:auto-common:0.11" private const val autoValueVersion = "1.7.4" const val autoValueAnnotations = "com.google.auto.value:auto-value-annotations:$autoValueVersion" @@ -18,6 +18,6 @@ object Libs { const val log4jApi = "org.apache.logging.log4j:log4j-api:$log4jVersion" const val log4jCore = "org.apache.logging.log4j:log4j-core:$log4jVersion" const val javaxAnnotations = "com.google.code.findbugs:jsr305:3.0.2" - const val compileTesting = "com.google.testing.compile:compile-testing:0.19" + const val compileTesting = "com.google.testing.compile:compile-testing:0.21.0" const val mockito = "org.mockito:mockito-core:3.8.0" } diff --git a/buildSrc/src/main/kotlin/common.kt b/buildSrc/src/main/kotlin/common.kt index 9fa3889..418943d 100644 --- a/buildSrc/src/main/kotlin/common.kt +++ b/buildSrc/src/main/kotlin/common.kt @@ -1,12 +1,9 @@ -import net.minecrell.gradle.licenser.LicenseExtension -import org.gradle.api.JavaVersion +import org.cadixdev.gradle.licenser.LicenseExtension import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.SourceSetContainer -import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.api.tasks.testing.Test @@ -32,7 +29,7 @@ fun Project.applyCommonConfig( ) { apply(plugin = "java-library") apply(plugin = "java") - apply(plugin = "net.minecrell.licenser") + apply(plugin = "org.cadixdev.licenser") apply(plugin = "maven-publish") apply(plugin = "com.jfrog.artifactory") apply(plugin = "jacoco") @@ -40,9 +37,9 @@ fun Project.applyCommonConfig( project.group = group configure { - header = rootProject.file("HEADER.txt") - exclude("**/META-INF/**") - exclude("**/*.properties") + header(rootProject.file("HEADER.txt")) + include("**/*.java") + include("**/*.kt") } tasks.withType().configureEach { @@ -73,8 +70,14 @@ fun Project.applyCommonConfig( from(rootProject.file("common-test-resources")) } - configure { - toolchain.languageVersion.set(JavaLanguageVersion.of(8)) + tasks.withType { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + plugins.withId("java") { + the().toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } } tasks.withType().configureEach { (options as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet") diff --git a/core-ap/processor/build.gradle.kts b/core-ap/processor/build.gradle.kts index 8de5f3f..9958549 100644 --- a/core-ap/processor/build.gradle.kts +++ b/core-ap/processor/build.gradle.kts @@ -2,8 +2,8 @@ import org.gradle.internal.jvm.Jvm import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.4.31" - kotlin("kapt") version "1.4.31" + kotlin("jvm") version "1.9.0" + kotlin("kapt") version "1.9.0" } applyCoreApConfig() diff --git a/core-ap/processor/src/main/java/org/enginehub/piston/gen/util/CodeBlockUtil.java b/core-ap/processor/src/main/java/org/enginehub/piston/gen/util/CodeBlockUtil.java index 883150c..570414e 100644 --- a/core-ap/processor/src/main/java/org/enginehub/piston/gen/util/CodeBlockUtil.java +++ b/core-ap/processor/src/main/java/org/enginehub/piston/gen/util/CodeBlockUtil.java @@ -22,8 +22,7 @@ import com.google.common.collect.ImmutableList; import com.squareup.javapoet.CodeBlock; import com.squareup.javapoet.TypeName; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.internal.RegistrationUtil; import javax.annotation.Nullable; @@ -72,11 +71,11 @@ public static CodeBlock listForGen(Stream rawCode) { } public static CodeBlock textCompOf(String text) { - return CodeBlock.of("$T.of($S)", TextComponent.class, text); + return CodeBlock.of("$T.text($S)", Component.class, text); } public static CodeBlock transCompOf(String text) { - return CodeBlock.of("$T.of($S)", TranslatableComponent.class, text); + return CodeBlock.of("$T.translatable($S)", Component.class, text); } public static Collector joining(String delimiter) { diff --git a/core-ap/processor/src/test/kotlin/org/enginehub/piston/RegressionTest.kt b/core-ap/processor/src/test/kotlin/org/enginehub/piston/RegressionTest.kt index 5c11e4f..44a47a4 100644 --- a/core-ap/processor/src/test/kotlin/org/enginehub/piston/RegressionTest.kt +++ b/core-ap/processor/src/test/kotlin/org/enginehub/piston/RegressionTest.kt @@ -19,7 +19,7 @@ package org.enginehub.piston -import net.kyori.text.TextComponent +import net.kyori.adventure.text.Component import org.enginehub.piston.commands.RegressionCommands import org.enginehub.piston.commands.RegressionCommandsRegistration import org.enginehub.piston.converter.SimpleArgumentConverter @@ -36,7 +36,6 @@ import org.junit.jupiter.api.assertThrows import org.mockito.Mockito.mock import org.mockito.Mockito.times import org.mockito.Mockito.verify -import org.mockito.Mockito.verifyNoInteractions @DisplayName("Regression tests") class RegressionTest { @@ -94,10 +93,10 @@ class RegressionTest { action(it.valueOf(arg).asString()) 1 } - .description(TextComponent.of("Sub-command")) + .description(Component.text("Sub-command")) .build() cmd.run { - description(TextComponent.of("Issue 9 #2")) + description(Component.text("Issue 9 #2")) // Optional arg prior to sub-command addPart(arg) addPart(subs(sub)) @@ -137,11 +136,11 @@ class RegressionTest { } val sub = manager.newCommand("vert") .action { SUB_ACTION } - .description(TextComponent.of("Sub-command")) + .description(Component.text("Sub-command")) .build() cmd.run { action { ROOT_ACTION } - description(TextComponent.of("Issue 14")) + description(Component.text("Issue 14")) addPart(subs(sub, required = false)) addPart(req) addPart(optAfter) @@ -171,10 +170,10 @@ class RegressionTest { val sub = manager.newCommand("world") .action { SUB_ACTION } .aliases(setOf("there")) - .description(TextComponent.of("Sub-command")) + .description(Component.text("Sub-command")) .build() cmd.run { - description(TextComponent.of("hello")) + description(Component.text("hello")) addPart(subs(sub, required = true)) } } diff --git a/core-ap/processor/src/test/kotlin/org/enginehub/piston/TestSupport.kt b/core-ap/processor/src/test/kotlin/org/enginehub/piston/TestSupport.kt index bc4ab66..f083fb7 100644 --- a/core-ap/processor/src/test/kotlin/org/enginehub/piston/TestSupport.kt +++ b/core-ap/processor/src/test/kotlin/org/enginehub/piston/TestSupport.kt @@ -21,8 +21,7 @@ package org.enginehub.piston import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet -import net.kyori.text.TextComponent -import net.kyori.text.TranslatableComponent +import net.kyori.adventure.text.Component import org.enginehub.piston.gen.CommandRegistration import org.enginehub.piston.part.ArgAcceptingCommandFlag import org.enginehub.piston.part.CommandArgument @@ -56,21 +55,21 @@ inline fun withMockedContainer(block: (CI) -> Unit) { inline fun arg(name: String, desc: String, block: CommandArgument.Builder.() -> Unit = {}): CommandArgument = CommandParts.arg( - TranslatableComponent.of(name), - TextComponent.of(desc) + Component.translatable(name), + Component.text(desc) ).also(block).build() inline fun flag(name: Char, desc: String, block: NoArgCommandFlag.Builder.() -> Unit = {}): NoArgCommandFlag = CommandParts.flag( name, - TextComponent.of(desc) + Component.text(desc) ).also(block).build() inline fun argFlag(name: Char, desc: String, argName: String, block: ArgAcceptingCommandFlag.Builder.() -> Unit = {}): ArgAcceptingCommandFlag = CommandParts.flag( name, - TextComponent.of(desc) + Component.text(desc) ) .withRequiredArg() .argNamed(argName) @@ -78,8 +77,8 @@ inline fun argFlag(name: Char, desc: String, argName: String, fun subs(vararg subCommands: Command, required: Boolean = true): SubCommandPart = SubCommandPart.builder( - TranslatableComponent.of("actions"), - TextComponent.of("Sub-actions") + Component.translatable("actions"), + Component.text("Sub-actions") ).run { withCommands(ImmutableList.copyOf(subCommands)) diff --git a/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/ManagerSuggestionTest.kt b/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/ManagerSuggestionTest.kt index f6ef715..bea17ab 100644 --- a/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/ManagerSuggestionTest.kt +++ b/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/ManagerSuggestionTest.kt @@ -19,7 +19,8 @@ package org.enginehub.piston.suggestion -import net.kyori.text.TextComponent +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TextComponent import org.enginehub.piston.Command import org.enginehub.piston.CommandManager import org.enginehub.piston.assertEqualUnordered @@ -57,12 +58,12 @@ class ManagerSuggestionTest { } register("notpermitted") { cmd -> - cmd.description(TextComponent.of("Command with false condition")) + cmd.description(Component.text("Command with false condition")) cmd.condition(Command.Condition.FALSE) } register("sub") { cmd -> - cmd.description(TextComponent.of("Sub-commands test command")) + cmd.description(Component.text("Sub-commands test command")) cmd.addPart(subs(*allCommands.toList().toTypedArray())) } } @@ -91,7 +92,7 @@ class ManagerSuggestionTest { withSuggestionManager { manager -> manager.registerManager(newManager().apply { register("permitted") { cmd -> - cmd.description(TextComponent.of("Command with true condition")) + cmd.description(Component.text("Command with true condition")) cmd.condition(Command.Condition.TRUE) } }) diff --git a/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/SimpleSuggestingConverter.kt b/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/SimpleSuggestingConverter.kt index a0a8dd1..15b3d69 100644 --- a/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/SimpleSuggestingConverter.kt +++ b/core-ap/processor/src/test/kotlin/org/enginehub/piston/suggestion/SimpleSuggestingConverter.kt @@ -19,8 +19,8 @@ package org.enginehub.piston.suggestion -import net.kyori.text.Component -import net.kyori.text.TextComponent +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TextComponent import org.enginehub.piston.converter.ArgumentConverter import org.enginehub.piston.converter.ConversionResult import org.enginehub.piston.converter.FailedConversion @@ -37,7 +37,7 @@ class SimpleSuggestingConverter(private val suggestions: List) : Argumen } override fun describeAcceptableArguments(): Component { - return TextComponent.of("Any of $suggestions") + return Component.text("Any of $suggestions") } override fun getSuggestions(input: String, context: InjectedValueAccess): List = diff --git a/core-ap/processor/src/test/kotlin/org/enginehub/piston/util/HelpGeneratorTest.kt b/core-ap/processor/src/test/kotlin/org/enginehub/piston/util/HelpGeneratorTest.kt index c2fd987..fc4b04c 100644 --- a/core-ap/processor/src/test/kotlin/org/enginehub/piston/util/HelpGeneratorTest.kt +++ b/core-ap/processor/src/test/kotlin/org/enginehub/piston/util/HelpGeneratorTest.kt @@ -20,7 +20,7 @@ package org.enginehub.piston.util import com.google.common.collect.ImmutableList -import net.kyori.text.TextComponent +import net.kyori.adventure.text.Component import org.enginehub.piston.TestCommandMetadata import org.enginehub.piston.TestCommandParameters import org.enginehub.piston.TestParseResult @@ -98,7 +98,7 @@ class HelpGeneratorTest { @Test fun singleArgOptionalNotNoneHelp() { val command = listOf(newManager().newCommand("single-arg-opt") - .description(TextComponent.of("description")) + .description(Component.text("description")) .addParts( arg("piston.argument.first","First argument") { defaultsTo(ImmutableList.of("a", "b")) @@ -116,7 +116,7 @@ class HelpGeneratorTest { @Test fun flagsHelp() { val command = listOf(newManager().newCommand("flags") - .description(TextComponent.of("description")) + .description(Component.text("description")) .addParts( flag('f', "Flag"), argFlag('q', "Quibble", "qux"), @@ -138,12 +138,12 @@ class HelpGeneratorTest { @Test fun subCommandsHelp() { val subCommand = newManager().newCommand("sub-command") - .description(TextComponent.of("sub-description")) + .description(Component.text("sub-description")) .build() val interArg = arg("intermediate", "inter-arg") val subCommands = subs(subCommand) val command = newManager().newCommand("main") - .description(TextComponent.of("description")) + .description(Component.text("description")) .addParts(interArg, subCommands) .build() assertEquals(""" @@ -180,4 +180,4 @@ class HelpGeneratorTest { ).fullName)) } -} \ No newline at end of file +} diff --git a/core-ap/processor/src/test/resources/gen/CollectionArgRegistration.java b/core-ap/processor/src/test/resources/gen/CollectionArgRegistration.java index 32014ae..d4dd37e 100644 --- a/core-ap/processor/src/test/resources/gen/CollectionArgRegistration.java +++ b/core-ap/processor/src/test/resources/gen/CollectionArgRegistration.java @@ -34,8 +34,7 @@ import java.lang.Throwable; import java.lang.reflect.Method; import java.util.Collection; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.gen.CommandCallListener; @@ -53,12 +52,12 @@ final class CollectionArgRegistration implements CommandRegistration listeners; - private final CommandArgument argPart = arg(TranslatableComponent.of("piston.argument.arg"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart = arg(Component.translatable("piston.argument.arg"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(string_Key)) .build(); - private final CommandArgument argPart2 = arg(TranslatableComponent.of("piston.argument.arg"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart2 = arg(Component.translatable("piston.argument.arg"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(object_Key)) .build(); @@ -89,13 +88,13 @@ public CollectionArgRegistration listeners(Collection liste public void build() { commandManager.register("collectionArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart)); b.action(this::cmd$collectionArgument); }); commandManager.register("objectArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart2)); b.action(this::cmd$objectArgument); }); diff --git a/core-ap/processor/src/test/resources/gen/CommandValueArgRegistration.java b/core-ap/processor/src/test/resources/gen/CommandValueArgRegistration.java index ae759a1..f80879b 100644 --- a/core-ap/processor/src/test/resources/gen/CommandValueArgRegistration.java +++ b/core-ap/processor/src/test/resources/gen/CommandValueArgRegistration.java @@ -32,8 +32,8 @@ import java.lang.Throwable; import java.lang.reflect.Method; import java.util.Collection; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; + +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.CommandValue; @@ -48,7 +48,7 @@ final class CommandValueArgRegistration implements CommandRegistration listeners; - private final CommandArgument argPart = arg(TranslatableComponent.of("piston.argument.arg"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart = arg(Component.translatable("piston.argument.arg"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .build(); @@ -78,7 +78,7 @@ public CommandValueArgRegistration listeners(Collection lis public void build() { commandManager.register("valueArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart)); b.action(this::cmd$valueArgument); }); diff --git a/core-ap/processor/src/test/resources/gen/FlagsRegistration.java b/core-ap/processor/src/test/resources/gen/FlagsRegistration.java index bea4230..39feb0f 100644 --- a/core-ap/processor/src/test/resources/gen/FlagsRegistration.java +++ b/core-ap/processor/src/test/resources/gen/FlagsRegistration.java @@ -32,8 +32,7 @@ import java.lang.Throwable; import java.lang.reflect.Method; import java.util.Collection; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.gen.CommandCallListener; @@ -50,18 +49,18 @@ final class FlagsRegistration implements CommandRegistration { private ImmutableList listeners; - private final NoArgCommandFlag flagPart = flag('f', TextComponent.of("ARG DESCRIPTION")).build(); + private final NoArgCommandFlag flagPart = flag('f', Component.text("ARG DESCRIPTION")).build(); - private final ArgAcceptingCommandFlag flagPart2 = flag('f', TextComponent.of("ARG DESCRIPTION")) + private final ArgAcceptingCommandFlag flagPart2 = flag('f', Component.text("ARG DESCRIPTION")) .withRequiredArg() - .argNamed(TranslatableComponent.of("piston.argument.flag")) + .argNamed(Component.translatable("piston.argument.flag")) .defaultsTo(ImmutableList.of("DEFAULT")) .ofTypes(ImmutableList.of(string_Key)) .build(); - private final ArgAcceptingCommandFlag flagPart3 = flag('f', TextComponent.of("ARG DESCRIPTION")) + private final ArgAcceptingCommandFlag flagPart3 = flag('f', Component.text("ARG DESCRIPTION")) .withRequiredArg() - .argNamed(TranslatableComponent.of("piston.argument.ARG NAME")) + .argNamed(Component.translatable("piston.argument.ARG NAME")) .defaultsTo(ImmutableList.of("DEFAULT")) .ofTypes(ImmutableList.of(string_Key)) .build(); @@ -92,19 +91,19 @@ public FlagsRegistration listeners(Collection listeners) { public void build() { commandManager.register("booleanFlag", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(flagPart)); b.action(this::cmd$booleanFlag); }); commandManager.register("stringArgFlag", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(flagPart2)); b.action(this::cmd$stringArgFlag); }); commandManager.register("stringArgFlagCustom", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(flagPart3)); b.action(this::cmd$stringArgFlagCustom); }); @@ -166,4 +165,4 @@ public void build() { private String extract$flag3(CommandParameters parameters) { return flagPart3.value(parameters).asSingle(string_Key); } -} \ No newline at end of file +} diff --git a/core-ap/processor/src/test/resources/gen/IntArgRegistration.java b/core-ap/processor/src/test/resources/gen/IntArgRegistration.java index e1b247d..f1b3d94 100644 --- a/core-ap/processor/src/test/resources/gen/IntArgRegistration.java +++ b/core-ap/processor/src/test/resources/gen/IntArgRegistration.java @@ -37,8 +37,7 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.List; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.gen.CommandCallListener; @@ -77,27 +76,27 @@ Annotation a(@InjectDelta(qux = 45, baz = 32, thq = { 10, 99 }) Object ah) { private ImmutableList listeners; - private final CommandArgument argPart = arg(TranslatableComponent.of("piston.argument.arg"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart = arg(Component.translatable("piston.argument.arg"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(integer_Key)) .build(); - private final CommandArgument argPart2 = arg(TranslatableComponent.of("piston.argument.arg"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart2 = arg(Component.translatable("piston.argument.arg"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(integer_injectGamma_something_to_match__Key)) .build(); - private final CommandArgument deltaPart = arg(TranslatableComponent.of("piston.argument.delta"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument deltaPart = arg(Component.translatable("piston.argument.delta"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(integer_injectDeltaQux45$Baz32$Thq1099_Key)) .build(); - private final CommandArgument alphaPart = arg(TranslatableComponent.of("piston.argument.alpha"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument alphaPart = arg(Component.translatable("piston.argument.alpha"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(integer_injectAlpha_Key)) .build(); - private final CommandArgument argPart3 = arg(TranslatableComponent.of("piston.argument.args"), TextComponent.of("ARG DESCRIPTION")) + private final CommandArgument argPart3 = arg(Component.translatable("piston.argument.args"), Component.text("ARG DESCRIPTION")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(integer_Key)) .variable(true) @@ -129,31 +128,31 @@ public IntArgRegistration listeners(Collection listeners) { public void build() { commandManager.register("intArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart)); b.action(this::cmd$intArgument); }); commandManager.register("annotatedIntArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart2)); b.action(this::cmd$annotatedIntArgument); }); commandManager.register("annotatedIntArgument2", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(deltaPart)); b.action(this::cmd$annotatedIntArgument2); }); commandManager.register("annotatedIntArgument3", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(alphaPart)); b.action(this::cmd$annotatedIntArgument3); }); commandManager.register("variableIntArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of(argPart3)); b.action(this::cmd$variableIntArgument); }); diff --git a/core-ap/processor/src/test/resources/gen/NoArgRegistration.java b/core-ap/processor/src/test/resources/gen/NoArgRegistration.java index c2d8ea8..5253d1e 100644 --- a/core-ap/processor/src/test/resources/gen/NoArgRegistration.java +++ b/core-ap/processor/src/test/resources/gen/NoArgRegistration.java @@ -32,7 +32,7 @@ import java.lang.Throwable; import java.lang.reflect.Method; import java.util.Collection; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; @@ -81,20 +81,20 @@ public NoArgRegistration listeners(Collection listeners) { public void build() { commandManager.register("noArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$noArgument); }); commandManager.register("noArgumentFooter", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); - b.footer(TextComponent.of("DESC FOOTER")); + b.description(Component.text("DESCRIPTION")); + b.footer(Component.text("DESC FOOTER")); b.parts(ImmutableList.of()); b.action(this::cmd$noArgumentFooter); }); commandManager.register("noArgumentCondition", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$noArgumentCondition); Method commandMethod = getCommandMethod(NoArg.class, "noArgCondition"); @@ -103,7 +103,7 @@ public void build() { }); commandManager.register("noArgumentStatic", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$noArgumentStatic); }); diff --git a/core-ap/processor/src/test/resources/gen/NonArgParametersRegistration.java b/core-ap/processor/src/test/resources/gen/NonArgParametersRegistration.java index 44674f6..ab09ec9 100644 --- a/core-ap/processor/src/test/resources/gen/NonArgParametersRegistration.java +++ b/core-ap/processor/src/test/resources/gen/NonArgParametersRegistration.java @@ -34,7 +34,7 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.concurrent.Callable; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.gen.CommandCallListener; @@ -77,13 +77,13 @@ public NonArgParametersRegistration listeners(Collection li public void build() { commandManager.register("nonArgCommandParameters", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$nonArgCommandParameters); }); commandManager.register("nonArgInjected", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$nonArgInjected); }); @@ -126,4 +126,4 @@ public void build() { private Callable extract$injected(CommandParameters parameters) { return requireOptional(callable$Object_Key, "injected", parameters.injectedValue(callable$Object_Key)); } -} \ No newline at end of file +} diff --git a/core-ap/processor/src/test/resources/gen/Outer_BasicNestedRegistration.java b/core-ap/processor/src/test/resources/gen/Outer_BasicNestedRegistration.java index 2dcfc6b..52372c4 100644 --- a/core-ap/processor/src/test/resources/gen/Outer_BasicNestedRegistration.java +++ b/core-ap/processor/src/test/resources/gen/Outer_BasicNestedRegistration.java @@ -32,7 +32,7 @@ import java.lang.Throwable; import java.lang.reflect.Method; import java.util.Collection; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.gen.CommandCallListener; @@ -71,7 +71,7 @@ public Outer_BasicNestedRegistration listeners(Collection l public void build() { commandManager.register("noArgument", b -> { b.aliases(ImmutableList.of()); - b.description(TextComponent.of("DESCRIPTION")); + b.description(Component.text("DESCRIPTION")); b.parts(ImmutableList.of()); b.action(this::cmd$noArgument); }); diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 3609940..d688eea 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -2,9 +2,9 @@ applyCommonConfig() dependencies { "api"(Libs.guava) - "api"(Libs.kyoriText) + "api"(Libs.kyoriAdventure) "api"(Libs.javaxAnnotations) - "implementation"(Libs.kyoriTextPlain) + "implementation"(Libs.kyoriAdventureTextPlain) "compileOnly"(Libs.autoValueAnnotations) "annotationProcessor"(Libs.autoValueProcessor) "testImplementation"(Libs.mockito) diff --git a/core/src/main/java/org/enginehub/piston/Command.java b/core/src/main/java/org/enginehub/piston/Command.java index 3bbad75..24c4d78 100644 --- a/core/src/main/java/org/enginehub/piston/Command.java +++ b/core/src/main/java/org/enginehub/piston/Command.java @@ -20,7 +20,7 @@ package org.enginehub.piston; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.part.CommandPart; import org.enginehub.piston.suggestion.SuggestionProvider; diff --git a/core/src/main/java/org/enginehub/piston/config/ColorConfig.java b/core/src/main/java/org/enginehub/piston/config/ColorConfig.java index 6b33c0e..65062df 100644 --- a/core/src/main/java/org/enginehub/piston/config/ColorConfig.java +++ b/core/src/main/java/org/enginehub/piston/config/ColorConfig.java @@ -20,11 +20,12 @@ package org.enginehub.piston.config; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; -import net.kyori.text.format.Style; -import net.kyori.text.format.TextColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.Style; +import net.kyori.adventure.text.format.TextColor; import javax.annotation.Nullable; import java.util.Arrays; @@ -37,13 +38,13 @@ public class ColorConfig extends Config { private static final ColorConfig TEXT_MODIFIER = - new ColorConfig("piston.style.text.modifier", TextColor.YELLOW); + new ColorConfig("piston.style.text.modifier", NamedTextColor.YELLOW); private static final ColorConfig MAIN_TEXT = - new ColorConfig("piston.style.main.text", TextColor.GOLD); + new ColorConfig("piston.style.main.text", NamedTextColor.GOLD); private static final ColorConfig HELP_TEXT = - new ColorConfig("piston.style.help.text", TextColor.GRAY); + new ColorConfig("piston.style.help.text", NamedTextColor.GRAY); private static final ColorConfig PART_WRAPPING = - new ColorConfig("piston.style.part.wrapping", TextColor.YELLOW); + new ColorConfig("piston.style.part.wrapping", NamedTextColor.YELLOW); private static final Set MERGE_NO_COLOR = Style.Merge.of( Style.Merge.DECORATIONS, Style.Merge.INSERTION, Style.Merge.EVENTS @@ -93,7 +94,7 @@ public ColorConfig value(@Nullable TextColor value) { } public Component wrap(String text) { - return wrap(ImmutableList.of(TextComponent.of(text))); + return wrap(ImmutableList.of(Component.text(text))); } public Component wrap(Component... args) { @@ -116,7 +117,7 @@ private TextComponent.Builder renderFromArgs(List args) { TextColor color = getValue(); switch (args.size()) { case 0: - return TextComponent.builder("", color); + return Component.text().color(color); case 1: Component only = args.get(0); if (only instanceof TextComponent) { @@ -124,7 +125,7 @@ private TextComponent.Builder renderFromArgs(List args) { } // fall-through default: - return TextComponent.builder() + return Component.text() .color(color) .append(args); } diff --git a/core/src/main/java/org/enginehub/piston/config/Config.java b/core/src/main/java/org/enginehub/piston/config/Config.java index 65dd85f..f716ce2 100644 --- a/core/src/main/java/org/enginehub/piston/config/Config.java +++ b/core/src/main/java/org/enginehub/piston/config/Config.java @@ -20,8 +20,8 @@ package org.enginehub.piston.config; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; import javax.annotation.Nullable; import java.util.List; @@ -76,7 +76,7 @@ public Component value() { } protected Component wrapInternal(List args) { - return TranslatableComponent.of(key, args); + return Component.translatable(key, args); } protected abstract Component apply(TranslatableComponent placeholder); diff --git a/core/src/main/java/org/enginehub/piston/config/ConfigHolder.java b/core/src/main/java/org/enginehub/piston/config/ConfigHolder.java index 85e0d00..68577da 100644 --- a/core/src/main/java/org/enginehub/piston/config/ConfigHolder.java +++ b/core/src/main/java/org/enginehub/piston/config/ConfigHolder.java @@ -19,7 +19,7 @@ package org.enginehub.piston.config; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import java.util.HashMap; import java.util.Map; diff --git a/core/src/main/java/org/enginehub/piston/config/ConfigRenderer.java b/core/src/main/java/org/enginehub/piston/config/ConfigRenderer.java index 11f4b7f..d63601d 100644 --- a/core/src/main/java/org/enginehub/piston/config/ConfigRenderer.java +++ b/core/src/main/java/org/enginehub/piston/config/ConfigRenderer.java @@ -20,10 +20,10 @@ package org.enginehub.piston.config; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TranslatableComponent; -import net.kyori.text.renderer.ComponentRenderer; -import org.checkerframework.checker.nullness.qual.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.renderer.ComponentRenderer; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -45,7 +45,7 @@ private ConfigRenderer() { } @Override - public @NonNull Component render(@NonNull Component component, @NonNull ConfigHolder context) { + public @NotNull Component render(@NotNull Component component, @NotNull ConfigHolder context) { component = replaceSubcomponents(component, context); if (component instanceof TranslatableComponent) { // check if replacing diff --git a/core/src/main/java/org/enginehub/piston/config/TextConfig.java b/core/src/main/java/org/enginehub/piston/config/TextConfig.java index 3aa77b0..dfc85db 100644 --- a/core/src/main/java/org/enginehub/piston/config/TextConfig.java +++ b/core/src/main/java/org/enginehub/piston/config/TextConfig.java @@ -19,9 +19,9 @@ package org.enginehub.piston.config; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import com.google.common.base.Strings; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; import javax.annotation.Nullable; @@ -69,7 +69,8 @@ protected void checkValue(@Nullable String value) { @Override protected Component apply(TranslatableComponent placeholder) { checkState(placeholder.args().isEmpty(), "TextConfig takes no arguments"); - return TextComponent.builder(getValue()) + return Component.text() + .content(Strings.nullToEmpty(getValue())) .mergeStyle(placeholder) .append(placeholder.children()) .build(); diff --git a/core/src/main/java/org/enginehub/piston/converter/ArgumentConverter.java b/core/src/main/java/org/enginehub/piston/converter/ArgumentConverter.java index cd08618..7d5b734 100644 --- a/core/src/main/java/org/enginehub/piston/converter/ArgumentConverter.java +++ b/core/src/main/java/org/enginehub/piston/converter/ArgumentConverter.java @@ -19,7 +19,7 @@ package org.enginehub.piston.converter; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.inject.InjectedValueAccess; import java.util.Collections; diff --git a/core/src/main/java/org/enginehub/piston/converter/ForwardingArgumentConverter.java b/core/src/main/java/org/enginehub/piston/converter/ForwardingArgumentConverter.java index d7dcb58..b03e0d5 100644 --- a/core/src/main/java/org/enginehub/piston/converter/ForwardingArgumentConverter.java +++ b/core/src/main/java/org/enginehub/piston/converter/ForwardingArgumentConverter.java @@ -19,7 +19,7 @@ package org.enginehub.piston.converter; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.inject.InjectedValueAccess; import java.util.List; diff --git a/core/src/main/java/org/enginehub/piston/converter/MapArgumentConverter.java b/core/src/main/java/org/enginehub/piston/converter/MapArgumentConverter.java index 9adfec3..2bbde21 100644 --- a/core/src/main/java/org/enginehub/piston/converter/MapArgumentConverter.java +++ b/core/src/main/java/org/enginehub/piston/converter/MapArgumentConverter.java @@ -20,7 +20,7 @@ package org.enginehub.piston.converter; import com.google.common.collect.ImmutableMap; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.config.ColorConfig; import org.enginehub.piston.inject.InjectedValueAccess; diff --git a/core/src/main/java/org/enginehub/piston/converter/MultiKeyConverter.java b/core/src/main/java/org/enginehub/piston/converter/MultiKeyConverter.java index 9468785..49ce8dc 100644 --- a/core/src/main/java/org/enginehub/piston/converter/MultiKeyConverter.java +++ b/core/src/main/java/org/enginehub/piston/converter/MultiKeyConverter.java @@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.config.ColorConfig; import org.enginehub.piston.inject.InjectedValueAccess; diff --git a/core/src/main/java/org/enginehub/piston/converter/SimpleArgumentConverter.java b/core/src/main/java/org/enginehub/piston/converter/SimpleArgumentConverter.java index 7ba79f2..0d619b8 100644 --- a/core/src/main/java/org/enginehub/piston/converter/SimpleArgumentConverter.java +++ b/core/src/main/java/org/enginehub/piston/converter/SimpleArgumentConverter.java @@ -19,8 +19,7 @@ package org.enginehub.piston.converter; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.inject.InjectedValueAccess; import java.util.List; @@ -32,7 +31,7 @@ public class SimpleArgumentConverter implements ArgumentConverter { public static SimpleArgumentConverter from(Converter converter, String description) { - return from(converter, TextComponent.of(description)); + return from(converter, Component.text(description)); } /** diff --git a/core/src/main/java/org/enginehub/piston/exception/CommandException.java b/core/src/main/java/org/enginehub/piston/exception/CommandException.java index 289cd50..d96c670 100644 --- a/core/src/main/java/org/enginehub/piston/exception/CommandException.java +++ b/core/src/main/java/org/enginehub/piston/exception/CommandException.java @@ -20,8 +20,7 @@ package org.enginehub.piston.exception; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; import org.enginehub.piston.util.TextHelper; @@ -33,7 +32,7 @@ public class CommandException extends RuntimeException { protected final ImmutableList commands; public CommandException(ImmutableList commands) { - this.message = TextComponent.empty(); + this.message = Component.empty(); this.commands = commands; } @@ -51,7 +50,7 @@ public CommandException(Component message, Throwable cause, ImmutableList commands) { super(cause); - this.message = TextComponent.empty(); + this.message = Component.empty(); this.commands = commands; } diff --git a/core/src/main/java/org/enginehub/piston/exception/ConditionFailedException.java b/core/src/main/java/org/enginehub/piston/exception/ConditionFailedException.java index a0dbac1..26a1b80 100644 --- a/core/src/main/java/org/enginehub/piston/exception/ConditionFailedException.java +++ b/core/src/main/java/org/enginehub/piston/exception/ConditionFailedException.java @@ -21,13 +21,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; public class ConditionFailedException extends CommandException { public ConditionFailedException(ImmutableList commands) { - super(TextComponent.of("Condition failed: " + Iterables.getLast(commands).getCondition()), + super(Component.text("Condition failed: " + Iterables.getLast(commands).getCondition()), commands); } diff --git a/core/src/main/java/org/enginehub/piston/exception/ConversionFailedException.java b/core/src/main/java/org/enginehub/piston/exception/ConversionFailedException.java index cbf47ff..abc3018 100644 --- a/core/src/main/java/org/enginehub/piston/exception/ConversionFailedException.java +++ b/core/src/main/java/org/enginehub/piston/exception/ConversionFailedException.java @@ -19,8 +19,8 @@ package org.enginehub.piston.exception; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.enginehub.piston.CommandParseResult; import org.enginehub.piston.CommandValue; import org.enginehub.piston.converter.ArgumentConverter; @@ -36,14 +36,14 @@ public class ConversionFailedException extends UsageException { private static Component getMessage(Component conversionTarget, ArgumentConverter converter, FailedConversion conversion) { - TextComponent.Builder builder = TextComponent.builder("") - .append(TextComponent.of("Invalid value for ")) + TextComponent.Builder builder = Component.text() + .append(Component.text("Invalid value for ")) .append(conversionTarget); if (conversion.getError().getMessage() != null) { - builder.append(TextComponent.of(" (" + conversion.getError().getMessage() + ")")); + builder.append(Component.text(" (" + conversion.getError().getMessage() + ")")); } return builder - .append(TextComponent.of(", acceptable values are ")) + .append(Component.text(", acceptable values are ")) .append(converter.describeAcceptableArguments()) .build(); } diff --git a/core/src/main/java/org/enginehub/piston/exception/NoSuchCommandException.java b/core/src/main/java/org/enginehub/piston/exception/NoSuchCommandException.java index 8a00bfe..fd492ba 100644 --- a/core/src/main/java/org/enginehub/piston/exception/NoSuchCommandException.java +++ b/core/src/main/java/org/enginehub/piston/exception/NoSuchCommandException.java @@ -20,14 +20,14 @@ package org.enginehub.piston.exception; import com.google.common.collect.ImmutableList; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; public class NoSuchCommandException extends CommandException { private final String requestedCommand; public NoSuchCommandException(String requestedCommand) { - super(TextComponent.of("No such command: " + requestedCommand), ImmutableList.of()); + super(Component.text("No such command: " + requestedCommand), ImmutableList.of()); this.requestedCommand = requestedCommand; } diff --git a/core/src/main/java/org/enginehub/piston/exception/NoSuchFlagException.java b/core/src/main/java/org/enginehub/piston/exception/NoSuchFlagException.java index b5d0fe0..111f667 100644 --- a/core/src/main/java/org/enginehub/piston/exception/NoSuchFlagException.java +++ b/core/src/main/java/org/enginehub/piston/exception/NoSuchFlagException.java @@ -21,8 +21,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParseResult; import org.enginehub.piston.config.ColorConfig; @@ -41,16 +41,16 @@ private static String getAllFlags(ImmutableList commands) { } private static Component getMessage(CommandParseResult parseResult, char requestedFlag) { - TextComponent.Builder message = TextComponent.builder(""); - message.append(TextComponent.of("Flag '")) + TextComponent.Builder message = Component.text(); + message.append(Component.text("Flag '")) .append(ColorConfig.mainText().wrap(String.valueOf(requestedFlag))) - .append(TextComponent.of("' is not a valid flag for ")); + .append(Component.text("' is not a valid flag for ")); message.append(HelpGenerator.create(parseResult).getFullName()); String allFlags = getAllFlags(parseResult.getExecutionPath()); if (allFlags.isEmpty()) { - message.append(TextComponent.of(", as it does not have any flags")); + message.append(Component.text(", as it does not have any flags")); } else { - message.append(TextComponent.of(". Options: ")) + message.append(Component.text(". Options: ")) .append(ColorConfig.mainText().wrap(allFlags)); } return message.build(); diff --git a/core/src/main/java/org/enginehub/piston/exception/StopExecutionException.java b/core/src/main/java/org/enginehub/piston/exception/StopExecutionException.java index 6ac59ab..1ee873d 100644 --- a/core/src/main/java/org/enginehub/piston/exception/StopExecutionException.java +++ b/core/src/main/java/org/enginehub/piston/exception/StopExecutionException.java @@ -20,7 +20,7 @@ package org.enginehub.piston.exception; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; /** diff --git a/core/src/main/java/org/enginehub/piston/exception/UsageException.java b/core/src/main/java/org/enginehub/piston/exception/UsageException.java index 698c59e..cf7bd65 100644 --- a/core/src/main/java/org/enginehub/piston/exception/UsageException.java +++ b/core/src/main/java/org/enginehub/piston/exception/UsageException.java @@ -19,7 +19,7 @@ package org.enginehub.piston.exception; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandParseResult; /** diff --git a/core/src/main/java/org/enginehub/piston/part/ArgAcceptingCommandFlag.java b/core/src/main/java/org/enginehub/piston/part/ArgAcceptingCommandFlag.java index 2e068c4..5495ca5 100644 --- a/core/src/main/java/org/enginehub/piston/part/ArgAcceptingCommandFlag.java +++ b/core/src/main/java/org/enginehub/piston/part/ArgAcceptingCommandFlag.java @@ -21,9 +21,8 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; import org.enginehub.piston.config.ColorConfig; import org.enginehub.piston.inject.Key; @@ -50,7 +49,7 @@ public final Builder named(char name) { abstract Builder name(char name); public final Builder describedBy(String description) { - return describedBy(TextComponent.of(description)); + return describedBy(Component.text(description)); } public final Builder describedBy(Component description) { @@ -72,7 +71,7 @@ public final Builder ofTypes(Collection> types) { abstract Builder types(Collection> types); public final Builder argNamed(String name) { - return argNamed(TranslatableComponent.of(name)); + return argNamed(Component.translatable(name)); } public final Builder argNamed(TranslatableComponent name) { @@ -90,13 +89,13 @@ public final Builder argNamed(TranslatableComponent name) { @Override public Component getTextRepresentation() { return ColorConfig.partWrapping().wrap( - TextComponent.of("["), + Component.text("["), ColorConfig.mainText().wrap("-" + getName()), - TextComponent.space(), - TextComponent.of("<"), + Component.space(), + Component.text("<"), ColorConfig.mainText().wrap(getArgumentName()), - TextComponent.of(">"), - TextComponent.of("]") + Component.text(">"), + Component.text("]") ); } } diff --git a/core/src/main/java/org/enginehub/piston/part/ArgConsumingCommandPart.java b/core/src/main/java/org/enginehub/piston/part/ArgConsumingCommandPart.java index 72a17c0..36e93c3 100644 --- a/core/src/main/java/org/enginehub/piston/part/ArgConsumingCommandPart.java +++ b/core/src/main/java/org/enginehub/piston/part/ArgConsumingCommandPart.java @@ -19,7 +19,7 @@ package org.enginehub.piston.part; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.TranslatableComponent; /** * Marker interface for parts that consume arguments directly from the line, diff --git a/core/src/main/java/org/enginehub/piston/part/CommandArgument.java b/core/src/main/java/org/enginehub/piston/part/CommandArgument.java index 62d02ab..5c94ecb 100644 --- a/core/src/main/java/org/enginehub/piston/part/CommandArgument.java +++ b/core/src/main/java/org/enginehub/piston/part/CommandArgument.java @@ -22,9 +22,8 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; import org.enginehub.piston.config.ColorConfig; import org.enginehub.piston.inject.Key; @@ -46,7 +45,7 @@ public static Builder builder(TranslatableComponent name, Component description) public abstract static class Builder { public final Builder named(String name) { - return named(TranslatableComponent.of(name)); + return named(Component.translatable(name)); } public final Builder named(TranslatableComponent name) { @@ -56,7 +55,7 @@ public final Builder named(TranslatableComponent name) { abstract Builder argumentName(TranslatableComponent name); public final Builder describedBy(String description) { - return describedBy(TextComponent.of(description)); + return describedBy(Component.text(description)); } public final Builder describedBy(Component description) { @@ -105,12 +104,12 @@ public final boolean isRequired() { @Override public Component getTextRepresentation() { ImmutableList.Builder builder = ImmutableList.builder(); - builder.add(TextComponent.of(isRequired() ? "<" : "[")); + builder.add(Component.text(isRequired() ? "<" : "[")); builder.add(ColorConfig.mainText().wrap(getArgumentName())); if (isVariable()) { builder.add(ColorConfig.textModifier().wrap("...")); } - builder.add(TextComponent.of(isRequired() ? ">" : "]")); + builder.add(Component.text(isRequired() ? ">" : "]")); return ColorConfig.partWrapping().wrap(builder.build()); } diff --git a/core/src/main/java/org/enginehub/piston/part/CommandPart.java b/core/src/main/java/org/enginehub/piston/part/CommandPart.java index 26685d3..12d2420 100644 --- a/core/src/main/java/org/enginehub/piston/part/CommandPart.java +++ b/core/src/main/java/org/enginehub/piston/part/CommandPart.java @@ -19,7 +19,7 @@ package org.enginehub.piston.part; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import org.enginehub.piston.CommandParameters; /** diff --git a/core/src/main/java/org/enginehub/piston/part/CommandParts.java b/core/src/main/java/org/enginehub/piston/part/CommandParts.java index 313ccdb..eca7a49 100644 --- a/core/src/main/java/org/enginehub/piston/part/CommandParts.java +++ b/core/src/main/java/org/enginehub/piston/part/CommandParts.java @@ -19,8 +19,8 @@ package org.enginehub.piston.part; -import net.kyori.text.Component; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; public class CommandParts { diff --git a/core/src/main/java/org/enginehub/piston/part/NoArgCommandFlag.java b/core/src/main/java/org/enginehub/piston/part/NoArgCommandFlag.java index c836509..24a1c60 100644 --- a/core/src/main/java/org/enginehub/piston/part/NoArgCommandFlag.java +++ b/core/src/main/java/org/enginehub/piston/part/NoArgCommandFlag.java @@ -20,8 +20,7 @@ package org.enginehub.piston.part; import com.google.auto.value.AutoValue; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.config.ColorConfig; @AutoValue @@ -29,7 +28,7 @@ public abstract class NoArgCommandFlag implements CommandFlag { public static NoArgCommandFlag.Builder builder(char name, String description) { - return builder(name, TextComponent.of(description)); + return builder(name, Component.text(description)); } public static NoArgCommandFlag.Builder builder(char name, @@ -49,7 +48,7 @@ public final Builder named(char name) { abstract Builder name(char name); public final Builder describedBy(String description) { - return describedBy(TextComponent.of(description)); + return describedBy(Component.text(description)); } public final Builder describedBy(Component description) { @@ -76,9 +75,9 @@ public final ArgAcceptingCommandFlag.Builder withRequiredArg() { @Override public Component getTextRepresentation() { return ColorConfig.partWrapping().wrap( - TextComponent.of("["), + Component.text("["), ColorConfig.mainText().wrap("-" + getName()), - TextComponent.of("]") + Component.text("]") ); } } diff --git a/core/src/main/java/org/enginehub/piston/part/SubCommandPart.java b/core/src/main/java/org/enginehub/piston/part/SubCommandPart.java index 3c119c7..478e9ec 100644 --- a/core/src/main/java/org/enginehub/piston/part/SubCommandPart.java +++ b/core/src/main/java/org/enginehub/piston/part/SubCommandPart.java @@ -21,9 +21,8 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; import org.enginehub.piston.Command; import org.enginehub.piston.config.ColorConfig; @@ -50,7 +49,7 @@ public final Builder named(TranslatableComponent name) { abstract Builder argumentName(TranslatableComponent name); public final Builder describedBy(String description) { - return describedBy(TextComponent.of(description)); + return describedBy(Component.text(description)); } public final Builder describedBy(Component description) { @@ -83,13 +82,13 @@ public final Builder optional() { @Override public Component getTextRepresentation() { ImmutableList.Builder builder = ImmutableList.builder(); - builder.add(TextComponent.of(isRequired() ? "<" : "[")); + builder.add(Component.text(isRequired() ? "<" : "[")); builder.addAll(getCommands().stream() .map(Command::getName) .map(ColorConfig.mainText()::wrap) .collect(joiningWithBar()) .children()); - builder.add(TextComponent.of(isRequired() ? ">" : "]")); + builder.add(Component.text(isRequired() ? ">" : "]")); return ColorConfig.partWrapping().wrap(builder.build()); } diff --git a/core/src/main/java/org/enginehub/piston/util/ComponentHelper.java b/core/src/main/java/org/enginehub/piston/util/ComponentHelper.java index c35c3be..ff3fab1 100644 --- a/core/src/main/java/org/enginehub/piston/util/ComponentHelper.java +++ b/core/src/main/java/org/enginehub/piston/util/ComponentHelper.java @@ -19,8 +19,8 @@ package org.enginehub.piston.util; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.enginehub.piston.config.ColorConfig; import javax.annotation.Nullable; @@ -34,9 +34,9 @@ public class ComponentHelper { */ public static Collector joiningWithBar() { return joiningTexts( - TextComponent.empty(), + Component.empty(), ColorConfig.partWrapping().wrap("|"), - TextComponent.empty() + Component.empty() ); } @@ -69,7 +69,7 @@ private ComponentJoiner(Component prefix, Component delimiter, Component suffix) private TextComponent.Builder initBuilder() { if (value == null) { - value = TextComponent.builder(""); + value = Component.text(); } else { value.append(delimiter); } @@ -94,7 +94,7 @@ public Component finish() { } return initBuilder().append(prefix).append(suffix).build(); } - return TextComponent.builder("") + return Component.text() .append(prefix) .append(value.build().children()) .append(suffix) diff --git a/core/src/main/java/org/enginehub/piston/util/HelpGenerator.java b/core/src/main/java/org/enginehub/piston/util/HelpGenerator.java index 3eb874b..af356c6 100644 --- a/core/src/main/java/org/enginehub/piston/util/HelpGenerator.java +++ b/core/src/main/java/org/enginehub/piston/util/HelpGenerator.java @@ -20,8 +20,8 @@ package org.enginehub.piston.util; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.enginehub.piston.ArgBinding; import org.enginehub.piston.Command; import org.enginehub.piston.CommandMetadata; @@ -42,9 +42,6 @@ import java.util.List; import java.util.stream.Collectors; -import static net.kyori.text.TextComponent.newline; -import static net.kyori.text.TextComponent.space; - public class HelpGenerator { public static HelpGenerator create(Iterable commands) { @@ -83,7 +80,7 @@ private HelpGenerator(CommandParseResult parseResult) { * Generate a name for the set of commands as a whole. */ public Component getFullName() { - TextComponent.Builder usage = TextComponent.builder(); + TextComponent.Builder usage = Component.text(); String name = parseResult.getExecutionPath().get(0).getName(); CommandMetadata metadata = parseResult.getParameters().getMetadata(); @@ -92,11 +89,11 @@ public Component getFullName() { } usage.append(ColorConfig.mainText().wrap( TextConfig.commandPrefixValue(), - TextComponent.of(name) + Component.text(name) )); for (String input : parseResult.getOriginalArguments()) { - usage.append(space()); + usage.append(Component.space()); usage.append(ColorConfig.mainText().wrap(input)); } @@ -107,7 +104,7 @@ public Component getFullName() { * Generate a usage help text. */ public Component getUsage() { - TextComponent.Builder usage = TextComponent.builder() + TextComponent.Builder usage = Component.text() .append(ColorConfig.mainText().wrap( TextConfig.commandPrefixValue() )); @@ -138,12 +135,12 @@ public Component getUsage() { } // append a space before parts, if needed if (!reducedParts.isEmpty()) { - usage.append(space()); + usage.append(Component.space()); } PartHelper.appendUsage(reducedParts.stream(), usage); // append a space after parts/command, if needed if (iterator.hasNext()) { - usage.append(space()); + usage.append(Component.space()); } } @@ -156,7 +153,7 @@ public Component getFullHelp() { builder.add(primary.getDescription()); - builder.add(TextComponent.of("\nUsage: ")); + builder.add(Component.text("\nUsage: ")); builder.add(getUsage()); @@ -164,7 +161,7 @@ public Component getFullHelp() { appendFlags(builder); - primary.getFooter().ifPresent(footer -> builder.add(newline()).add(footer)); + primary.getFooter().ifPresent(footer -> builder.add(Component.newline()).add(footer)); return ColorConfig.helpText().wrap(builder.build()); } @@ -176,16 +173,16 @@ private void appendArguments(ImmutableList.Builder builder) { .map(x -> (CommandArgument) x) .collect(Collectors.toList()); if (args.size() > 0) { - builder.add(newline()); - builder.add(TextComponent.of("Arguments:\n")); + builder.add(Component.newline()); + builder.add(Component.text("Arguments:\n")); for (Iterator iterator = args.iterator(); iterator.hasNext(); ) { CommandArgument arg = iterator.next(); - builder.add(TextComponent.of(" ")).add(arg.getTextRepresentation()); + builder.add(Component.text(" ")).add(arg.getTextRepresentation()); addDefaultInfo(builder, arg); - builder.add(TextComponent.of(": ")) + builder.add(Component.text(": ")) .add(arg.getDescription()); if (iterator.hasNext()) { - builder.add(newline()); + builder.add(Component.newline()); } } } @@ -198,8 +195,8 @@ private void appendFlags(ImmutableList.Builder builder) { .map(x -> (CommandFlag) x) .collect(Collectors.toList()); if (flags.size() > 0) { - builder.add(newline()); - builder.add(TextComponent.of("Flags:\n")); + builder.add(Component.newline()); + builder.add(Component.text("Flags:\n")); for (Iterator iterator = flags.iterator(); iterator.hasNext(); ) { CommandFlag flag = iterator.next(); // produces text like "-f: Some description" @@ -207,10 +204,10 @@ private void appendFlags(ImmutableList.Builder builder) { if (flag instanceof ArgAcceptingCommandFlag) { addDefaultInfo(builder, (ArgAcceptingCommandFlag) flag); } - builder.add(TextComponent.of(": ")) + builder.add(Component.text(": ")) .add(flag.getDescription()); if (iterator.hasNext()) { - builder.add(newline()); + builder.add(Component.newline()); } } } @@ -220,7 +217,7 @@ private void addDefaultInfo(ImmutableList.Builder builder, ArgAccepti if (arg.getDefaults().isEmpty()) { return; } - builder.add(TextComponent.of(" (defaults to ")); + builder.add(Component.text(" (defaults to ")); String value; if (arg.getDefaults().size() == 1) { value = arg.getDefaults().get(0); @@ -232,8 +229,8 @@ private void addDefaultInfo(ImmutableList.Builder builder, ArgAccepti .filter(s -> s.trim().length() > 0) .collect(Collectors.joining(", ", "[", "]")); } - builder.add(TextComponent.of(value)); - builder.add(TextComponent.of(")")); + builder.add(Component.text(value)); + builder.add(Component.text(")")); } } diff --git a/core/src/main/java/org/enginehub/piston/util/PartHelper.java b/core/src/main/java/org/enginehub/piston/util/PartHelper.java index ff2235a..70d70e1 100644 --- a/core/src/main/java/org/enginehub/piston/util/PartHelper.java +++ b/core/src/main/java/org/enginehub/piston/util/PartHelper.java @@ -19,8 +19,8 @@ package org.enginehub.piston.util; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.enginehub.piston.Command; import org.enginehub.piston.config.ColorConfig; import org.enginehub.piston.part.CommandPart; @@ -74,9 +74,9 @@ public static void appendUsage(Stream parts, TextComponent.Builder .map(String::valueOf) .collect(Collectors.joining(""))) .map(text -> ColorConfig.partWrapping().wrap( - TextComponent.of("["), + Component.text("["), ColorConfig.mainText().wrap("-" + text), - TextComponent.of("]") + Component.text("]") )) .map(Stream::of).orElse(Stream.empty()); @@ -88,7 +88,7 @@ public static void appendUsage(Stream parts, TextComponent.Builder while (usages.hasNext()) { output.append(usages.next()); if (usages.hasNext()) { - output.append(TextComponent.of(" ")); + output.append(Component.text(" ")); } } } @@ -96,18 +96,18 @@ public static void appendUsage(Stream parts, TextComponent.Builder private static Stream buildOptionalMerging(SubCommandPart optionalSubCommand, Stream postComponents) { return Stream.of(ColorConfig.partWrapping().wrap( - TextComponent.of("<"), + Component.text("<"), optionalSubCommand.getCommands().stream() .map(Command::getName) .map(ColorConfig.mainText()::wrap) .collect(ComponentHelper.joiningWithBar()), - TextComponent.of("|"), + Component.text("|"), postComponents.collect(ComponentHelper.joiningTexts( - TextComponent.empty(), - TextComponent.of(" "), - TextComponent.empty() + Component.empty(), + Component.text(" "), + Component.empty() )), - TextComponent.of(">") + Component.text(">") )); } diff --git a/core/src/main/java/org/enginehub/piston/util/TextHelper.java b/core/src/main/java/org/enginehub/piston/util/TextHelper.java index fbeacf5..aa5a567 100644 --- a/core/src/main/java/org/enginehub/piston/util/TextHelper.java +++ b/core/src/main/java/org/enginehub/piston/util/TextHelper.java @@ -20,10 +20,10 @@ package org.enginehub.piston.util; import com.google.common.base.Joiner; -import net.kyori.text.Component; -import net.kyori.text.KeybindComponent; -import net.kyori.text.TranslatableComponent; -import net.kyori.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.KeybindComponent; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import org.enginehub.piston.config.ConfigHolder; import org.enginehub.piston.config.ConfigRenderer; diff --git a/core/src/test/java/org/enginehub/piston/ConditionTest.java b/core/src/test/java/org/enginehub/piston/ConditionTest.java index 05464d3..855ed29 100644 --- a/core/src/test/java/org/enginehub/piston/ConditionTest.java +++ b/core/src/test/java/org/enginehub/piston/ConditionTest.java @@ -19,7 +19,6 @@ package org.enginehub.piston; -import org.enginehub.piston.inject.InjectedValueAccess; import org.junit.jupiter.api.Test; import static org.enginehub.piston.Command.Condition.FALSE; diff --git a/core/src/test/java/org/enginehub/piston/config/ConfigHolderTest.java b/core/src/test/java/org/enginehub/piston/config/ConfigHolderTest.java index 9b958c6..e0992f5 100644 --- a/core/src/test/java/org/enginehub/piston/config/ConfigHolderTest.java +++ b/core/src/test/java/org/enginehub/piston/config/ConfigHolderTest.java @@ -20,10 +20,9 @@ package org.enginehub.piston.config; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; -import net.kyori.text.format.TextColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicNode; @@ -54,7 +53,7 @@ private TestCase(String name, Component input, Component expected) { private final ConfigHolder holder = ConfigHolder.create(); private final Component inputWithStyles = ColorConfig.helpText() .wrap(TextConfig.commandPrefixValue()); - private final TextComponent outputStyled = TextComponent.of("prefix!", TextColor.DARK_PURPLE); + private final TextComponent outputStyled = Component.text("prefix!", NamedTextColor.DARK_PURPLE); @BeforeEach void setUp() { @@ -67,11 +66,11 @@ void setUp() { Stream test() { List testCases = ImmutableList.of( new TestCase("Translatable", - TranslatableComponent.of("test", inputWithStyles), - TranslatableComponent.of("test", outputStyled)), + Component.translatable("test", inputWithStyles), + Component.translatable("test", outputStyled)), new TestCase("Text", - TextComponent.of("test").append(inputWithStyles), - TextComponent.of("test").append(outputStyled)) + Component.text("test").append(inputWithStyles), + Component.text("test").append(outputStyled)) ); return testCases.stream().map(testCase -> diff --git a/core/src/test/java/org/enginehub/piston/exception/ConstructionTest.java b/core/src/test/java/org/enginehub/piston/exception/ConstructionTest.java index ab9823a..5f8272a 100644 --- a/core/src/test/java/org/enginehub/piston/exception/ConstructionTest.java +++ b/core/src/test/java/org/enginehub/piston/exception/ConstructionTest.java @@ -20,8 +20,7 @@ package org.enginehub.piston.exception; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParseResult; import org.enginehub.piston.NoInputCommandParameters; @@ -62,7 +61,7 @@ void commandExecutionException() { @Test void stopExecutionException() { - Component message = TextComponent.of("stop"); + Component message = Component.text("stop"); ImmutableList commands = ImmutableList.of(mock(Command.class)); StopExecutionException ex = new StopExecutionException(message, commands); assertSame(message, ex.getRichMessage()); @@ -72,7 +71,7 @@ void stopExecutionException() { @Test void stopExecutionExceptionNoCommands() { - Component message = TextComponent.of("stop"); + Component message = Component.text("stop"); StopExecutionException ex = new StopExecutionException(message); assertSame(message, ex.getRichMessage()); assertEquals("stop", ex.getMessage()); @@ -111,7 +110,7 @@ void noSuchFlagExceptionNoFlags() { void noSuchFlagExceptionWrongFlag() { CommandParseResult mock = mock(CommandParseResult.class); ImmutableList executionPath = mockExecutionPath(ImmutableList.of( - CommandParts.flag('q', TextComponent.of("q flag")).build() + CommandParts.flag('q', Component.text("q flag")).build() )); when(mock.getExecutionPath()).thenReturn(executionPath); when(mock.getParameters()).thenReturn(NoInputCommandParameters.builder().build()); @@ -131,7 +130,7 @@ void usageExceptionNoMessage() { UsageException ex = new UsageException(mock); assertSame(executionPath, ex.getCommands()); assertSame(mock, ex.getCommandParseResult()); - assertEquals(TextComponent.empty(), ex.getRichMessage()); + assertEquals(Component.empty(), ex.getRichMessage()); assertNull(ex.getMessage()); } @@ -141,7 +140,7 @@ void usageExceptionMessage() { ImmutableList executionPath = mockExecutionPath(ImmutableList.of()); when(mock.getExecutionPath()).thenReturn(executionPath); when(mock.getParameters()).thenReturn(NoInputCommandParameters.builder().build()); - Component message = TextComponent.of("message"); + Component message = Component.text("message"); UsageException ex = new UsageException(message, mock); assertSame(executionPath, ex.getCommands()); assertSame(mock, ex.getCommandParseResult()); @@ -155,7 +154,7 @@ void usageExceptionMessageCause() { ImmutableList executionPath = mockExecutionPath(ImmutableList.of()); when(mock.getExecutionPath()).thenReturn(executionPath); when(mock.getParameters()).thenReturn(NoInputCommandParameters.builder().build()); - Component message = TextComponent.of("message"); + Component message = Component.text("message"); Throwable cause = new Throwable(); UsageException ex = new UsageException(message, cause, mock); assertSame(executionPath, ex.getCommands()); @@ -175,7 +174,7 @@ void usageExceptionCause() { UsageException ex = new UsageException(cause, mock); assertSame(executionPath, ex.getCommands()); assertSame(mock, ex.getCommandParseResult()); - assertEquals(TextComponent.empty(), ex.getRichMessage()); + assertEquals(Component.empty(), ex.getRichMessage()); assertEquals(cause.getClass().getName(), ex.getMessage()); assertSame(cause, ex.getCause()); } diff --git a/default-impl/src/main/java/org/enginehub/piston/impl/CommandImpl.java b/default-impl/src/main/java/org/enginehub/piston/impl/CommandImpl.java index 83175c4..2a664c7 100644 --- a/default-impl/src/main/java/org/enginehub/piston/impl/CommandImpl.java +++ b/default-impl/src/main/java/org/enginehub/piston/impl/CommandImpl.java @@ -21,22 +21,16 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; -import org.enginehub.piston.part.CommandArgument; -import org.enginehub.piston.part.CommandFlag; import org.enginehub.piston.part.CommandPart; import org.enginehub.piston.suggestion.DefaultSuggestionProvider; import org.enginehub.piston.suggestion.SuggestionProvider; import javax.annotation.Nullable; import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkState; -import static net.kyori.text.TextComponent.newline; import static org.enginehub.piston.Command.Action.NULL_ACTION; @AutoValue diff --git a/default-impl/src/main/java/org/enginehub/piston/impl/CommandParser.java b/default-impl/src/main/java/org/enginehub/piston/impl/CommandParser.java index 2f857a0..2f86f81 100644 --- a/default-impl/src/main/java/org/enginehub/piston/impl/CommandParser.java +++ b/default-impl/src/main/java/org/enginehub/piston/impl/CommandParser.java @@ -19,29 +19,13 @@ package org.enginehub.piston.impl; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static java.util.Objects.requireNonNull; - - -import javax.annotation.Nullable; -import java.util.HashSet; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ThreadLocalRandom; -import java.util.function.Consumer; -import java.util.stream.Collectors; - import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.apache.logging.log4j.Logger; import org.enginehub.piston.Command; import org.enginehub.piston.CommandMetadata; @@ -67,6 +51,22 @@ import org.enginehub.piston.util.ComponentHelper; import org.enginehub.piston.util.StreamHelper; +import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; +import static net.kyori.adventure.text.Component.text; + class CommandParser { private static final Logger LOGGER = LogManagerCompat.getLogger(); @@ -168,11 +168,11 @@ private UsageException usageException(Component message) { } private UsageException notEnoughArgumentsException() { - return usageException(TextComponent.of("Not enough arguments.")); + return usageException(text("Not enough arguments.")); } private UsageException tooManyArgumentsException() { - return usageException(TextComponent.of("Too many arguments.")); + return usageException(text("Too many arguments.")); } private ConversionFailedException conversionFailedException(ArgAcceptingCommandPart nextArg, String token) { @@ -302,14 +302,15 @@ private void finalizeCommand() { if (requiredIter.hasNext()) { ArgConsumingCommandPart missing = requiredIter.next(); if (missing instanceof CommandArgument) { - throw usageException(TextComponent.builder("Missing argument for ") + throw usageException(text() + .content("Missing argument for ") .append(missing.getTextRepresentation()) - .append(TextComponent.of(".")) + .append(text(".")) .build()); } else { checkState(missing instanceof SubCommandPart, "Unknown part interface: %s", missing.getClass()); - throw usageException(TextComponent.of("No sub-command provided. Options: " + throw usageException(text("No sub-command provided. Options: " + ((SubCommandPart) missing).getCommands().stream() .distinct() .map(Command::getName) @@ -384,17 +385,17 @@ private boolean parseSubCommand(SubCommandPart part, String token) { } private TextComponent invalidSubCommandMessage(String token, ImmutableMap subCommands) { - return TextComponent.builder() - .append("Invalid sub-command '") + return text() + .append(text("Invalid sub-command '")) .append(ColorConfig.mainText().wrap(token)) - .append("'. Options: ") + .append(text("'. Options: ")) .append(subCommands.values().stream().distinct() .map(Command::getName) .map(ColorConfig.mainText()::wrap) .collect(ComponentHelper.joiningTexts( - TextComponent.empty(), - TextComponent.of(", "), - TextComponent.empty() + Component.empty(), + text(", "), + Component.empty() ))) .build(); } @@ -507,15 +508,16 @@ private void parseFlags(String flags) { throw new NoSuchFlagException(getResult(), c); } if (seenFlags.contains(flag)) { - throw usageException(TextComponent.builder("Flag ") + throw usageException(Component.text() + .content("Flag ") .append(flag.getTextRepresentation()) - .append(" has already been specified.") + .append(text(" has already been specified.")) .build()); } if (flag instanceof ArgAcceptingCommandFlag) { if (i + 1 < flags.length()) { // Only allow argument-flags at the end of flag-combos. - throw usageException(TextComponent.of("Argument-accepting flags must be " + + throw usageException(text("Argument-accepting flags must be " + "at the end of combined flag groups.")); } bind(flag); diff --git a/default-impl/src/test/java/org/enginehub/piston/impl/CommandManagerTest.java b/default-impl/src/test/java/org/enginehub/piston/impl/CommandManagerTest.java index e0cf013..1e97b41 100644 --- a/default-impl/src/test/java/org/enginehub/piston/impl/CommandManagerTest.java +++ b/default-impl/src/test/java/org/enginehub/piston/impl/CommandManagerTest.java @@ -20,8 +20,7 @@ package org.enginehub.piston.impl; import com.google.common.collect.ImmutableList; -import net.kyori.text.TextComponent; -import net.kyori.text.TranslatableComponent; +import net.kyori.adventure.text.Component; import org.enginehub.piston.Command; import org.enginehub.piston.CommandManager; import org.enginehub.piston.exception.ConditionFailedException; @@ -40,7 +39,7 @@ public class CommandManagerTest { void parseFailsOnRootConditionUnsatisfied() { CommandManager manager = new CommandManagerImpl(); manager.register("test", cmd -> { - cmd.description(TextComponent.of("Test")) + cmd.description(Component.text("Test")) .condition(Command.Condition.FALSE); }); @@ -55,11 +54,11 @@ void parseFailsOnSubConditionUnsatisfied() { CommandManager manager = new CommandManagerImpl(); manager.register("test", cmd -> { Command sub = manager.newCommand("sub") - .description(TextComponent.of("Sub")) + .description(Component.text("Sub")) .condition(Command.Condition.FALSE) .build(); - cmd.description(TextComponent.of("Test")) - .addPart(SubCommandPart.builder(TranslatableComponent.of("actions"), TextComponent.of("Sub-actions")) + cmd.description(Component.text("Test")) + .addPart(SubCommandPart.builder(Component.translatable("actions"), Component.text("Sub-actions")) .required() .withCommands(ImmutableList.of(sub)) .build()); diff --git a/gradle.properties b/gradle.properties index e699728..b159a14 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=org.enginehub.piston -version=0.5.8-SNAPSHOT +version=0.6.0-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c05..e708b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d913..84a0b92 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c51..4f906e0 100755 --- a/gradlew +++ b/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index a9f778a..ac1b06f 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell