diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt index be97b63496..f10e478769 100644 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ b/buildSrc/src/main/kotlin/LibsConfig.kt @@ -38,6 +38,7 @@ fun Project.applyLibrariesConfiguration() { val relocations = mapOf( "net.kyori.text" to "com.sk89q.worldedit.util.formatting.text", + "net.kyori.adventure" to "com.sk89q.worldedit.util.adventure", "net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori", ) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 000a02a468..a2c1189da2 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -2,8 +2,9 @@ import org.gradle.api.Project object Versions { const val TEXT = "3.0.4" - const val TEXT_EXTRAS = "3.0.6" - const val PISTON = "0.5.7" + const val KYORI_ADVENTURE = "4.14.0" + const val KYORI_PLATFORM_BUKKIT = "4.3.1" + const val PISTON = "0.6.0-SNAPSHOT" const val AUTO_VALUE = "1.9" const val JUNIT = "5.8.1" const val MOCKITO = "4.3.1" diff --git a/verification/src/changes/accepted-bukkit-public-api-changes.json b/verification/src/changes/accepted-bukkit-public-api-changes.json index 7a73a41bfd..2517f7ae48 100644 --- a/verification/src/changes/accepted-bukkit-public-api-changes.json +++ b/verification/src/changes/accepted-bukkit-public-api-changes.json @@ -1,2 +1,32 @@ { -} \ No newline at end of file + "Default implementation in interface added": [ + { + "type": "com.sk89q.worldedit.bukkit.BukkitBlockCommandSender", + "member": "Method com.sk89q.worldedit.bukkit.BukkitBlockCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.bukkit.BukkitBlockRegistry", + "member": "Method com.sk89q.worldedit.bukkit.BukkitBlockRegistry.getRichName(com.sk89q.worldedit.world.block.BlockType)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.bukkit.BukkitCommandSender", + "member": "Method com.sk89q.worldedit.bukkit.BukkitCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.bukkit.BukkitPlayer", + "member": "Method com.sk89q.worldedit.bukkit.BukkitPlayer.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + } + ] +} diff --git a/verification/src/changes/accepted-cli-public-api-changes.json b/verification/src/changes/accepted-cli-public-api-changes.json index 7a73a41bfd..bb3dc4ad66 100644 --- a/verification/src/changes/accepted-cli-public-api-changes.json +++ b/verification/src/changes/accepted-cli-public-api-changes.json @@ -1,2 +1,11 @@ { -} \ No newline at end of file + "Default implementation in interface added": [ + { + "type": "com.sk89q.worldedit.cli.CLICommandSender", + "member": "Method com.sk89q.worldedit.cli.CLICommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + } + ] +} diff --git a/verification/src/changes/accepted-core-public-api-changes.json b/verification/src/changes/accepted-core-public-api-changes.json index 8842fa552f..386c6222a5 100644 --- a/verification/src/changes/accepted-core-public-api-changes.json +++ b/verification/src/changes/accepted-core-public-api-changes.json @@ -136,6 +136,13 @@ "changes": [ "METHOD_NEW_DEFAULT" ] + }, + { + "type": "com.sk89q.worldedit.world.registry.ItemRegistry", + "member": "Method com.sk89q.worldedit.world.registry.ItemRegistry.getDisplayName(com.sk89q.worldedit.blocks.BaseItemStack)", + "changes": [ + "METHOD_NEW_DEFAULT" + ] } ], "LazyReference was never publicly extensible": [ @@ -216,6 +223,41 @@ "changes": [ "METHOD_NEW_DEFAULT" ] + }, + { + "type": "com.sk89q.worldedit.extension.platform.Actor", + "member": "Method com.sk89q.worldedit.extension.platform.Actor.printDebug(com.sk89q.worldedit.util.adventure.text.Component)", + "changes": [ + "METHOD_NEW_DEFAULT" + ] + }, + { + "type": "com.sk89q.worldedit.extension.platform.Actor", + "member": "Method com.sk89q.worldedit.extension.platform.Actor.printError(com.sk89q.worldedit.util.adventure.text.Component)", + "changes": [ + "METHOD_NEW_DEFAULT" + ] + }, + { + "type": "com.sk89q.worldedit.extension.platform.Actor", + "member": "Method com.sk89q.worldedit.extension.platform.Actor.printInfo(com.sk89q.worldedit.util.adventure.text.Component)", + "changes": [ + "METHOD_NEW_DEFAULT" + ] + }, + { + "type": "com.sk89q.worldedit.function.operation.Operation", + "member": "Method com.sk89q.worldedit.function.operation.Operation.getMessages()", + "changes": [ + "METHOD_NEW_DEFAULT" + ] + }, + { + "type": "com.sk89q.worldedit.regions.RegionSelector", + "member": "Method com.sk89q.worldedit.regions.RegionSelector.getSelectionInformationLines()", + "changes": [ + "METHOD_NEW_DEFAULT" + ] } ] } diff --git a/verification/src/changes/accepted-fabric-public-api-changes.json b/verification/src/changes/accepted-fabric-public-api-changes.json index 7a73a41bfd..1e5e457411 100644 --- a/verification/src/changes/accepted-fabric-public-api-changes.json +++ b/verification/src/changes/accepted-fabric-public-api-changes.json @@ -1,2 +1,46 @@ { + "Default implementation in interface added": [ + { + "type": "com.sk89q.worldedit.fabric.FabricBlockCommandSender", + "member": "Method com.sk89q.worldedit.fabric.FabricBlockCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.fabric.FabricBlockRegistry", + "member": "Method com.sk89q.worldedit.fabric.FabricBlockRegistry.getRichName(com.sk89q.worldedit.world.block.BlockType)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.fabric.FabricCommandSender", + "member": "Method com.sk89q.worldedit.fabric.FabricCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.fabric.FabricItemRegistry", + "member": "Method com.sk89q.worldedit.fabric.FabricItemRegistry.getRichName(com.sk89q.worldedit.world.item.ItemType)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.fabric.FabricItemRegistry", + "member": "Method com.sk89q.worldedit.fabric.FabricItemRegistry.getRichName(com.sk89q.worldedit.blocks.BaseItemStack)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.fabric.FabricPlayer", + "member": "Method com.sk89q.worldedit.fabric.FabricPlayer.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + } + ] } \ No newline at end of file diff --git a/verification/src/changes/accepted-forge-public-api-changes.json b/verification/src/changes/accepted-forge-public-api-changes.json index 7a73a41bfd..0ef75ea001 100644 --- a/verification/src/changes/accepted-forge-public-api-changes.json +++ b/verification/src/changes/accepted-forge-public-api-changes.json @@ -1,2 +1,60 @@ { + "Default implementation in interface added": [ + { + "type": "com.sk89q.worldedit.forge.ForgeBlockCommandSender", + "member": "Method com.sk89q.worldedit.forge.ForgeBlockCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.ForgeBlockRegistry", + "member": "Method com.sk89q.worldedit.forge.ForgeBlockRegistry.getRichName(com.sk89q.worldedit.world.block.BlockType)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.ForgeCommandSender", + "member": "Method com.sk89q.worldedit.forge.ForgeCommandSender.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.ForgeItemRegistry", + "member": "Method com.sk89q.worldedit.forge.ForgeItemRegistry.getRichName(com.sk89q.worldedit.world.item.ItemType)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.ForgeItemRegistry", + "member": "Method com.sk89q.worldedit.forge.ForgeItemRegistry.getRichName(com.sk89q.worldedit.blocks.BaseItemStack)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.ForgePlayer", + "member": "Method com.sk89q.worldedit.forge.ForgePlayer.print(com.sk89q.worldedit.util.formatting.text.Component)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.WorldEditFakePlayer", + "member": "Method com.sk89q.worldedit.forge.WorldEditFakePlayer.m_36391_(boolean)", + "changes": [ + "METHOD_REMOVED" + ] + }, + { + "type": "com.sk89q.worldedit.forge.WorldEditFakePlayer", + "member": "Method com.sk89q.worldedit.forge.WorldEditFakePlayer.m_5893_(net.minecraft.world.MenuProvider)", + "changes": [ + "METHOD_REMOVED" + ] + } + ] } \ No newline at end of file diff --git a/worldedit-bukkit/adapters/adapter-1.17.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_17_R1_2/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.17.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_17_R1_2/PaperweightAdapter.java index 32ac4b66c5..fb75eff3c8 100644 --- a/worldedit-bukkit/adapters/adapter-1.17.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_17_R1_2/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.17.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_17_R1_2/PaperweightAdapter.java @@ -49,9 +49,8 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; @@ -544,17 +543,17 @@ private void removeUnwantedEntityTagsRecursively(CompoundTag tag) { @Override public Component getRichBlockName(BlockType blockType) { - return TranslatableComponent.of(getBlockFromType(blockType).getDescriptionId()); + return Component.translatable(getBlockFromType(blockType).getDescriptionId()); } @Override public Component getRichItemName(ItemType itemType) { - return TranslatableComponent.of(getItemFromType(itemType).getDescriptionId()); + return Component.translatable(getItemFromType(itemType).getDescriptionId()); } @Override public Component getRichItemName(BaseItemStack itemStack) { - return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); + return Component.translatable(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/worldedit-bukkit/adapters/adapter-1.18.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_18_R2/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.18.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_18_R2/PaperweightAdapter.java index 562a508a64..11a2ad4c8d 100644 --- a/worldedit-bukkit/adapters/adapter-1.18.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_18_R2/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.18.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_18_R2/PaperweightAdapter.java @@ -49,9 +49,8 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; @@ -536,17 +535,17 @@ private void removeUnwantedEntityTagsRecursively(CompoundTag tag) { @Override public Component getRichBlockName(BlockType blockType) { - return TranslatableComponent.of(getBlockFromType(blockType).getDescriptionId()); + return Component.translatable(getBlockFromType(blockType).getDescriptionId()); } @Override public Component getRichItemName(ItemType itemType) { - return TranslatableComponent.of(getItemFromType(itemType).getDescriptionId()); + return Component.translatable(getItemFromType(itemType).getDescriptionId()); } @Override public Component getRichItemName(BaseItemStack itemStack) { - return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); + return Component.translatable(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/worldedit-bukkit/adapters/adapter-1.19.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R3/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.19.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R3/PaperweightAdapter.java index 64d37df8f0..2b8e17fed2 100644 --- a/worldedit-bukkit/adapters/adapter-1.19.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R3/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.19.4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R3/PaperweightAdapter.java @@ -50,9 +50,8 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; @@ -568,17 +567,17 @@ private void removeUnwantedEntityTagsRecursively(net.minecraft.nbt.CompoundTag t @Override public Component getRichBlockName(BlockType blockType) { - return TranslatableComponent.of(getBlockFromType(blockType).getDescriptionId()); + return Component.translatable(getBlockFromType(blockType).getDescriptionId()); } @Override public Component getRichItemName(ItemType itemType) { - return TranslatableComponent.of(getItemFromType(itemType).getDescriptionId()); + return Component.translatable(getItemFromType(itemType).getDescriptionId()); } @Override public Component getRichItemName(BaseItemStack itemStack) { - return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); + return Component.translatable(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java index 85def690ac..395fc672c6 100644 --- a/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.20.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R2/PaperweightAdapter.java @@ -50,9 +50,8 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; @@ -568,17 +567,17 @@ private void removeUnwantedEntityTagsRecursively(net.minecraft.nbt.CompoundTag t @Override public Component getRichBlockName(BlockType blockType) { - return TranslatableComponent.of(getBlockFromType(blockType).getDescriptionId()); + return Component.translatable(getBlockFromType(blockType).getDescriptionId()); } @Override public Component getRichItemName(ItemType itemType) { - return TranslatableComponent.of(getItemFromType(itemType).getDescriptionId()); + return Component.translatable(getItemFromType(itemType).getDescriptionId()); } @Override public Component getRichItemName(BaseItemStack itemStack) { - return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); + return Component.translatable(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/worldedit-bukkit/adapters/adapter-1.20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R1/PaperweightAdapter.java b/worldedit-bukkit/adapters/adapter-1.20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R1/PaperweightAdapter.java index 3a1c56b634..87acbb3716 100644 --- a/worldedit-bukkit/adapters/adapter-1.20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R1/PaperweightAdapter.java +++ b/worldedit-bukkit/adapters/adapter-1.20/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_20_R1/PaperweightAdapter.java @@ -50,9 +50,8 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.io.file.SafeFiles; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; @@ -568,17 +567,17 @@ private void removeUnwantedEntityTagsRecursively(net.minecraft.nbt.CompoundTag t @Override public Component getRichBlockName(BlockType blockType) { - return TranslatableComponent.of(getBlockFromType(blockType).getDescriptionId()); + return Component.translatable(getBlockFromType(blockType).getDescriptionId()); } @Override public Component getRichItemName(ItemType itemType) { - return TranslatableComponent.of(getItemFromType(itemType).getDescriptionId()); + return Component.translatable(getItemFromType(itemType).getDescriptionId()); } @Override public Component getRichItemName(BaseItemStack itemStack) { - return TranslatableComponent.of(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); + return Component.translatable(CraftItemStack.asNMSCopy(BukkitAdapter.adapt(itemStack)).getDescriptionId()); } @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java index 5bccb32833..cc02854ad8 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBiomeRegistry.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.bukkit; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; @@ -38,8 +37,8 @@ class BukkitBiomeRegistry implements BiomeRegistry { } @Override - public Component getRichName(BiomeType biomeType) { - return TranslatableComponent.of( + public Component getDisplayName(BiomeType biomeType) { + return Component.translatable( TranslationManager.makeTranslationKey("biome", biomeType.getId()) ); } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 12840c4dd7..a7b55cb34c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -22,12 +22,9 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.AbstractCommandBlockActor; import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -66,33 +63,9 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.LIGHT_PURPLE)); - } - } - - @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.GRAY)); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.RED)); - } - } - @Override public void print(Component component) { - TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); + plugin.getAudiences().sender(sender).sendMessage(WorldEditText.format(component, getLocale())); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java index 4407ca3d69..4540075b2f 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -37,11 +37,11 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { private final Map materialMap = new EnumMap<>(Material.class); @Override - public Component getRichName(BlockType blockType) { + public Component getDisplayName(BlockType blockType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichBlockName(blockType); } - return super.getRichName(blockType); + return super.getDisplayName(blockType); } @Nullable diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java index c06e0565c3..f54b112ef4 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java @@ -22,9 +22,8 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -72,33 +71,9 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - sender.sendMessage("§d" + part); - } - } - - @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - sender.sendMessage("§7" + part); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - sender.sendMessage("§c" + part); - } - } - @Override public void print(Component component) { - TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); + plugin.getAudiences().sender(sender).sendMessage(WorldEditText.format(component, getLocale())); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java index c528a5b790..22fe5a2fd7 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemRegistry.java @@ -20,24 +20,24 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; class BukkitItemRegistry extends BundledItemRegistry { @Override - public Component getRichName(ItemType itemType) { + public Component getDisplayName(ItemType itemType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemType); } - return super.getRichName(itemType); + return super.getDisplayName(itemType); } @Override - public Component getRichName(BaseItemStack itemStack) { + public Component getDisplayName(BaseItemStack itemStack) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemStack); } - return super.getRichName(itemStack); + return super.getDisplayName(itemStack); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index bf53f4ffd3..e1764cbb55 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -31,14 +31,11 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.component.TextUtils; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -115,33 +112,9 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - player.sendMessage("§d" + part); - } - } - - @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - player.sendMessage("§7" + part); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - player.sendMessage("§c" + part); - } - } - @Override public void print(Component component) { - TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale())); + plugin.getAudiences().player(player).sendMessage(WorldEditText.format(component, getLocale())); } @Override @@ -236,8 +209,8 @@ public Locale getLocale() { @Override public void sendAnnouncements() { if (!WorldEditPlugin.getInstance().getLifecycledBukkitImplAdapter().isValid()) { - printError(TranslatableComponent.of("worldedit.version.bukkit.unsupported-adapter", - TextComponent.of("https://enginehub.org/worldedit/#downloads", TextColor.AQUA) + printError(Component.translatable("worldedit.version.bukkit.unsupported-adapter", + Component.text("https://enginehub.org/worldedit/#downloads", NamedTextColor.AQUA) .clickEvent(ClickEvent.openUrl("https://enginehub.org/worldedit/#downloads")))); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index b338b2498f..5858e99b1d 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -45,6 +45,7 @@ import com.sk89q.worldedit.internal.command.CommandUtil; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.util.adventure.platform.bukkit.BukkitAudiences; import com.sk89q.worldedit.util.lifecycle.Lifecycled; import com.sk89q.worldedit.util.lifecycle.SimpleLifecycled; import com.sk89q.worldedit.world.World; @@ -121,6 +122,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { SimpleLifecycled.invalid(); private BukkitServerInterface platform; private BukkitConfiguration config; + private BukkitAudiences audiences; @Override public void onLoad() { @@ -171,6 +173,8 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new AsyncTabCompleteListener(), this); } + audiences = BukkitAudiences.create(this); + if (Bukkit.getWorlds().isEmpty()) { setupPreWorldData(); // register this so we can load world-dependent data right as the first world is loading @@ -471,6 +475,15 @@ public BukkitPlayer wrapPlayer(Player player) { return new BukkitPlayer(this, player); } + /** + * Convert a player to an adventure audience. + * + * @return the parsed adventure audience + */ + public BukkitAudiences getAudiences() { + return this.audiences; + } + public Actor wrapCommandSender(CommandSender sender) { if (sender instanceof Player) { return wrapPlayer((Player) sender); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index 80db191862..4f5c5bbcd1 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffect; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java index 94048eed4b..98cf0cc73b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/UnsupportedVersionEditException.java @@ -20,10 +20,10 @@ package com.sk89q.worldedit.bukkit.adapter; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; public class UnsupportedVersionEditException extends WorldEditException { public UnsupportedVersionEditException() { - super(TranslatableComponent.of("worldedit.bukkit.no-edit-without-adapter")); + super(Component.translatable("worldedit.bukkit.no-edit-without-adapter")); } } diff --git a/worldedit-cli/build.gradle.kts b/worldedit-cli/build.gradle.kts index 718bc608aa..2334e3c136 100644 --- a/worldedit-cli/build.gradle.kts +++ b/worldedit-cli/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { "annotationProcessor"(project(":worldedit-libs:core:ap")) "annotationProcessor"("com.google.guava:guava:${Versions.GUAVA}") "api"(project(":worldedit-core")) + "api"(project(":worldedit-libs:cli")) "implementation"(platform("org.apache.logging.log4j:log4j-bom:${Versions.LOG4J}") { because("We control Log4J on this platform") }) diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java index e7205b9d96..ef68cfbf9a 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java @@ -24,10 +24,10 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.FileDialogUtil; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.ansi.ANSIComponentSerializer; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer; import org.apache.logging.log4j.Logger; import java.io.File; @@ -72,38 +72,19 @@ public void printRaw(String msg) { } } - private static final String ANSI_PURPLE = "\u001B[35m"; - private static final String ANSI_RED = "\u001B[31m"; - private static final String ANSI_GREEN = "\u001B[32m"; - private static final String ANSI_RESET = "\u001B[0m"; - @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - sender.info(ANSI_PURPLE + part + ANSI_RESET); - } + public void printError(Component component) { + sender.error(ANSIComponentSerializer.ansi().serialize(WorldEditText.format(component, getLocale()))); } @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - sender.debug(ANSI_GREEN + part + ANSI_RESET); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - sender.error(ANSI_RED + part + ANSI_RESET); - } + public void printDebug(Component component) { + sender.debug(ANSIComponentSerializer.ansi().serialize(WorldEditText.format(component, getLocale()))); } @Override public void print(Component component) { - print(PlainComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale()))); + sender.info(ANSIComponentSerializer.ansi().serialize(WorldEditText.format(component, getLocale()))); } @Override diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIExtraCommands.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIExtraCommands.java index 2ded87ac38..4804d5a4d1 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIExtraCommands.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIExtraCommands.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.task.Task; import com.sk89q.worldedit.world.World; import org.enginehub.piston.annotation.Command; @@ -46,7 +46,7 @@ public void selectWorld(Actor actor, World world, LocalSession session) { selector = new CuboidRegionSelector(world, world.getMinimumPoint(), world.getMaximumPoint()); } session.setRegionSelector(world, selector); - actor.printInfo(TextComponent.of("Selected the entire world.")); + actor.printInfo(Component.text("Selected the entire world.")); } @Command( diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java index d527790157..12183cbfda 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIWorldEdit.java @@ -38,7 +38,7 @@ import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockState; @@ -268,13 +268,13 @@ public void run(InputStream inputStream) { continue; } if (line.equals("stop")) { - commandSender.printInfo(TranslatableComponent.of("worldedit.cli.stopping")); + commandSender.printInfo(Component.translatable("worldedit.cli.stopping")); break; } CommandEvent event = new CommandEvent(commandSender, line); WorldEdit.getInstance().getEventBus().post(event); if (!event.isCancelled()) { - commandSender.printError(TranslatableComponent.of("worldedit.cli.unknown-command")); + commandSender.printError(Component.translatable("worldedit.cli.unknown-command")); } else { saveAllWorlds(false); } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java index f716064956..c09ad46ced 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/data/FileRegistries.java @@ -48,6 +48,9 @@ public void loadDataFiles() { ResourceLoader resourceLoader = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.CONFIGURATION).getResourceLoader(); try { URL url = resourceLoader.getResource(FileRegistries.class, app.getPlatform().getDataVersion() + ".json"); + if (url == null) { + throw new RuntimeException("The provided file " + app.getPlatform().getDataVersion() + " is not compatible with this version of WorldEdit-CLI. Please update or report this."); + } this.dataFile = gson.fromJson(Resources.toString(url, StandardCharsets.UTF_8), DataFile.class); } catch (IOException e) { throw new RuntimeException("The provided file is not compatible with this version of WorldEdit-CLI. Please update or report this."); diff --git a/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/DocumentationPrinter.kt b/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/DocumentationPrinter.kt index 0ef42ff927..38d7aa136c 100644 --- a/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/DocumentationPrinter.kt +++ b/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/DocumentationPrinter.kt @@ -37,7 +37,7 @@ import com.sk89q.worldedit.command.ToolUtilCommands import com.sk89q.worldedit.command.UtilityCommands import com.sk89q.worldedit.command.util.PermissionCondition import com.sk89q.worldedit.internal.command.CommandUtil -import com.sk89q.worldedit.util.formatting.text.TextComponent +import com.sk89q.worldedit.util.adventure.text.Component import org.enginehub.piston.Command import org.enginehub.piston.config.TextConfig import org.enginehub.piston.part.SubCommandPart @@ -45,7 +45,6 @@ import org.enginehub.piston.util.HelpGenerator import java.nio.file.Files import java.nio.file.Paths import java.util.stream.Stream -import kotlin.streams.toList class DocumentationPrinter private constructor() { @@ -306,7 +305,7 @@ Other Permissions val footer = CommandUtil.footerWithoutDeprecation(command) when { footer.isPresent -> append( - TextComponent.builder("\n\n").append(footer.get()) + Component.text("\n\n").append(footer.get()) ) else -> this } diff --git a/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/RstWorldEditText.kt b/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/RstWorldEditText.kt index 87dadef870..8733f8f9ce 100644 --- a/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/RstWorldEditText.kt +++ b/worldedit-core/doctools/src/main/kotlin/com/sk89q/worldedit/internal/util/RstWorldEditText.kt @@ -20,11 +20,11 @@ package com.sk89q.worldedit.internal.util import com.sk89q.worldedit.util.formatting.WorldEditText -import com.sk89q.worldedit.util.formatting.text.Component -import com.sk89q.worldedit.util.formatting.text.TextComponent -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent -import com.sk89q.worldedit.util.formatting.text.format.TextDecoration +import com.sk89q.worldedit.util.adventure.text.Component +import com.sk89q.worldedit.util.adventure.text.TextComponent +import com.sk89q.worldedit.util.adventure.text.TranslatableComponent +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration import org.enginehub.piston.util.TextHelper import java.util.Locale @@ -41,8 +41,9 @@ private fun formatAsRst(component: Component, currentDeco: String? = null): Char val deco = when { // Actions that suggest themselves as commands are marked as code component.isSuggestingAsCommand(content.toString()) -> "``" - component.decorations().any { it == TextDecoration.BOLD } -> "**" - component.decorations().any { it == TextDecoration.ITALIC } -> "*" + // TODO: Fix this somehow + //component.decorations().any { it == TextDecoration.BOLD } -> "**" + //component.decorations().any { it == TextDecoration.ITALIC } -> "*" else -> null } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index d06b7a291f..af552bcc93 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -110,11 +110,10 @@ import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.collection.BlockMap; import com.sk89q.worldedit.util.collection.DoubleArrayList; import com.sk89q.worldedit.util.eventbus.EventBus; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.NullWorld; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; @@ -932,7 +931,7 @@ private void dumpTracingInformation() { List tracingExtents = getActiveTracingExtents(); assert actor != null; if (tracingExtents.isEmpty()) { - actor.printError(TranslatableComponent.of("worldedit.trace.no-tracing-extents")); + actor.printError(Component.translatable("worldedit.trace.no-tracing-extents")); return; } // find the common stacks @@ -955,13 +954,12 @@ private void dumpTracingInformation() { stackToPosition.forEach((stack, position) -> { // stack can never be empty, something has to have touched the position TracingExtent failure = stack.get(0); - actor.printDebug(TranslatableComponent.builder("worldedit.trace.action-failed") + actor.printDebug(Component.translatable("worldedit.trace.action-failed") .args( - TextComponent.of(failure.getFailedActions().get(position).toString()), - TextComponent.of(position.toString()), - TextComponent.of(failure.getExtent().getClass().getName()) - ) - .build()); + Component.text(failure.getFailedActions().get(position).toString()), + Component.text(position.toString()), + Component.text(failure.getExtent().getClass().getName()) + )); }); } @@ -1484,7 +1482,7 @@ public int stackRegionBlockUnits(Region region, BlockVector3 offset, int count, BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); BlockVector3 offsetAbs = offset.abs(); if (offsetAbs.getX() < size.getX() && offsetAbs.getY() < size.getY() && offsetAbs.getZ() < size.getZ()) { - throw new RegionOperationException(TranslatableComponent.of("worldedit.stack.intersecting-region")); + throw new RegionOperationException(Component.translatable("worldedit.stack.intersecting-region")); } BlockVector3 to = region.getMinimumPoint(); ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index e727756075..0deb3d90e4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -51,7 +51,7 @@ import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.SideEffectSet; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -775,7 +775,7 @@ public BrushTool forceBrush(ItemType item, Brush brush, String permission) throw */ public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException { if (item.hasBlockType()) { - throw new InvalidToolBindException(item, TranslatableComponent.of("worldedit.tool.error.item-only")); + throw new InvalidToolBindException(item, Component.translatable("worldedit.tool.error.item-only")); } if (tool instanceof SelectionWand) { setSingleItemTool(id -> { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java index 808bd430b6..8fa3a048e5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/MissingWorldException.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Raised when a world is missing but is required. @@ -27,6 +27,6 @@ public class MissingWorldException extends WorldEditException { public MissingWorldException() { - super(TranslatableComponent.of("worldedit.error.missing-world")); + super(Component.translatable("worldedit.error.missing-world")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/NotABlockException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/NotABlockException.java index 4a43cf9dc7..3509ef8c04 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/NotABlockException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/NotABlockException.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; /** @@ -32,7 +31,7 @@ public class NotABlockException extends WorldEditException { * Create a new instance. */ public NotABlockException() { - super(TranslatableComponent.of("worldedit.error.not-a-block")); + super(Component.translatable("worldedit.error.not-a-block")); } /** @@ -42,7 +41,7 @@ public NotABlockException() { */ @Deprecated public NotABlockException(String input) { - super(TranslatableComponent.of("worldedit.error.not-a-block.item", TextComponent.of(input))); + super(Component.translatable("worldedit.error.not-a-block.item", Component.text(input))); } /** @@ -52,7 +51,7 @@ public NotABlockException(String input) { */ @Deprecated public NotABlockException(int input) { - super(TranslatableComponent.of("worldedit.error.not-a-block.item", TextComponent.of(input))); + super(Component.translatable("worldedit.error.not-a-block.item", Component.text(input))); } /** @@ -61,6 +60,6 @@ public NotABlockException(int input) { * @param input the input that was used */ public NotABlockException(ItemType input) { - super(TranslatableComponent.of("worldedit.error.not-a-block.item", input.getRichName())); + super(Component.translatable("worldedit.error.not-a-block.item", input.getDisplayName())); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/UnknownDirectionException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/UnknownDirectionException.java index 9ba595d1a5..175eb14bfd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/UnknownDirectionException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/UnknownDirectionException.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Thrown when an unknown direction is specified or detected. @@ -35,7 +34,7 @@ public class UnknownDirectionException extends WorldEditException { * @param dir the input that was tried */ public UnknownDirectionException(String dir) { - super(TranslatableComponent.of("worldedit.error.unknown-direction", TextComponent.of(dir))); + super(Component.translatable("worldedit.error.unknown-direction", Component.text(dir))); this.dir = dir; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index 10ac429db8..9a856f3d7c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -54,12 +54,12 @@ import com.sk89q.worldedit.session.SessionManager; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.asset.AssetLoaders; import com.sk89q.worldedit.util.concurrency.EvenMoreExecutors; import com.sk89q.worldedit.util.eventbus.EventBus; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; @@ -325,7 +325,7 @@ private File getSafeFile(@Nullable Actor actor, File dir, String filename, Strin } if (f == null) { - throw new FileSelectionAbortedException(TranslatableComponent.of("worldedit.error.no-file-selected")); + throw new FileSelectionAbortedException(Component.translatable("worldedit.error.no-file-selected")); } } else { List exts = extensions == null ? ImmutableList.of(defaultExt) : Lists.asList(defaultExt, extensions); @@ -344,12 +344,12 @@ private File getSafeFile(@Nullable Actor actor, File dir, String filename, Strin boolean isSym = existingParent != null && !existingParent.toRealPath().equals(existingParent); if (!inDir || (!getConfiguration().allowSymlinks && isSym)) { - throw new FilenameResolutionException(filename, TranslatableComponent.of("worldedit.error.file-resolution.outside-root")); + throw new FilenameResolutionException(filename, Component.translatable("worldedit.error.file-resolution.outside-root")); } return filePath.toFile(); } catch (IOException | InvalidPathException e) { - throw new FilenameResolutionException(filename, TranslatableComponent.of("worldedit.error.file-resolution.resolve-failed")); + throw new FilenameResolutionException(filename, Component.translatable("worldedit.error.file-resolution.resolve-failed")); } } @@ -376,7 +376,7 @@ private File getSafeFileWithExtensions(File dir, String filename, List e result = getSafeFileWithExtension(dir, filename, iter.next()); } if (result == null) { - throw new InvalidFilenameException(filename, TranslatableComponent.of("worldedit.error.invalid-filename.invalid-characters")); + throw new InvalidFilenameException(filename, Component.translatable("worldedit.error.invalid-filename.invalid-characters")); } return result; } @@ -599,22 +599,22 @@ public void flushBlockBag(Actor actor, EditSession editSession) { Map missingBlocks = editSession.popMissingBlocks(); if (!missingBlocks.isEmpty()) { - TextComponent.Builder str = TextComponent.builder(); - str.append("Missing these blocks: "); + TextComponent.Builder str = Component.text(); + str.content("Missing these blocks: "); int size = missingBlocks.size(); int i = 0; for (Map.Entry blockTypeIntegerEntry : missingBlocks.entrySet()) { - str.append((blockTypeIntegerEntry.getKey()).getRichName()); + str.append((blockTypeIntegerEntry.getKey()).getDisplayName()); - str.append(" [Amt: ") - .append(String.valueOf(blockTypeIntegerEntry.getValue())) - .append("]"); + str.append(Component.text(" [Amt: ")) + .append(Component.text(blockTypeIntegerEntry.getValue())) + .append(Component.text("]")); ++i; if (i != size) { - str.append(", "); + str.append(Component.text(", ")); } } @@ -712,7 +712,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce String ext = filename.substring(index + 1); if (!ext.equalsIgnoreCase("js")) { - player.printError(TranslatableComponent.of("worldedit.script.unsupported")); + player.printError(Component.translatable("worldedit.script.unsupported")); return; } @@ -725,7 +725,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename); if (file == null) { - player.printError(TranslatableComponent.of("worldedit.script.file-not-found", TextComponent.of(filename))); + player.printError(Component.translatable("worldedit.script.file-not-found", Component.text(filename))); return; } } else { @@ -738,7 +738,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce in.close(); script = new String(data, 0, data.length, StandardCharsets.UTF_8); } catch (IOException e) { - player.printError(TranslatableComponent.of("worldedit.script.read-error", TextComponent.of(e.getMessage()))); + player.printError(Component.translatable("worldedit.script.read-error", Component.text(e.getMessage()))); return; } @@ -751,7 +751,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce try { engine = new RhinoCraftScriptEngine(); } catch (NoClassDefFoundError ignored) { - player.printError(TranslatableComponent.of("worldedit.script.no-script-engine")); + player.printError(Component.translatable("worldedit.script.no-script-engine")); return; } @@ -767,14 +767,14 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce } catch (ScriptException e) { // non-exceptional return check if (!(Throwables.getRootCause(e) instanceof ReturnException)) { - player.printError(TranslatableComponent.of("worldedit.script.failed", TextComponent.of(e.getMessage(), TextColor.WHITE))); + player.printError(Component.translatable("worldedit.script.failed", Component.text(e.getMessage(), NamedTextColor.WHITE))); logger.warn("Failed to execute script", e); } } catch (NumberFormatException | WorldEditException e) { throw e; } catch (Throwable e) { - player.printError(TranslatableComponent.of("worldedit.script.failed-console", TextComponent.of(e.getClass().getCanonicalName(), - TextColor.WHITE))); + player.printError(Component.translatable("worldedit.script.failed-console", Component.text(e.getClass().getCanonicalName(), + NamedTextColor.WHITE))); logger.warn("Failed to execute script", e); } finally { for (EditSession editSession : scriptContext.getEditSessions()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java index 814e6c213f..9f8ba244cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditException.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.Locale; @@ -49,7 +49,7 @@ protected WorldEditException() { protected WorldEditException(String message) { super(message); - this.message = TextComponent.of(message); + this.message = Component.text(message); } /** @@ -63,6 +63,19 @@ protected WorldEditException(Component message) { this.message = message; } + /** + * Create a new exception with a message. + * + * @param message the message + * @deprecated Use {@link WorldEditException#WorldEditException(Component)} + */ + @Deprecated + protected WorldEditException(com.sk89q.worldedit.util.formatting.text.Component message) { + super(WorldEditText.reduceToText(LegacyTextHelper.adapt(message), Locale.getDefault())); + + this.message = LegacyTextHelper.adapt(message); + } + /** * Create a new exception with a message and a cause. * @@ -74,7 +87,7 @@ protected WorldEditException(Component message) { protected WorldEditException(String message, Throwable cause) { super(message, cause); - this.message = TextComponent.of(message); + this.message = Component.text(message); } /** @@ -89,6 +102,20 @@ protected WorldEditException(Component message, Throwable cause) { this.message = message; } + /** + * Create a new exception with a message and a cause. + * + * @param message the message + * @param cause the cause + * @deprecated Use {@link WorldEditException#WorldEditException(Component, Throwable)} + */ + @Deprecated + protected WorldEditException(com.sk89q.worldedit.util.formatting.text.Component message, Throwable cause) { + super(WorldEditText.reduceToText(LegacyTextHelper.adapt(message), Locale.getDefault()), cause); + + this.message = LegacyTextHelper.adapt(message); + } + /** * Create a new exception with a cause. * @@ -105,7 +132,18 @@ protected WorldEditException(Throwable cause) { * * @return The rich message */ - public Component getRichMessage() { + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component getRichMessage() { + return LegacyTextHelper.adapt(this.message); + } + + + /** + * Get the message of this exception as a rich text component. + * + * @return The rich message + */ + public Component getTextMessage() { return this.message; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java index 711739cecf..bcd56da972 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/BaseItemStack.java @@ -22,8 +22,8 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.linbus.tree.LinCompoundTag; @@ -100,8 +100,26 @@ public void setAmount(int amount) { this.amount = amount; } - public Component getRichName() { + /** + * Gets the rich name of the item stack. + * + * @return the rich name + * @deprecated Use {@link BaseItemStack#getDisplayName()} instead + */ + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component getRichName() { return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) .getRegistries().getItemRegistry().getRichName(this); } + + /** + * Gets the display name of the item stack. + * + * @return the display name + */ + public Component getDisplayName() { + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) + .getRegistries().getItemRegistry().getDisplayName(this); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java index 596aea821b..35a47f72af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java @@ -39,10 +39,9 @@ import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.regions.factory.RegionFactory; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; -import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; import org.enginehub.piston.CommandParameters; @@ -61,19 +60,19 @@ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ApplyBrushCommands { - private static final CommandArgument REGION_FACTORY = arg(TranslatableComponent.of("shape"), TranslatableComponent.of("worldedit.brush.apply.shape")) + private static final CommandArgument REGION_FACTORY = arg(Component.translatable("shape"), Component.translatable("worldedit.brush.apply.shape")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(Key.of(RegionFactory.class))) .build(); - private static final CommandArgument RADIUS = arg(TranslatableComponent.of("radius"), TranslatableComponent.of("worldedit.brush.apply.radius")) + private static final CommandArgument RADIUS = arg(Component.translatable("radius"), Component.translatable("worldedit.brush.apply.radius")) .defaultsTo(ImmutableList.of("5")) .ofTypes(ImmutableList.of(Key.of(double.class))) .build(); public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) { commandManager.register("apply", builder -> { - builder.description(TranslatableComponent.of("worldedit.brush.apply.description")); + builder.description(Component.translatable("worldedit.brush.apply.description")); builder.action(org.enginehub.piston.Command.Action.NULL_ACTION); CommandManager manager = service.newCommandManager(); @@ -86,7 +85,7 @@ public static void register(CommandManagerService service, CommandManager comman builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.apply"))); builder.addParts(REGION_FACTORY, RADIUS); - builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TranslatableComponent.of("worldedit.brush.apply.type")) + builder.addPart(SubCommandPart.builder(Component.translatable("type"), Component.translatable("worldedit.brush.apply.type")) .withCommands(manager.getAllCommands().collect(Collectors.toList())) .required() .build()); @@ -124,8 +123,8 @@ public void item(CommandParameters parameters, @Arg(desc = "The direction in which the item will be applied", def = "up") @Direction(includeDiagonals = true) com.sk89q.worldedit.util.Direction direction) throws WorldEditException { - player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD) - .append(TranslatableComponent.of("worldedit.brush.apply.item.warning")).build()); + player.print(Component.text("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD) + .append(Component.translatable("worldedit.brush.apply.item.warning"))); setApplyBrush(parameters, player, localSession, new ItemUseFactory(item, direction)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index a42f88f24d..1edc4cb0c7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -41,12 +41,10 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.component.TextUtils; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.JoinConfiguration; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -88,16 +86,16 @@ public void biomeList(Actor actor, BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); - PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%", + PaginationBox paginationBox = PaginationBox.fromText("Available Biomes", "/biomelist -p %page%", BiomeType.REGISTRY.values().stream() - .map(biomeType -> TextComponent.builder() - .append(biomeType.getId()) - .append(" (") - .append(biomeRegistry.getRichName(biomeType)) - .append(")") + .map(biomeType -> Component.text() + .append(Component.text(biomeType.getId())) + .append(Component.text(" (")) + .append(biomeRegistry.getDisplayName(biomeType)) + .append(Component.text(")")) .build()) .collect(Collectors.toList())); - return paginationBox.create(page); + return paginationBox.build(page); }, (Component) null); } @@ -121,7 +119,7 @@ public void biomeInfo(Actor actor, World world, LocalSession session, if (actor instanceof Player) { Location blockPosition = ((Player) actor).getBlockTrace(300); if (blockPosition == null) { - actor.printError(TranslatableComponent.of("worldedit.raytrace.noblock")); + actor.printError(Component.translatable("worldedit.raytrace.noblock")); return; } @@ -130,7 +128,7 @@ public void biomeInfo(Actor actor, World world, LocalSession session, messageKey = "worldedit.biomeinfo.lineofsight"; } else { - actor.printError(TranslatableComponent.of("worldedit.raytrace.require-player")); + actor.printError(Component.translatable("worldedit.raytrace.require-player")); return; } } else if (usePosition) { @@ -140,7 +138,7 @@ public void biomeInfo(Actor actor, World world, LocalSession session, messageKey = "worldedit.biomeinfo.position"; } else { - actor.printError(TranslatableComponent.of("worldedit.biomeinfo.not-locatable")); + actor.printError(Component.translatable("worldedit.biomeinfo.not-locatable")); return; } } else { @@ -154,11 +152,11 @@ public void biomeInfo(Actor actor, World world, LocalSession session, } List components = biomes.stream().map(biome -> - biomeRegistry.getRichName(biome).hoverEvent( - HoverEvent.showText(TextComponent.of(biome.getId())) + biomeRegistry.getDisplayName(biome).hoverEvent( + HoverEvent.showText(Component.text(biome.getId())) ) ).collect(Collectors.toList()); - actor.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", ")))); + actor.printInfo(Component.translatable(messageKey, Component.join(JoinConfiguration.separator(Component.text(", ")), components))); } @Command( @@ -180,7 +178,7 @@ public void setBiome(Actor actor, World world, LocalSession session, EditSession final BlockVector3 pos = ((Locatable) actor).getLocation().toVector().toBlockPoint(); region = new CuboidRegion(pos, pos); } else { - actor.printError(TranslatableComponent.of("worldedit.setbiome.not-locatable")); + actor.printError(Component.translatable("worldedit.setbiome.not-locatable")); return; } } else { @@ -194,12 +192,12 @@ public void setBiome(Actor actor, World world, LocalSession session, EditSession RegionVisitor visitor = new RegionVisitor(region, replace); Operations.completeLegacy(visitor); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.setbiome.changed", - TextComponent.of(visitor.getAffected()) + Component.text(visitor.getAffected()) ) - .append(TextComponent.newline()) - .append(TranslatableComponent.of("worldedit.setbiome.warning"))); + .append(Component.newline()) + .append(Component.translatable("worldedit.setbiome.warning"))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 5b33a9741e..5f3a35fba2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -73,14 +73,12 @@ import com.sk89q.worldedit.session.request.RequestExtent; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.asset.AssetLoadTask; import com.sk89q.worldedit.util.asset.AssetLoader; import com.sk89q.worldedit.util.asset.holder.ImageHeightmap; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; @@ -102,9 +100,8 @@ public class BrushCommands { private final WorldEdit worldEdit; - private static final Component UNBIND_COMMAND_COMPONENT = TextComponent.builder("/brush unbind", TextColor.AQUA) - .clickEvent(ClickEvent.suggestCommand("/brush unbind")) - .build(); + private static final Component UNBIND_COMMAND_COMPONENT = Component.text("/brush unbind", NamedTextColor.AQUA) + .clickEvent(ClickEvent.suggestCommand("/brush unbind")); /** * Create a new instance. @@ -150,7 +147,7 @@ public void sphereBrush(Player player, LocalSession session, tool.setFill(pattern); tool.setSize(radius); - player.printInfo(TranslatableComponent.of("worldedit.brush.sphere.equip", TextComponent.of(String.format("%.0f", radius)))); + player.printInfo(Component.translatable("worldedit.brush.sphere.equip", Component.text(String.format("%.0f", radius)))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -182,7 +179,7 @@ public void cylinderBrush(Player player, LocalSession session, tool.setFill(pattern); tool.setSize(radius); - player.printInfo(TranslatableComponent.of("worldedit.brush.cylinder.equip", TextComponent.of((int) radius), TextComponent.of(height))); + player.printInfo(Component.translatable("worldedit.brush.cylinder.equip", Component.text((int) radius), Component.text(height))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -202,7 +199,7 @@ public void splatterBrush(Player player, LocalSession session, worldEdit.checkMaxBrushRadius(radius); if (decay < 0 || decay > 10) { - player.printError(TranslatableComponent.of("worldedit.brush.splatter.decay-out-of-range", TextComponent.of(decay))); + player.printError(Component.translatable("worldedit.brush.splatter.decay-out-of-range", Component.text(decay))); return; } @@ -214,7 +211,7 @@ public void splatterBrush(Player player, LocalSession session, tool.setFill(pattern); tool.setSize(radius); - player.printInfo(TranslatableComponent.of("worldedit.brush.splatter.equip", TextComponent.of((int) radius), TextComponent.of(decay))); + player.printInfo(Component.translatable("worldedit.brush.splatter.equip", Component.text((int) radius), Component.text(decay))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -257,7 +254,7 @@ public void clipboardBrush(Player player, LocalSession session, "worldedit.brush.clipboard" ); - player.printInfo(TranslatableComponent.of("worldedit.brush.clipboard.equip")); + player.printInfo(Component.translatable("worldedit.brush.clipboard.equip")); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -283,11 +280,11 @@ public void smoothBrush(Player player, LocalSession session, ); tool.setSize(radius); - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.brush.smooth.equip", - TextComponent.of((int) radius), - TextComponent.of(iterations), - TranslatableComponent.of("worldedit.brush.smooth." + (mask == null ? "no" : "") + "filter") + Component.text((int) radius), + Component.text(iterations), + Component.translatable("worldedit.brush.smooth." + (mask == null ? "no" : "") + "filter") )); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -316,12 +313,12 @@ public void snowSmoothBrush(Player player, LocalSession session, ); tool.setSize(radius); - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.brush.snowsmooth.equip", - TextComponent.of((int) radius), - TextComponent.of(iterations), - TranslatableComponent.of("worldedit.brush.snowsmooth." + (mask == null ? "no" : "") + "filter"), - TextComponent.of(snowBlockCount) + Component.text((int) radius), + Component.text(iterations), + Component.translatable("worldedit.brush.snowsmooth." + (mask == null ? "no" : "") + "filter"), + Component.text(snowBlockCount) )); } @@ -345,7 +342,7 @@ public void extinguishBrush(Player player, LocalSession session, tool.setSize(radius); tool.setMask(new BlockTypeMask(new RequestExtent(), BlockTypes.FIRE)); - player.printInfo(TranslatableComponent.of("worldedit.brush.extinguish.equip", TextComponent.of((int) radius))); + player.printInfo(Component.translatable("worldedit.brush.extinguish.equip", Component.text((int) radius))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -376,7 +373,7 @@ public void gravityBrush(Player player, LocalSession session, ); tool.setSize(radius); - player.printInfo(TranslatableComponent.of("worldedit.brush.gravity.equip", TextComponent.of((int) radius))); + player.printInfo(Component.translatable("worldedit.brush.gravity.equip", Component.text((int) radius))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -417,7 +414,7 @@ public void butcherBrush(Player player, LocalSession session, maxRadius = Math.max(config.maxBrushRadius, config.butcherMaxRadius); } if (radius > maxRadius) { - player.printError(TranslatableComponent.of("worldedit.brush.radius-too-large", TextComponent.of(maxRadius))); + player.printError(Component.translatable("worldedit.brush.radius-too-large", Component.text(maxRadius))); return; } @@ -438,7 +435,7 @@ public void butcherBrush(Player player, LocalSession session, ); tool.setSize(radius); - player.printInfo(TranslatableComponent.of("worldedit.brush.butcher.equip", TextComponent.of((int) radius))); + player.printInfo(Component.translatable("worldedit.brush.butcher.equip", Component.text((int) radius))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -468,9 +465,9 @@ void heightmapBrush(Player player, LocalSession session, AssetLoadTask task = new AssetLoadTask<>(loader.get(), imageName); AsyncCommandBuilder.wrap(task, player) .registerWithSupervisor(worldEdit.getSupervisor(), "Loading asset " + imageName) - .setDelayMessage(TranslatableComponent.of("worldedit.asset.load.loading")) - .setWorkingMessage(TranslatableComponent.of("worldedit.asset.load.still-loading")) - .onSuccess(TranslatableComponent.of("worldedit.brush.heightmap.equip", TextComponent.of((int) radius)), heightmap -> { + .setDelayMessage(Component.translatable("worldedit.asset.load.loading")) + .setWorkingMessage(Component.translatable("worldedit.asset.load.still-loading")) + .onSuccess(Component.translatable("worldedit.brush.heightmap.equip", Component.text((int) radius)), heightmap -> { BrushTool tool; try { tool = session.forceBrush( @@ -484,10 +481,10 @@ void heightmapBrush(Player player, LocalSession session, tool.setSize(radius); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); }) - .onFailure(TranslatableComponent.of("worldedit.asset.load.failed"), worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) + .onFailure(Component.translatable("worldedit.asset.load.failed"), worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) .buildAndExec(worldEdit.getExecutorService()); } else { - player.printError(TranslatableComponent.of("worldedit.brush.heightmap.unknown", TextComponent.of(imageName))); + player.printError(Component.translatable("worldedit.brush.heightmap.unknown", Component.text(imageName))); } } @@ -642,14 +639,14 @@ public void biome(Player player, LocalSession localSession, } else if (shape instanceof CuboidRegionFactory) { shape = new FixedHeightCuboidRegionFactory(player.getWorld().getMinY(), player.getWorld().getMaxY()); } else { - player.printError(TranslatableComponent.of("worldedit.brush.biome.column-supported-types")); + player.printError(Component.translatable("worldedit.brush.biome.column-supported-types")); return; } } setOperationBasedBrush(player, localSession, radius, new ApplyRegion(new BiomeFactory(biomeType)), shape, "worldedit.brush.biome"); - player.printInfo(TranslatableComponent.of("worldedit.setbiome.warning")); + player.printInfo(Component.translatable("worldedit.setbiome.warning")); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -677,7 +674,7 @@ public void morph(Player player, LocalSession session, ); tool.setSize(brushSize); - player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize))); + player.printInfo(Component.translatable("worldedit.brush.morph.equip", Component.text((int) brushSize))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -697,7 +694,7 @@ public void erode(Player player, LocalSession session, ); tool.setSize(brushSize); - player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize))); + player.printInfo(Component.translatable("worldedit.brush.morph.equip", Component.text((int) brushSize))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -717,7 +714,7 @@ public void dilate(Player player, LocalSession session, ); tool.setSize(brushSize); - player.printInfo(TranslatableComponent.of("worldedit.brush.morph.equip", TextComponent.of((int) brushSize))); + player.printInfo(Component.translatable("worldedit.brush.morph.equip", Component.text((int) brushSize))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -734,7 +731,7 @@ static void setOperationBasedBrush(Player player, LocalSession session, double r tool.setSize(radius); tool.setFill(null); - player.printInfo(TranslatableComponent.of("worldedit.brush.operation.equip", TextComponent.of(factory.toString()))); + player.printInfo(Component.translatable("worldedit.brush.operation.equip", Component.text(factory.toString()))); ToolCommands.sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index 9416fbb537..56b5c19d72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -35,12 +35,10 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.LegacyChunkStore; import com.sk89q.worldedit.world.storage.McRegionChunkStore; @@ -85,9 +83,9 @@ public void chunkInfo(Player player) { int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0); final BlockVector2 chunkPos = BlockVector2.at(chunkX, chunkZ); - player.printInfo(TranslatableComponent.of("worldedit.chunkinfo.chunk", TextComponent.of(chunkX), TextComponent.of(chunkZ))); - player.printInfo(TranslatableComponent.of("worldedit.chunkinfo.old-filename", TextComponent.of(LegacyChunkStore.getFilename(chunkPos)))); - player.printInfo(TranslatableComponent.of("worldedit.chunkinfo.mcregion-filename", TextComponent.of(McRegionChunkStore.getFilename(chunkPos)))); + player.printInfo(Component.translatable("worldedit.chunkinfo.chunk", Component.text(chunkX), Component.text(chunkZ))); + player.printInfo(Component.translatable("worldedit.chunkinfo.old-filename", Component.text(LegacyChunkStore.getFilename(chunkPos)))); + player.printInfo(Component.translatable("worldedit.chunkinfo.mcregion-filename", Component.text(McRegionChunkStore.getFilename(chunkPos)))); } @Command( @@ -100,10 +98,10 @@ public void listChunks(Actor actor, World world, LocalSession session, final Region region = session.getSelection(world); WorldEditAsyncCommandBuilder.createAndSendMessage(actor, - () -> new ChunkListPaginationBox(region).create(page), - TranslatableComponent.of( + () -> new ChunkListPaginationBox(region).build(page), + Component.translatable( "worldedit.listchunks.listfor", - TextComponent.of(actor.getName()) + Component.text(actor.getName()) )); } @@ -118,7 +116,7 @@ public void deleteChunks(Actor actor, World world, LocalSession session, ZonedDateTime beforeTime) throws WorldEditException { Path worldDir = world.getStoragePath(); if (worldDir == null) { - throw new StopExecutionException(TextComponent.of("Couldn't find world folder for this world.")); + throw new StopExecutionException(Component.text("Couldn't find world folder for this world.")); } Path chunkPath = worldEdit.getWorkingDirectoryPath(DELCHUNKS_FILE_NAME); @@ -127,7 +125,7 @@ public void deleteChunks(Actor actor, World world, LocalSession session, try { currentInfo = ChunkDeleter.readInfo(chunkPath); } catch (IOException e) { - throw new StopExecutionException(TextComponent.of("Error reading existing chunk file.")); + throw new StopExecutionException(Component.text("Error reading existing chunk file.")); } } if (currentInfo == null) { @@ -160,22 +158,22 @@ public void deleteChunks(Actor actor, World world, LocalSession session, try { ChunkDeleter.writeInfo(currentInfo, chunkPath); } catch (IOException | JsonIOException e) { - throw new StopExecutionException(TextComponent.of("Failed to write chunk list: " + e.getMessage())); + throw new StopExecutionException(Component.text("Failed to write chunk list: " + e.getMessage())); } - actor.print(TextComponent.of( + actor.print(Component.text( String.format("%d chunk(s) have been marked for deletion the next time the server starts.", newBatch.getChunkCount()) )); if (currentInfo.batches.size() > 1) { - actor.printDebug(TextComponent.of( + actor.printDebug(Component.text( String.format("%d chunks total marked for deletion. (May have overlaps).", currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum()) )); } - actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE) - .append(TextComponent.of("/stop", TextColor.AQUA) - .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop")))); + actor.print(Component.text("You can mark more chunks for deletion, or to stop now, run: ", NamedTextColor.LIGHT_PURPLE) + .append(Component.text("/stop", NamedTextColor.AQUA) + .clickEvent(ClickEvent.suggestCommand("/stop")))); } private static class ChunkListPaginationBox extends PaginationBox { @@ -192,8 +190,8 @@ private static class ChunkListPaginationBox extends PaginationBox { } @Override - public Component getComponent(int number) { - return TextComponent.of(chunks.get(number).toString()); + public Component component(int number) { + return Component.text(chunks.get(number).toString()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 69c497fd85..c25c963746 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -43,13 +43,10 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; @@ -107,7 +104,7 @@ public void copy(Actor actor, LocalSession session, EditSession editSession, Operations.completeLegacy(copy); session.setClipboard(new ClipboardHolder(clipboard)); - copy.getStatusMessages().forEach(actor::print); + copy.getMessages().forEach(actor::print); } @Command( @@ -140,7 +137,7 @@ public void cut(Actor actor, LocalSession session, EditSession editSession, Operations.completeLegacy(copy); session.setClipboard(new ClipboardHolder(clipboard)); - copy.getStatusMessages().forEach(actor::print); + copy.getMessages().forEach(actor::print); } @Command( @@ -185,7 +182,7 @@ public void paste(Actor actor, World world, LocalSession session, EditSession ed .maskSource(sourceMask) .build(); Operations.completeLegacy(operation); - messages.addAll(Lists.newArrayList(operation.getStatusMessages())); + messages.addAll(Lists.newArrayList(operation.getMessages())); } if (selectPasted || onlySelect) { @@ -204,9 +201,9 @@ public void paste(Actor actor, World world, LocalSession session, EditSession ed } if (onlySelect) { - actor.printInfo(TranslatableComponent.of("worldedit.paste.selected")); + actor.printInfo(Component.translatable("worldedit.paste.selected")); } else { - actor.printInfo(TranslatableComponent.of("worldedit.paste.pasted", TextComponent.of(to.toString()))); + actor.printInfo(Component.translatable("worldedit.paste.pasted", Component.text(to.toString()))); } messages.forEach(actor::print); } @@ -229,7 +226,7 @@ public void rotate(Actor actor, LocalSession session, if (Math.abs(rotateY % 90) > 0.001 || Math.abs(rotateX % 90) > 0.001 || Math.abs(rotateZ % 90) > 0.001) { - actor.printDebug(TranslatableComponent.of("worldedit.rotate.no-interpolation")); + actor.printDebug(Component.translatable("worldedit.rotate.no-interpolation")); } ClipboardHolder holder = session.getClipboard(); @@ -238,7 +235,7 @@ public void rotate(Actor actor, LocalSession session, transform = transform.rotateX(-rotateX); transform = transform.rotateZ(-rotateZ); holder.setTransform(holder.getTransform().combine(transform)); - actor.printInfo(TranslatableComponent.of("worldedit.rotate.rotated")); + actor.printInfo(Component.translatable("worldedit.rotate.rotated")); } @Command( @@ -253,7 +250,7 @@ public void flip(Actor actor, LocalSession session, AffineTransform transform = new AffineTransform(); transform = transform.scale(direction.abs().multiply(-2).add(1, 1, 1).toVector3()); holder.setTransform(holder.getTransform().combine(transform)); - actor.printInfo(TranslatableComponent.of("worldedit.flip.flipped")); + actor.printInfo(Component.translatable("worldedit.flip.flipped")); } @Command( @@ -263,6 +260,6 @@ public void flip(Actor actor, LocalSession session, @CommandPermissions("worldedit.clipboard.clear") public void clearClipboard(Actor actor, LocalSession session) { session.setClipboard(null); - actor.printInfo(TranslatableComponent.of("worldedit.clearclipboard.cleared")); + actor.printInfo(Component.translatable("worldedit.clearclipboard.cleared")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ExpandCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ExpandCommands.java index 4686f6607e..27e71d6ab0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ExpandCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ExpandCommands.java @@ -32,8 +32,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import org.enginehub.piston.Command; import org.enginehub.piston.CommandManager; @@ -73,8 +72,8 @@ public static void register(CommandRegistrationHandler registration, command.condition(new PermissionCondition(ImmutableSet.of("worldedit.selection.expand"))); command.addPart(SubCommandPart.builder( - TranslatableComponent.of("vert"), - TextComponent.of("Vertical expansion sub-command") + Component.translatable("vert"), + Component.text("Vertical expansion sub-command") ) .withCommands(ImmutableSet.of(createVertCommand(commandManager))) .optional() @@ -88,7 +87,7 @@ public static void register(CommandRegistrationHandler registration, private static Command createVertCommand(CommandManager commandManager) { return commandManager.newCommand("vert") - .description(TranslatableComponent.of("worldedit.expand.description.vert")) + .description(Component.translatable("worldedit.expand.description.vert")) .action(parameters -> { expandVert( requireIV(Key.of(LocalSession.class), "localSession", parameters), @@ -113,10 +112,10 @@ private static void expandVert(LocalSession session, Actor actor, World world) t session.getRegionSelector(world).explainRegionAdjust(actor, session); long changeSize = newSize - oldSize; actor.printInfo( - TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize)) + Component.translatable("worldedit.expand.expanded.vert", Component.text(changeSize)) ); } catch (RegionOperationException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); } } @@ -152,7 +151,7 @@ public void expand(Actor actor, World world, LocalSession session, session.getRegionSelector(world).explainRegionAdjust(actor, session); long changeSize = newSize - oldSize; - actor.printInfo(TranslatableComponent.of("worldedit.expand.expanded", TextComponent.of(changeSize))); + actor.printInfo(Component.translatable("worldedit.expand.expanded", Component.text(changeSize))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index 05a89bd409..3e112ceab7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -48,13 +48,11 @@ import com.sk89q.worldedit.session.PlacementType; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.auth.AuthorizationException; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.component.SideEffectBox; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; +import com.sk89q.worldedit.util.formatting.adventure.SideEffectBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.piston.CommandManager; @@ -121,7 +119,7 @@ private static Component replaceFastForPerf(org.enginehub.piston.Command oldCmd, } ImmutableList args = oldParams.getMetadata().getArguments(); if (args.isEmpty()) { - return TextComponent.of("There is not yet a replacement for //fast" + return Component.text("There is not yet a replacement for //fast" + " with no arguments"); } String arg0 = args.get(0).toLowerCase(Locale.ENGLISH); @@ -134,7 +132,7 @@ private static Component replaceFastForPerf(org.enginehub.piston.Command oldCmd, flipped = "on"; break; default: - return TextComponent.of("There is no replacement for //fast " + arg0); + return Component.text("There is no replacement for //fast " + arg0); } return CommandUtil.createNewCommandReplacementText("//perf " + flipped); } @@ -166,15 +164,15 @@ public void limit(Actor actor, LocalSession session, limit = limit == null ? config.defaultChangeLimit : Math.max(-1, limit); if (!mayDisable && config.maxChangeLimit > -1) { if (limit > config.maxChangeLimit) { - actor.printError(TranslatableComponent.of("worldedit.limit.too-high", TextComponent.of(config.maxChangeLimit))); + actor.printError(Component.translatable("worldedit.limit.too-high", Component.text(config.maxChangeLimit))); return; } } session.setBlockChangeLimit(limit); - Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.limit.set", TextComponent.of(limit))); + Component component = Component.empty().append(Component.translatable("worldedit.limit.set", Component.text(limit))); if (limit != config.defaultChangeLimit) { - component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", TextColor.GRAY)); + component = component.append(Component.space()).append(Component.translatable("worldedit.limit.return-to-default", NamedTextColor.GRAY)); } actor.printInfo(component); } @@ -193,15 +191,15 @@ public void timeout(Actor actor, LocalSession session, limit = limit == null ? config.calculationTimeout : Math.max(-1, limit); if (!mayDisable && config.maxCalculationTimeout > -1) { if (limit > config.maxCalculationTimeout) { - actor.printError(TranslatableComponent.of("worldedit.timeout.too-high", TextComponent.of(config.maxCalculationTimeout))); + actor.printError(Component.translatable("worldedit.timeout.too-high", Component.text(config.maxCalculationTimeout))); return; } } session.setTimeout(limit); - Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.timeout.set", TextComponent.of(limit))); + Component component = Component.empty().append(Component.translatable("worldedit.timeout.set", Component.text(limit))); if (limit != config.calculationTimeout) { - component.append(TranslatableComponent.of("worldedit.timeout.return-to-default", TextColor.GRAY)); + component = component.append(Component.translatable("worldedit.timeout.return-to-default", NamedTextColor.GRAY)); } actor.printInfo(component); } @@ -217,16 +215,16 @@ void fast(Actor actor, LocalSession session, Boolean fastMode) { boolean hasFastMode = session.hasFastMode(); if (fastMode != null && fastMode == hasFastMode) { - actor.printError(TranslatableComponent.of(fastMode ? "worldedit.fast.enabled.already" : "worldedit.fast.disabled.already")); + actor.printError(Component.translatable(fastMode ? "worldedit.fast.enabled.already" : "worldedit.fast.disabled.already")); return; } if (hasFastMode) { session.setFastMode(false); - actor.printInfo(TranslatableComponent.of("worldedit.fast.disabled")); + actor.printInfo(Component.translatable("worldedit.fast.disabled")); } else { session.setFastMode(true); - actor.printInfo(TranslatableComponent.of("worldedit.fast.enabled")); + actor.printInfo(Component.translatable("worldedit.fast.enabled")); } } @@ -248,10 +246,10 @@ void perf(Actor actor, LocalSession session, SideEffect.State currentState = session.getSideEffectSet().getState(sideEffect); if (newState != null && newState == currentState) { if (!showInfoBox) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.perf.sideeffect.already-set", - TranslatableComponent.of(sideEffect.getDisplayName()), - TranslatableComponent.of(newState.getDisplayName()) + Component.translatable(sideEffect.getDisplayName()), + Component.translatable(newState.getDisplayName()) )); } return; @@ -260,17 +258,17 @@ void perf(Actor actor, LocalSession session, if (newState != null) { session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState)); if (!showInfoBox) { - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.perf.sideeffect.set", - TranslatableComponent.of(sideEffect.getDisplayName()), - TranslatableComponent.of(newState.getDisplayName()) + Component.translatable(sideEffect.getDisplayName()), + Component.translatable(newState.getDisplayName()) )); } } else { - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.perf.sideeffect.get", - TranslatableComponent.of(sideEffect.getDisplayName()), - TranslatableComponent.of(currentState.getDisplayName()) + Component.translatable(sideEffect.getDisplayName()), + Component.translatable(currentState.getDisplayName()) )); } } else if (newState != null) { @@ -280,16 +278,16 @@ void perf(Actor actor, LocalSession session, } session.setSideEffectSet(applier); if (!showInfoBox) { - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.perf.sideeffect.set-all", - TranslatableComponent.of(newState.getDisplayName()) + Component.translatable(newState.getDisplayName()) )); } } if (sideEffect == null || showInfoBox) { SideEffectBox sideEffectBox = new SideEffectBox(session.getSideEffectSet()); - actor.print(sideEffectBox.create(1)); + actor.print(sideEffectBox.build(1)); } } @@ -313,7 +311,7 @@ void update(Actor actor, LocalSession session, World injectedWorld, RegionVisitor visitor = new RegionVisitor(session.getSelection(injectedWorld), apply); Operations.complete(visitor); - actor.printInfo(TranslatableComponent.of("worldedit.update")); + actor.printInfo(Component.translatable("worldedit.update")); } @Command( @@ -326,10 +324,10 @@ public void reorderMode(Actor actor, LocalSession session, @Arg(desc = "The reorder mode", def = "") EditSession.ReorderMode reorderMode) { if (reorderMode == null) { - actor.printInfo(TranslatableComponent.of("worldedit.reorder.current", TextComponent.of(session.getReorderMode().getDisplayName()))); + actor.printInfo(Component.translatable("worldedit.reorder.current", Component.text(session.getReorderMode().getDisplayName()))); } else { session.setReorderMode(reorderMode); - actor.printInfo(TranslatableComponent.of("worldedit.reorder.set", TextComponent.of(session.getReorderMode().getDisplayName()))); + actor.printInfo(Component.translatable("worldedit.reorder.set", Component.text(session.getReorderMode().getDisplayName()))); } } @@ -342,28 +340,28 @@ public void drawSelection(Player player, LocalSession session, @Arg(desc = "The new draw selection state", def = "") Boolean drawSelection) throws WorldEditException { if (!WorldEdit.getInstance().getConfiguration().serverSideCUI) { - throw new AuthorizationException(TranslatableComponent.of("worldedit.error.disabled")); + throw new AuthorizationException(Component.translatable("worldedit.error.disabled")); } boolean useServerCui = session.shouldUseServerCUI(); if (drawSelection != null && drawSelection == useServerCui) { - player.printError(TranslatableComponent.of("worldedit.drawsel." + (useServerCui ? "enabled" : "disabled") + ".already")); + player.printError(Component.translatable("worldedit.drawsel." + (useServerCui ? "enabled" : "disabled") + ".already")); return; } if (useServerCui) { session.setUseServerCUI(false); session.updateServerCUI(player); - player.printInfo(TranslatableComponent.of("worldedit.drawsel.disabled")); + player.printInfo(Component.translatable("worldedit.drawsel.disabled")); } else { session.setUseServerCUI(true); session.updateServerCUI(player); int maxSize = ServerCUIHandler.getMaxServerCuiSize(); - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.drawsel.enabled", - TextComponent.of(maxSize), - TextComponent.of(maxSize), - TextComponent.of(maxSize) + Component.text(maxSize), + Component.text(maxSize), + Component.text(maxSize) )); } } @@ -377,9 +375,9 @@ public void world(Actor actor, LocalSession session, @Arg(desc = "The world override", def = "") World world) { session.setWorldOverride(world); if (world == null) { - actor.printInfo(TranslatableComponent.of("worldedit.world.remove")); + actor.printInfo(Component.translatable("worldedit.world.remove")); } else { - actor.printInfo(TranslatableComponent.of("worldedit.world.set", TextComponent.of(world.getId()))); + actor.printInfo(Component.translatable("worldedit.world.set", Component.text(world.getId()))); } } @@ -394,16 +392,16 @@ public void watchdog(Actor actor, LocalSession session, @Arg(desc = "The mode to set the watchdog hook to", def = "") HookMode hookMode) { if (WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWatchdog() == null) { - actor.printError(TranslatableComponent.of("worldedit.watchdog.no-hook")); + actor.printError(Component.translatable("worldedit.watchdog.no-hook")); return; } boolean previousMode = session.isTickingWatchdog(); if (hookMode != null && (hookMode == HookMode.ACTIVE) == previousMode) { - actor.printError(TranslatableComponent.of(previousMode ? "worldedit.watchdog.active.already" : "worldedit.watchdog.inactive.already")); + actor.printError(Component.translatable(previousMode ? "worldedit.watchdog.active.already" : "worldedit.watchdog.inactive.already")); return; } session.setTickingWatchdog(!previousMode); - actor.printInfo(TranslatableComponent.of(previousMode ? "worldedit.watchdog.inactive" : "worldedit.watchdog.active")); + actor.printInfo(Component.translatable(previousMode ? "worldedit.watchdog.inactive" : "worldedit.watchdog.active")); } @Command( @@ -417,21 +415,21 @@ public void gmask(Actor actor, LocalSession session, Mask mask) { if (mask == null) { session.setMask(null); - actor.printInfo(TranslatableComponent.of("worldedit.gmask.disabled")); + actor.printInfo(Component.translatable("worldedit.gmask.disabled")); } else { session.setMask(mask); - actor.printInfo(TranslatableComponent.of("worldedit.gmask.set")); + actor.printInfo(Component.translatable("worldedit.gmask.set")); } } private static void placementImpl(Actor actor, LocalSession session, Placement placement) { if (!placement.canBeUsedBy(actor)) { - actor.printError(TranslatableComponent.of("worldedit.toggleplace.not-locatable")); + actor.printError(Component.translatable("worldedit.toggleplace.not-locatable")); return; } session.setPlacement(placement); - actor.printInfo(placement.getInfo()); + actor.printInfo(placement.getInformation()); } @Command( @@ -463,7 +461,7 @@ public void placement(Actor actor, LocalSession session, offset = offset.multiply(multiplier); if (placementType == PlacementType.HERE) { if (!placementType.canBeUsedBy(actor)) { - actor.printError(TranslatableComponent.of("worldedit.toggleplace.not-locatable")); + actor.printError(Component.translatable("worldedit.toggleplace.not-locatable")); return; } // Replace "//placement here" by "//placement " @@ -490,16 +488,16 @@ public void searchItem(Actor actor, List query) { String search = String.join(" ", query); if (search.length() <= 2) { - actor.printError(TranslatableComponent.of("worldedit.searchitem.too-short")); + actor.printError(Component.translatable("worldedit.searchitem.too-short")); return; } if (blocksOnly && itemsOnly) { - actor.printError(TranslatableComponent.of("worldedit.searchitem.either-b-or-i")); + actor.printError(Component.translatable("worldedit.searchitem.either-b-or-i")); return; } WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page), - TranslatableComponent.of("worldedit.searchitem.searching")); + Component.translatable("worldedit.searchitem.searching")); } private static class ItemSearcher implements Callable { @@ -531,16 +529,16 @@ public Component call() throws Exception { } final String id = searchType.getId(); if (id.contains(idMatch)) { - Component name = searchType.getRichName(); - results.put(id, TextComponent.builder() + Component name = searchType.getDisplayName(); + results.put(id, Component.text() .append(name) - .append(" (" + id + ")") + .append(Component.text(" (" + id + ")")) .build()); } } List list = new ArrayList<>(results.values()); - return PaginationBox.fromComponents("Search results for '" + search + "'", command, list) - .create(page); + return PaginationBox.fromText("Search results for '" + search + "'", command, list) + .build(page); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index acbb0a8b5b..d2fc3d40b3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -36,8 +36,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator.TreeType; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.generation.ConfiguredFeatureType; import com.sk89q.worldedit.world.generation.StructureType; @@ -118,7 +117,7 @@ public int cyl(Actor actor, LocalSession session, EditSession editSession, break; default: - actor.printError(TranslatableComponent.of("worldedit.cyl.invalid-radius")); + actor.printError(Component.translatable("worldedit.cyl.invalid-radius")); return 0; } @@ -128,7 +127,7 @@ public int cyl(Actor actor, LocalSession session, EditSession editSession, BlockVector3 pos = session.getPlacementPosition(actor); int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow); - actor.printInfo(TranslatableComponent.of("worldedit.cyl.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.cyl.created", Component.text(affected))); return affected; } @@ -160,7 +159,7 @@ public int cone(Actor actor, LocalSession session, EditSession editSession, radiusZ = Math.max(1, radii.get(1)); } default -> { - actor.printError(TranslatableComponent.of("worldedit.cone.invalid-radius")); + actor.printError(Component.translatable("worldedit.cone.invalid-radius")); return 0; } } @@ -171,7 +170,7 @@ public int cone(Actor actor, LocalSession session, EditSession editSession, BlockVector3 pos = session.getPlacementPosition(actor); int affected = editSession.makeCone(pos, pattern, radiusX, radiusZ, height, !hollow, thickness); - actor.printInfo(TranslatableComponent.of("worldedit.cone.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.cone.created", Component.text(affected))); return affected; } @@ -223,7 +222,7 @@ public int sphere(Actor actor, LocalSession session, EditSession editSession, break; default: - actor.printError(TranslatableComponent.of("worldedit.sphere.invalid-radius")); + actor.printError(Component.translatable("worldedit.sphere.invalid-radius")); return 0; } @@ -240,7 +239,7 @@ public int sphere(Actor actor, LocalSession session, EditSession editSession, if (actor instanceof Player) { ((Player) actor).findFreePosition(); } - actor.printInfo(TranslatableComponent.of("worldedit.sphere.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.sphere.created", Component.text(affected))); return affected; } @@ -261,7 +260,7 @@ public int forestGen(Actor actor, LocalSession session, EditSession editSession, worldEdit.checkMaxRadius(size); density /= 100; int affected = editSession.makeForest(session.getPlacementPosition(actor), size, density, type); - actor.printInfo(TranslatableComponent.of("worldedit.forestgen.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.forestgen.created", Component.text(affected))); return affected; } @@ -276,7 +275,7 @@ public int pumpkins(Actor actor, LocalSession session, EditSession editSession, int size) throws WorldEditException { worldEdit.checkMaxRadius(size); int affected = editSession.makePumpkinPatches(session.getPlacementPosition(actor), size); - actor.printInfo(TranslatableComponent.of("worldedit.pumpkins.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.pumpkins.created", Component.text(affected))); return affected; } @@ -290,9 +289,9 @@ public int feature(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The feature") ConfiguredFeatureType feature) throws WorldEditException { if (editSession.getWorld().generateFeature(feature, editSession, session.getPlacementPosition(actor))) { - actor.printInfo(TranslatableComponent.of("worldedit.feature.created")); + actor.printInfo(Component.translatable("worldedit.feature.created")); } else { - actor.printError(TranslatableComponent.of("worldedit.feature.failed")); + actor.printError(Component.translatable("worldedit.feature.failed")); } return 0; } @@ -307,9 +306,9 @@ public int structure(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The structure") StructureType feature) throws WorldEditException { if (editSession.getWorld().generateStructure(feature, editSession, session.getPlacementPosition(actor))) { - actor.printInfo(TranslatableComponent.of("worldedit.structure.created")); + actor.printInfo(Component.translatable("worldedit.structure.created")); } else { - actor.printError(TranslatableComponent.of("worldedit.structure.failed")); + actor.printError(Component.translatable("worldedit.structure.failed")); } return 0; } @@ -347,7 +346,7 @@ public int pyramid(Actor actor, LocalSession session, EditSession editSession, if (actor instanceof Player) { ((Player) actor).findFreePosition(); } - actor.printInfo(TranslatableComponent.of("worldedit.pyramid.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.pyramid.created", Component.text(affected))); return affected; } @@ -412,10 +411,10 @@ public int generate(Actor actor, LocalSession session, EditSession editSession, if (actor instanceof Player) { ((Player) actor).findFreePosition(); } - actor.printInfo(TranslatableComponent.of("worldedit.generate.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.generate.created", Component.text(affected))); return affected; } catch (ExpressionException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); return 0; } } @@ -477,10 +476,10 @@ public int generateBiome(Actor actor, LocalSession session, EditSession editSess try { final int affected = editSession.makeBiomeShape(region, zero, unit, target, String.join(" ", expression), hollow, session.getTimeout()); - actor.printInfo(TranslatableComponent.of("worldedit.generatebiome.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.generatebiome.changed", Component.text(affected))); return affected; } catch (ExpressionException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); return 0; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 4d35750116..605f9fe818 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -28,8 +28,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.inventory.BlockBag; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -71,7 +70,7 @@ public void undo(Actor actor, LocalSession session, actor.checkPermission("worldedit.history.undo.other"); undoSession = worldEdit.getSessionManager().findByName(playerName); if (undoSession == null) { - actor.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName))); + actor.printError(Component.translatable("worldedit.session.cant-find-session", Component.text(playerName))); return; } } @@ -87,9 +86,9 @@ public void undo(Actor actor, LocalSession session, } } if (timesUndone > 0) { - actor.printInfo(TranslatableComponent.of("worldedit.undo.undone", TextComponent.of(timesUndone))); + actor.printInfo(Component.translatable("worldedit.undo.undone", Component.text(timesUndone))); } else { - actor.printError(TranslatableComponent.of("worldedit.undo.none")); + actor.printError(Component.translatable("worldedit.undo.none")); } } @@ -110,7 +109,7 @@ public void redo(Actor actor, LocalSession session, actor.checkPermission("worldedit.history.redo.other"); redoSession = worldEdit.getSessionManager().findByName(playerName); if (redoSession == null) { - actor.printError(TranslatableComponent.of("worldedit.session.cant-find-session", TextComponent.of(playerName))); + actor.printError(Component.translatable("worldedit.session.cant-find-session", Component.text(playerName))); return; } } @@ -126,9 +125,9 @@ public void redo(Actor actor, LocalSession session, } } if (timesRedone > 0) { - actor.printInfo(TranslatableComponent.of("worldedit.redo.redone", TextComponent.of(timesRedone))); + actor.printInfo(Component.translatable("worldedit.redo.redone", Component.text(timesRedone))); } else { - actor.printError(TranslatableComponent.of("worldedit.redo.none")); + actor.printError(Component.translatable("worldedit.redo.none")); } } @@ -140,7 +139,7 @@ public void redo(Actor actor, LocalSession session, @CommandPermissions("worldedit.history.clear") public void clearHistory(Actor actor, LocalSession session) { session.clearHistory(); - actor.printInfo(TranslatableComponent.of("worldedit.clearhistory.cleared")); + actor.printInfo(Component.translatable("worldedit.clearhistory.cleared")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java index 666d582fb5..e5ee2ccbf2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/InsufficientArgumentsException.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.command; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; public class InsufficientArgumentsException extends WorldEditException { @@ -29,6 +30,11 @@ public InsufficientArgumentsException(String error) { super(error); } + @Deprecated + public InsufficientArgumentsException(com.sk89q.worldedit.util.formatting.text.Component error) { + super(LegacyTextHelper.adapt(error)); + } + public InsufficientArgumentsException(Component error) { super(error); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java index 499971396e..c500ed41ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java @@ -26,13 +26,11 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; import com.sk89q.worldedit.world.snapshot.Snapshot; @@ -65,9 +63,9 @@ void list(Actor actor, World world, int page) throws WorldEditException { List snapshots = config.snapshotRepo.getSnapshots(true, world.getName()); if (!snapshots.isEmpty()) { - actor.print(new SnapshotListBox(world.getName(), snapshots).create(page)); + actor.print(new SnapshotListBox(world.getName(), snapshots).build(page)); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.none-found-console")); + actor.printError(Component.translatable("worldedit.restore.none-found-console")); // Okay, let's toss some debugging information! File dir = config.snapshotRepo.getDirectory(); @@ -82,7 +80,7 @@ void list(Actor actor, World world, int page) throws WorldEditException { } } } catch (MissingWorldException ex) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } @@ -96,19 +94,19 @@ void use(Actor actor, World world, LocalSession session, String name) { if (snapshot != null) { session.setSnapshot(null); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest")); + actor.printInfo(Component.translatable("worldedit.snapshot.use.newest")); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.none-found")); + actor.printError(Component.translatable("worldedit.restore.none-found")); } } catch (MissingWorldException ex) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } else { try { session.setSnapshot(config.snapshotRepo.getSnapshot(name)); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(name))); + actor.printInfo(Component.translatable("worldedit.snapshot.use", Component.text(name))); } catch (InvalidSnapshotException e) { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); } } } @@ -117,25 +115,25 @@ void sel(Actor actor, World world, LocalSession session, int index) { LocalConfiguration config = we.getConfiguration(); if (index < 1) { - actor.printError(TranslatableComponent.of("worldedit.snapshot.index-above-0")); + actor.printError(Component.translatable("worldedit.snapshot.index-above-0")); return; } try { List snapshots = config.snapshotRepo.getSnapshots(true, world.getName()); if (snapshots.size() < index) { - actor.printError(TranslatableComponent.of("worldedit.snapshot.index-oob", TextComponent.of(snapshots.size()))); + actor.printError(Component.translatable("worldedit.snapshot.index-oob", Component.text(snapshots.size()))); return; } Snapshot snapshot = snapshots.get(index - 1); if (snapshot == null) { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); return; } session.setSnapshot(snapshot); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); + actor.printInfo(Component.translatable("worldedit.snapshot.use", Component.text(snapshot.getName()))); } catch (MissingWorldException e) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } @@ -146,16 +144,16 @@ void before(Actor actor, World world, LocalSession session, ZonedDateTime date) Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, world.getName()); if (snapshot == null) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.snapshot.none-before", - TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) + Component.text(dateFormat.withZone(session.getTimeZone()).format(date))) ); } else { session.setSnapshot(snapshot); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); + actor.printInfo(Component.translatable("worldedit.snapshot.use", Component.text(snapshot.getName()))); } } catch (MissingWorldException ex) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } @@ -165,16 +163,16 @@ void after(Actor actor, World world, LocalSession session, ZonedDateTime date) { try { Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, world.getName()); if (snapshot == null) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.snapshot.none-after", - TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) + Component.text(dateFormat.withZone(session.getTimeZone()).format(date))) ); } else { session.setSnapshot(snapshot); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); + actor.printInfo(Component.translatable("worldedit.snapshot.use", Component.text(snapshot.getName()))); } } catch (MissingWorldException ex) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } @@ -187,12 +185,12 @@ private static class SnapshotListBox extends PaginationBox { } @Override - public Component getComponent(int number) { + public Component component(int number) { final Snapshot snapshot = snapshots.get(number); - return TextComponent.of(number + 1 + ". ", TextColor.GOLD) - .append(TextComponent.of(snapshot.getName(), TextColor.LIGHT_PURPLE) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to use"))) - .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/snap use " + snapshot.getName()))); + return Component.text(number + 1 + ". ", NamedTextColor.GOLD) + .append(Component.text(snapshot.getName(), NamedTextColor.LIGHT_PURPLE) + .hoverEvent(HoverEvent.showText(Component.text("Click to use"))) + .clickEvent(ClickEvent.runCommand("/snap use " + snapshot.getName()))); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotUtilCommands.java index 2978410398..6c4ae5cb52 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotUtilCommands.java @@ -26,8 +26,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; @@ -58,7 +57,7 @@ void restore(Actor actor, World world, LocalSession session, EditSession editSes try { snapshot = config.snapshotRepo.getSnapshot(snapshotName); } catch (InvalidSnapshotException e) { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); return; } } else { @@ -71,7 +70,7 @@ void restore(Actor actor, World world, LocalSession session, EditSession editSes snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName()); if (snapshot == null) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-found-console")); + actor.printError(Component.translatable("worldedit.restore.none-found-console")); // Okay, let's toss some debugging information! File dir = config.snapshotRepo.getDirectory(); @@ -88,7 +87,7 @@ void restore(Actor actor, World world, LocalSession session, EditSession editSes return; } } catch (MissingWorldException ex) { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); return; } } @@ -98,9 +97,9 @@ void restore(Actor actor, World world, LocalSession session, EditSession editSes // Load chunk store try { chunkStore = snapshot.getChunkStore(); - actor.printInfo(TranslatableComponent.of("worldedit.restore.loaded", TextComponent.of(snapshot.getName()))); + actor.printInfo(Component.translatable("worldedit.restore.loaded", Component.text(snapshot.getName()))); } catch (DataException | IOException e) { - actor.printError(TranslatableComponent.of("worldedit.restore.failed", TextComponent.of(e.getMessage()))); + actor.printError(Component.translatable("worldedit.restore.failed", Component.text(e.getMessage()))); return; } @@ -114,17 +113,17 @@ void restore(Actor actor, World world, LocalSession session, EditSession editSes if (restore.hadTotalFailure()) { String error = restore.getLastErrorMessage(); if (!restore.getMissingChunks().isEmpty()) { - actor.printError(TranslatableComponent.of("worldedit.restore.chunk-not-present")); + actor.printError(Component.translatable("worldedit.restore.chunk-not-present")); } else if (error != null) { - actor.printError(TranslatableComponent.of("worldedit.restore.block-place-failed")); - actor.printError(TranslatableComponent.of("worldedit.restore.block-place-error", TextComponent.of(error))); + actor.printError(Component.translatable("worldedit.restore.block-place-failed")); + actor.printError(Component.translatable("worldedit.restore.block-place-error", Component.text(error))); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.chunk-load-failed")); + actor.printError(Component.translatable("worldedit.restore.chunk-load-failed")); } } else { - actor.printInfo(TranslatableComponent.of("worldedit.restore.restored", - TextComponent.of(restore.getMissingChunks().size()), - TextComponent.of(restore.getErrorChunks().size()))); + actor.printInfo(Component.translatable("worldedit.restore.restored", + Component.text(restore.getMissingChunks().size()), + Component.text(restore.getErrorChunks().size()))); } } finally { try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java index 2756309202..2850fc285d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java @@ -27,8 +27,7 @@ import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -63,7 +62,7 @@ public NavigationCommands(WorldEdit worldEdit) { @CommandPermissions("worldedit.navigation.unstuck") public void unstuck(Player player) throws WorldEditException { player.findFreePosition(); - player.printInfo(TranslatableComponent.of("worldedit.unstuck.moved")); + player.printInfo(Component.translatable("worldedit.unstuck.moved")); } @Command( @@ -83,9 +82,9 @@ public void ascend(Player player, } } if (ascentLevels == 0) { - player.printError(TranslatableComponent.of("worldedit.ascend.obstructed")); + player.printError(Component.translatable("worldedit.ascend.obstructed")); } else { - player.printInfo(TranslatableComponent.of("worldedit.ascend.moved", TextComponent.of(ascentLevels))); + player.printInfo(Component.translatable("worldedit.ascend.moved", Component.text(ascentLevels))); } } @@ -106,9 +105,9 @@ public void descend(Player player, } } if (descentLevels == 0) { - player.printError(TranslatableComponent.of("worldedit.descend.obstructed")); + player.printError(Component.translatable("worldedit.descend.obstructed")); } else { - player.printInfo(TranslatableComponent.of("worldedit.descend.moved", TextComponent.of(descentLevels))); + player.printInfo(Component.translatable("worldedit.descend.moved", Component.text(descentLevels))); } } @@ -129,9 +128,9 @@ public void ceiling(Player player, boolean alwaysGlass = getAlwaysGlass(forceFlight, forceGlass); if (player.ascendToCeiling(clearance, alwaysGlass)) { - player.printInfo(TranslatableComponent.of("worldedit.ceil.moved")); + player.printInfo(Component.translatable("worldedit.ceil.moved")); } else { - player.printError(TranslatableComponent.of("worldedit.ceil.obstructed")); + player.printError(Component.translatable("worldedit.ceil.obstructed")); } } @@ -142,9 +141,9 @@ public void ceiling(Player player, @CommandPermissions("worldedit.navigation.thru.command") public void thru(Player player) throws WorldEditException { if (player.passThroughForwardWall(6)) { - player.printInfo(TranslatableComponent.of("worldedit.thru.moved")); + player.printInfo(Component.translatable("worldedit.thru.moved")); } else { - player.printError(TranslatableComponent.of("worldedit.thru.obstructed")); + player.printError(Component.translatable("worldedit.thru.obstructed")); } } @@ -159,9 +158,9 @@ public void jumpTo(Player player) throws WorldEditException { Location pos = player.getSolidBlockTrace(300); if (pos != null) { player.findFreePosition(pos); - player.printInfo(TranslatableComponent.of("worldedit.jumpto.moved")); + player.printInfo(Component.translatable("worldedit.jumpto.moved")); } else { - player.printError(TranslatableComponent.of("worldedit.jumpto.none")); + player.printError(Component.translatable("worldedit.jumpto.none")); } } @@ -180,9 +179,9 @@ public void up(Player player, boolean forceGlass) throws WorldEditException { boolean alwaysGlass = getAlwaysGlass(forceFlight, forceGlass); if (player.ascendUpwards(distance, alwaysGlass)) { - player.printInfo(TranslatableComponent.of("worldedit.up.moved")); + player.printInfo(Component.translatable("worldedit.up.moved")); } else { - player.printError(TranslatableComponent.of("worldedit.up.obstructed")); + player.printError(Component.translatable("worldedit.up.obstructed")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java index 5395249a14..87fe8b1123 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java @@ -39,10 +39,9 @@ import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.regions.factory.RegionFactory; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; -import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; import org.enginehub.piston.CommandParameters; @@ -61,24 +60,24 @@ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class PaintBrushCommands { - private static final CommandArgument REGION_FACTORY = arg(TranslatableComponent.of("shape"), TranslatableComponent.of("worldedit.brush.paint.shape")) + private static final CommandArgument REGION_FACTORY = arg(Component.translatable("shape"), Component.translatable("worldedit.brush.paint.shape")) .defaultsTo(ImmutableList.of()) .ofTypes(ImmutableList.of(Key.of(RegionFactory.class))) .build(); - private static final CommandArgument RADIUS = arg(TranslatableComponent.of("radius"), TranslatableComponent.of("worldedit.brush.paint.size")) + private static final CommandArgument RADIUS = arg(Component.translatable("radius"), Component.translatable("worldedit.brush.paint.size")) .defaultsTo(ImmutableList.of("5")) .ofTypes(ImmutableList.of(Key.of(double.class))) .build(); - private static final CommandArgument DENSITY = arg(TranslatableComponent.of("density"), TranslatableComponent.of("worldedit.brush.paint.density")) + private static final CommandArgument DENSITY = arg(Component.translatable("density"), Component.translatable("worldedit.brush.paint.density")) .defaultsTo(ImmutableList.of("20")) .ofTypes(ImmutableList.of(Key.of(double.class))) .build(); public static void register(CommandManagerService service, CommandManager commandManager, CommandRegistrationHandler registration) { commandManager.register("paint", builder -> { - builder.description(TranslatableComponent.of("worldedit.brush.paint.description")); + builder.description(Component.translatable("worldedit.brush.paint.description")); builder.action(org.enginehub.piston.Command.Action.NULL_ACTION); CommandManager manager = service.newCommandManager(); @@ -91,7 +90,7 @@ public static void register(CommandManagerService service, CommandManager comman builder.condition(new PermissionCondition(ImmutableSet.of("worldedit.brush.paint"))); builder.addParts(REGION_FACTORY, RADIUS, DENSITY); - builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TranslatableComponent.of("worldedit.brush.paint.type")) + builder.addPart(SubCommandPart.builder(Component.translatable("type"), Component.translatable("worldedit.brush.paint.type")) .withCommands(manager.getAllCommands().collect(Collectors.toList())) .required() .build()); @@ -130,8 +129,8 @@ public void item(CommandParameters parameters, @Arg(desc = "The direction in which the item will be applied", def = "up") @Direction(includeDiagonals = true) com.sk89q.worldedit.util.Direction direction) throws WorldEditException { - player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD) - .append(TranslatableComponent.of("worldedit.brush.paint.item.warning")).build()); + player.print(Component.text("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD) + .append(Component.translatable("worldedit.brush.paint.item.warning"))); setPaintBrush(parameters, player, localSession, new ItemUseFactory(item, direction)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 7425e59376..c63b60a612 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -56,10 +56,8 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.util.TreeGenerator.TreeType; -import com.sk89q.worldedit.util.formatting.component.TextUtils; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.JoinConfiguration; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.World; import org.enginehub.piston.annotation.Command; @@ -105,11 +103,12 @@ public int set(Actor actor, EditSession editSession, RegionVisitor visitor = new RegionVisitor(region, set); Operations.completeBlindly(visitor); - List messages = Lists.newArrayList(visitor.getStatusMessages()); + List messages = Lists.newArrayList(visitor.getMessages()); if (messages.isEmpty()) { - actor.printInfo(TranslatableComponent.of("worldedit.set.done")); + actor.printInfo(Component.translatable("worldedit.set.done")); } else { - actor.printInfo(TranslatableComponent.of("worldedit.set.done.verbose", TextUtils.join(messages, TextComponent.of(", ")))); + actor.printInfo(Component.translatable("worldedit.set.done.verbose", + Component.join(JoinConfiguration.separator(Component.text(", ")), messages))); } return visitor.getAffected(); @@ -131,7 +130,7 @@ public int line(Actor actor, EditSession editSession, @Switch(name = 'h', desc = "Generate only a shell") boolean shell) throws WorldEditException { if (!((region instanceof CuboidRegion) || (region instanceof ConvexPolyhedralRegion))) { - actor.printError(TranslatableComponent.of("worldedit.line.invalid-type")); + actor.printError(Component.translatable("worldedit.line.invalid-type")); return 0; } checkCommandArgument(thickness >= 0, "Thickness must be >= 0"); @@ -148,7 +147,7 @@ public int line(Actor actor, EditSession editSession, int blocksChanged = editSession.drawLine(pattern, vectors, thickness, !shell); - actor.printInfo(TranslatableComponent.of("worldedit.line.changed", TextComponent.of(blocksChanged))); + actor.printInfo(Component.translatable("worldedit.line.changed", Component.text(blocksChanged))); return blocksChanged; } @@ -168,7 +167,7 @@ public int curve(Actor actor, EditSession editSession, @Switch(name = 'h', desc = "Generate only a shell") boolean shell) throws WorldEditException { if (!(region instanceof ConvexPolyhedralRegion)) { - actor.printError(TranslatableComponent.of("worldedit.curve.invalid-type")); + actor.printError(Component.translatable("worldedit.curve.invalid-type")); return 0; } checkCommandArgument(thickness >= 0, "Thickness must be >= 0"); @@ -178,7 +177,7 @@ public int curve(Actor actor, EditSession editSession, int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell); - actor.printInfo(TranslatableComponent.of("worldedit.curve.changed", TextComponent.of(blocksChanged))); + actor.printInfo(Component.translatable("worldedit.curve.changed", Component.text(blocksChanged))); return blocksChanged; } @@ -198,7 +197,7 @@ public int replace(Actor actor, EditSession editSession, @Selection Region regio from = new ExistingBlockMask(editSession); } int affected = editSession.replaceBlocks(region, from, to); - actor.printInfo(TranslatableComponent.of("worldedit.replace.replaced", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.replace.replaced", Component.text(affected))); return affected; } @@ -212,7 +211,7 @@ public int overlay(Actor actor, EditSession editSession, @Selection Region regio @Arg(desc = "The pattern of blocks to overlay") Pattern pattern) throws WorldEditException { int affected = editSession.overlayCuboidBlocks(region, pattern); - actor.printInfo(TranslatableComponent.of("worldedit.overlay.overlaid", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.overlay.overlaid", Component.text(affected))); return affected; } @@ -227,7 +226,7 @@ public int center(Actor actor, EditSession editSession, @Selection Region region @Arg(desc = "The pattern of blocks to set") Pattern pattern) throws WorldEditException { int affected = editSession.center(region, pattern); - actor.printInfo(TranslatableComponent.of("worldedit.center.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.center.changed", Component.text(affected))); return affected; } @@ -239,7 +238,7 @@ public int center(Actor actor, EditSession editSession, @Selection Region region @Logging(REGION) public int naturalize(Actor actor, EditSession editSession, @Selection Region region) throws WorldEditException { int affected = editSession.naturalizeCuboidBlocks(region); - actor.printInfo(TranslatableComponent.of("worldedit.naturalize.naturalized", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.naturalize.naturalized", Component.text(affected))); return affected; } @@ -253,7 +252,7 @@ public int walls(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") Pattern pattern) throws WorldEditException { int affected = editSession.makeWalls(region, pattern); - actor.printInfo(TranslatableComponent.of("worldedit.walls.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.walls.changed", Component.text(affected))); return affected; } @@ -268,7 +267,7 @@ public int faces(Actor actor, EditSession editSession, @Selection Region region, @Arg(desc = "The pattern of blocks to set") Pattern pattern) throws WorldEditException { int affected = editSession.makeFaces(region, pattern); - actor.printInfo(TranslatableComponent.of("worldedit.faces.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.faces.changed", Component.text(affected))); return affected; } @@ -287,7 +286,7 @@ public int smooth(Actor actor, EditSession editSession, @Selection Region region HeightMap heightMap = new HeightMap(editSession, region, mask); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); int affected = heightMap.applyFilter(filter, iterations); - actor.printInfo(TranslatableComponent.of("worldedit.smooth.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.smooth.changed", Component.text(affected))); return affected; } @@ -309,7 +308,7 @@ public int snowSmooth(Actor actor, EditSession editSession, @Selection Region re HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); float[] changed = heightMap.applyFilter(filter, iterations); int affected = heightMap.applyChanges(changed, snowBlockCount); - actor.printInfo(TranslatableComponent.of("worldedit.snowsmooth.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.snowsmooth.changed", Component.text(affected))); return affected; } @@ -364,7 +363,7 @@ public int move(Actor actor, World world, EditSession editSession, LocalSession } } - actor.printInfo(TranslatableComponent.of("worldedit.move.moved", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.move.moved", Component.text(affected))); return affected; } @@ -428,7 +427,7 @@ public int stack(Actor actor, World world, EditSession editSession, LocalSession } } - actor.printInfo(TranslatableComponent.of("worldedit.stack.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.stack.changed", Component.text(affected))); return affected; } @@ -457,9 +456,9 @@ void regenerate(Actor actor, World world, LocalSession session, EditSession edit session.setMask(mask); } if (success) { - actor.printInfo(TranslatableComponent.of("worldedit.regen.regenerated")); + actor.printInfo(Component.translatable("worldedit.regen.regenerated")); } else { - actor.printError(TranslatableComponent.of("worldedit.regen.failed")); + actor.printError(Component.translatable("worldedit.regen.failed")); } } @@ -520,10 +519,10 @@ public int deform(Actor actor, LocalSession session, EditSession editSession, if (actor instanceof Player) { ((Player) actor).findFreePosition(); } - actor.printInfo(TranslatableComponent.of("worldedit.deform.deformed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.deform.deformed", Component.text(affected))); return affected; } catch (ExpressionException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); return 0; } } @@ -544,7 +543,7 @@ public int hollow(Actor actor, EditSession editSession, checkCommandArgument(thickness >= 0, "Thickness must be >= 0"); int affected = editSession.hollowOutRegion(region, thickness, pattern); - actor.printInfo(TranslatableComponent.of("worldedit.hollow.changed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.hollow.changed", Component.text(affected))); return affected; } @@ -561,7 +560,7 @@ public int forest(Actor actor, EditSession editSession, @Selection Region region double density) throws WorldEditException { checkCommandArgument(0 <= density && density <= 100, "Density must be in [0, 100]"); int affected = editSession.makeForest(region, density / 100, type); - actor.printInfo(TranslatableComponent.of("worldedit.forest.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.forest.created", Component.text(affected))); return affected; } @@ -583,7 +582,7 @@ public int flora(Actor actor, EditSession editSession, @Selection Region region, Operations.completeLegacy(visitor); int affected = ground.getAffected(); - actor.printInfo(TranslatableComponent.of("worldedit.flora.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.flora.created", Component.text(affected))); return affected; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index eba358dd33..55bbb6e0fc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -42,16 +42,11 @@ import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.formatting.component.CodeFormat; -import com.sk89q.worldedit.util.formatting.component.ErrorFormat; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.component.SubtleFormat; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.util.io.file.MorePaths; @@ -120,7 +115,7 @@ public void load(Actor actor, LocalSession session, ClipboardFormats.getFileExtensionArray()); if (!f.exists()) { - actor.printError(TranslatableComponent.of("worldedit.schematic.load.does-not-exist", TextComponent.of(filename))); + actor.printError(Component.translatable("worldedit.schematic.load.does-not-exist", Component.text(filename))); return; } @@ -132,11 +127,11 @@ public void load(Actor actor, LocalSession session, SchematicLoadTask task = new SchematicLoadTask(actor, f, format); AsyncCommandBuilder.wrap(task, actor) .registerWithSupervisor(worldEdit.getSupervisor(), "Loading schematic " + filename) - .setDelayMessage(TranslatableComponent.of("worldedit.schematic.load.loading")) - .setWorkingMessage(TranslatableComponent.of("worldedit.schematic.load.still-loading")) - .onSuccess(TextComponent.of(filename, TextColor.GOLD) - .append(TextComponent.of(" loaded. Paste it with ", TextColor.LIGHT_PURPLE)) - .append(CodeFormat.wrap("//paste").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "//paste"))), + .setDelayMessage(Component.translatable("worldedit.schematic.load.loading")) + .setWorkingMessage(Component.translatable("worldedit.schematic.load.still-loading")) + .onSuccess(Component.text(filename, NamedTextColor.GOLD) + .append(Component.text(" loaded. Paste it with ", NamedTextColor.LIGHT_PURPLE)) + .append(Component.text("//paste", NamedTextColor.AQUA).clickEvent(ClickEvent.suggestCommand("//paste"))), session::setClipboard) .onFailure("Failed to load schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) .buildAndExec(worldEdit.getExecutorService()); @@ -155,7 +150,7 @@ public void save(Actor actor, LocalSession session, @Switch(name = 'f', desc = "Overwrite an existing file.") boolean allowOverwrite) throws WorldEditException { if (worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getDataVersion() == -1) { - actor.printError(TranslatableComponent.of("worldedit.schematic.unsupported-minecraft-version")); + actor.printError(Component.translatable("worldedit.schematic.unsupported-minecraft-version")); return; } @@ -168,10 +163,10 @@ public void save(Actor actor, LocalSession session, boolean overwrite = f.exists(); if (overwrite) { if (!actor.hasPermission("worldedit.schematic.delete")) { - throw new StopExecutionException(TextComponent.of("That schematic already exists!")); + throw new StopExecutionException(Component.text("That schematic already exists!")); } if (!allowOverwrite) { - actor.printError(TranslatableComponent.of("worldedit.schematic.save.already-exists")); + actor.printError(Component.translatable("worldedit.schematic.save.already-exists")); return; } } @@ -180,7 +175,7 @@ public void save(Actor actor, LocalSession session, File parent = f.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { - throw new StopExecutionException(TranslatableComponent.of( + throw new StopExecutionException(Component.translatable( "worldedit.schematic.save.failed-directory")); } } @@ -190,8 +185,8 @@ public void save(Actor actor, LocalSession session, SchematicSaveTask task = new SchematicSaveTask(actor, f, format, holder, overwrite); AsyncCommandBuilder.wrap(task, actor) .registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename) - .setDelayMessage(TranslatableComponent.of("worldedit.schematic.save.saving")) - .setWorkingMessage(TranslatableComponent.of("worldedit.schematic.save.still-saving")) + .setDelayMessage(Component.translatable("worldedit.schematic.save.saving")) + .setWorkingMessage(Component.translatable("worldedit.schematic.save.still-saving")) .onSuccess(filename + " saved" + (overwrite ? " (overwriting previous file)." : "."), null) .onFailure("Failed to save schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) .buildAndExec(worldEdit.getExecutorService()); @@ -210,7 +205,7 @@ public void share(Actor actor, LocalSession session, @Arg(desc = "Format name", def = "") ClipboardFormat format) throws WorldEditException { if (worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getDataVersion() == -1) { - actor.printError(TranslatableComponent.of("worldedit.schematic.unsupported-minecraft-version")); + actor.printError(Component.translatable("worldedit.schematic.unsupported-minecraft-version")); return; } @@ -219,10 +214,10 @@ public void share(Actor actor, LocalSession session, } if (!destination.supportsFormat(format)) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.schematic.share.unsupported-format", - TextComponent.of(destination.getName()), - TextComponent.of(format.getName()) + Component.text(destination.getName()), + Component.text(format.getName()) )); return; } @@ -232,8 +227,8 @@ public void share(Actor actor, LocalSession session, SchematicShareTask task = new SchematicShareTask(actor, holder, destination, format, schematicName); AsyncCommandBuilder.wrap(task, actor) .registerWithSupervisor(worldEdit.getSupervisor(), "Sharing schematic") - .setDelayMessage(TranslatableComponent.of("worldedit.schematic.save.saving")) - .setWorkingMessage(TranslatableComponent.of("worldedit.schematic.save.still-saving")) + .setDelayMessage(Component.translatable("worldedit.schematic.save.saving")) + .setWorkingMessage(Component.translatable("worldedit.schematic.save.still-saving")) .onSuccess("Shared", (consumer -> consumer.accept(actor))) .onFailure("Failed to share schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) .buildAndExec(worldEdit.getExecutorService()); @@ -255,16 +250,16 @@ public void delete(Actor actor, dir, filename, "schematic", ClipboardFormats.getFileExtensionArray()); if (!f.exists()) { - actor.printError(TranslatableComponent.of("worldedit.schematic.delete.does-not-exist", TextComponent.of(filename))); + actor.printError(Component.translatable("worldedit.schematic.delete.does-not-exist", Component.text(filename))); return; } if (!f.delete()) { - actor.printError(TranslatableComponent.of("worldedit.schematic.delete.failed", TextComponent.of(filename))); + actor.printError(Component.translatable("worldedit.schematic.delete.failed", Component.text(filename))); return; } - actor.printInfo(TranslatableComponent.of("worldedit.schematic.delete.deleted", TextComponent.of(filename))); + actor.printInfo(Component.translatable("worldedit.schematic.delete.deleted", Component.text(filename))); try { LOGGER.info(actor.getName() + " deleted " + f.getCanonicalPath()); } catch (IOException e) { @@ -279,7 +274,7 @@ public void delete(Actor actor, ) @CommandPermissions("worldedit.schematic.formats") public void formats(Actor actor) { - actor.printInfo(TranslatableComponent.of("worldedit.schematic.formats.title")); + actor.printInfo(Component.translatable("worldedit.schematic.formats.title")); StringBuilder builder; boolean first = true; for (ClipboardFormat format : ClipboardFormats.getAll()) { @@ -293,7 +288,7 @@ public void formats(Actor actor) { first = false; } first = true; - actor.printInfo(TextComponent.of(builder.toString())); + actor.printInfo(Component.text(builder.toString())); } } @@ -312,7 +307,7 @@ public void list(Actor actor, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst) { if (oldFirst && newFirst) { - throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest.")); + throw new StopExecutionException(Component.text("Cannot sort by oldest and newest.")); } final String saveDir = worldEdit.getConfiguration().saveDir; Comparator pathComparator; @@ -332,7 +327,7 @@ public void list(Actor actor, WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new SchematicListTask(saveDir, pathComparator, page, pageCommand), - SubtleFormat.wrap("(Please wait... gathering schematic list.)")); + Component.text("(Please wait... gathering schematic list.)")); } private static class SchematicLoadTask implements Callable { @@ -402,7 +397,7 @@ public Void call() throws Exception { LOGGER.info(actor.getName() + " saved " + file.getCanonicalPath() + (overwrite ? " (overwriting previous file)" : "")); } catch (IOException e) { file.delete(); - throw new CommandException(TextComponent.of(e.getMessage()), e, ImmutableList.of()); + throw new CommandException(Component.text(e.getMessage()), e, ImmutableList.of()); } return null; } @@ -455,13 +450,13 @@ public Component call() throws Exception { List fileList = allFiles(resolvedRoot); if (fileList.isEmpty()) { - return ErrorFormat.wrap("No schematics found."); + return Component.text("No schematics found."); } fileList.sort(pathComparator); PaginationBox paginationBox = new SchematicPaginationBox(resolvedRoot, fileList, pageCommand); - return paginationBox.create(page); + return paginationBox.build(page); } } @@ -490,7 +485,7 @@ private static class SchematicPaginationBox extends PaginationBox { } @Override - public Component getComponent(int number) { + public Component component(int number) { checkArgument(number < files.size() && number >= 0); Path file = files.get(number); @@ -507,16 +502,15 @@ public Component getComponent(int number) { ? file.getFileName().toString() : file.toString().substring(rootDir.toString().length()); - return TextComponent.builder() - .content("") - .append(TextComponent.of("[L]") - .color(TextColor.GOLD) - .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/schem load \"" + path + "\"")) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to load")))) - .append(TextComponent.space()) - .append(TextComponent.of(path) - .color(TextColor.DARK_GREEN) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(format)))) + return Component.text() + .append(Component.text("[L]") + .color(NamedTextColor.GOLD) + .clickEvent(ClickEvent.runCommand("/schem load \"" + path + "\"")) + .hoverEvent(HoverEvent.showText(Component.text("Click to load")))) + .append(Component.space()) + .append(Component.text(path) + .color(NamedTextColor.DARK_GREEN) + .hoverEvent(HoverEvent.showText(Component.text(format)))) .build(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java index 1586ccd742..ac32b269e1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ScriptingCommands.java @@ -26,7 +26,7 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -69,7 +69,7 @@ public void execute(Player player, LocalSession session, @Arg(desc = "Arguments to the CraftScript", def = "", variable = true) List args) throws WorldEditException { if (!player.hasPermission("worldedit.scripting.execute." + filename)) { - player.printError(TranslatableComponent.of("worldedit.execute.script-permissions")); + player.printError(Component.translatable("worldedit.execute.script-permissions")); return; } @@ -95,12 +95,12 @@ public void executeLast(Player player, LocalSession session, String lastScript = session.getLastScript(); if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) { - player.printError(TranslatableComponent.of("worldedit.execute.script-permissions")); + player.printError(Component.translatable("worldedit.execute.script-permissions")); return; } if (lastScript == null) { - player.printError(TranslatableComponent.of("worldedit.executelast.no-script")); + player.printError(Component.translatable("worldedit.executelast.no-script")); return; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index bd0429e96b..c75c734a67 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -60,17 +60,14 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.component.CommandListBox; -import com.sk89q.worldedit.util.formatting.component.InvalidComponentException; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.component.SubtleFormat; -import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.CommandListBox; +import com.sk89q.worldedit.util.formatting.adventure.InvalidComponentException; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -110,7 +107,7 @@ private BlockVector3 getLocatablePosition(Actor actor) { if (actor instanceof Locatable locatable) { return locatable.getLocation().toVector().toBlockPoint(); } - actor.printError(TranslatableComponent.of("worldedit.pos.console-require-coords")); + actor.printError(Component.translatable("worldedit.pos.console-require-coords")); return null; } @@ -159,10 +156,10 @@ public void pos(Actor actor, World world, LocalSession session, session.dispatchCUISelection(actor); - for (Component line : regionSelector.getSelectionInfoLines()) { + for (Component line : regionSelector.getSelectionInformationLines()) { actor.printInfo(line); } - actor.printInfo(TranslatableComponent.of("worldedit.selection.updated")); + actor.printInfo(Component.translatable("worldedit.selection.updated")); } @Command( @@ -182,7 +179,7 @@ public void pos1(Actor actor, World world, LocalSession session, } if (!session.getRegionSelector(world).selectPrimary(coordinates, ActorSelectorLimits.forActor(actor))) { - actor.printError(TranslatableComponent.of("worldedit.pos.already-set")); + actor.printError(Component.translatable("worldedit.pos.already-set")); return; } @@ -206,7 +203,7 @@ public void pos2(Actor actor, World world, LocalSession session, } if (!session.getRegionSelector(world).selectSecondary(coordinates, ActorSelectorLimits.forActor(actor))) { - actor.printError(TranslatableComponent.of("worldedit.pos.already-set")); + actor.printError(Component.translatable("worldedit.pos.already-set")); return; } @@ -224,14 +221,14 @@ public void hpos1(Player player, LocalSession session) { if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { - player.printError(TranslatableComponent.of("worldedit.hpos.already-set")); + player.printError(Component.translatable("worldedit.hpos.already-set")); return; } session.getRegionSelector(player.getWorld()) .explainPrimarySelection(player, session, pos.toVector().toBlockPoint()); } else { - player.printError(TranslatableComponent.of("worldedit.hpos.no-block")); + player.printError(Component.translatable("worldedit.hpos.no-block")); } } @@ -246,14 +243,14 @@ public void hpos2(Player player, LocalSession session) { if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { - player.printError(TranslatableComponent.of("worldedit.hpos.already-set")); + player.printError(Component.translatable("worldedit.hpos.already-set")); return; } session.getRegionSelector(player.getWorld()) .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); } else { - player.printError(TranslatableComponent.of("worldedit.hpos.no-block")); + player.printError(Component.translatable("worldedit.hpos.no-block")); } } @@ -288,14 +285,14 @@ public void chunk(Actor actor, World world, LocalSession session, min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS); max = maxChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS).add(15, 255, 15); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.chunk.selected-multiple", - TextComponent.of(minChunk.getBlockX()), - TextComponent.of(minChunk.getBlockY()), - TextComponent.of(minChunk.getBlockZ()), - TextComponent.of(maxChunk.getBlockX()), - TextComponent.of(maxChunk.getBlockY()), - TextComponent.of(maxChunk.getBlockZ()) + Component.text(minChunk.getBlockX()), + Component.text(minChunk.getBlockY()), + Component.text(minChunk.getBlockZ()), + Component.text(maxChunk.getBlockX()), + Component.text(maxChunk.getBlockY()), + Component.text(maxChunk.getBlockZ()) )); } else { BlockVector3 minChunk; @@ -309,17 +306,17 @@ public void chunk(Actor actor, World world, LocalSession session, if (actor instanceof Locatable) { minChunk = ChunkStore.toChunk3d(((Locatable) actor).getBlockLocation().toVector().toBlockPoint()); } else { - throw new StopExecutionException(TextComponent.of("A player or coordinates are required.")); + throw new StopExecutionException(Component.text("A player or coordinates are required.")); } } min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS); max = min.add(15, 255, 15); - actor.printInfo(TranslatableComponent.of("worldedit.chunk.selected", - TextComponent.of(minChunk.getBlockX()), - TextComponent.of(minChunk.getBlockY()), - TextComponent.of(minChunk.getBlockZ()))); + actor.printInfo(Component.translatable("worldedit.chunk.selected", + Component.text(minChunk.getBlockX()), + Component.text(minChunk.getBlockY()), + Component.text(minChunk.getBlockZ()))); } final CuboidRegionSelector selector; @@ -348,7 +345,7 @@ public void wand(Player player, LocalSession session, boolean navWand) throws WorldEditException { Tool tool = navWand ? new NavigationWand() : new SelectionWand(); if (!tool.canUse(player)) { - player.printError(TranslatableComponent.of("worldedit.command.permissions")); + player.printError(Component.translatable("worldedit.command.permissions")); return; } String wandId = navWand ? session.getNavWandItem() : session.getWandItem(); @@ -357,12 +354,12 @@ public void wand(Player player, LocalSession session, } ItemType itemType = ItemTypes.get(wandId); if (itemType == null) { - player.printError(TranslatableComponent.of("worldedit.wand.invalid")); + player.printError(Component.translatable("worldedit.wand.invalid")); return; } player.giveItem(new BaseItemStack(itemType, 1)); session.setTool(itemType, tool); - player.printInfo(TranslatableComponent.of("worldedit.wand." + (navWand ? "nav" : "sel" ) + "wand.info")); + player.printInfo(Component.translatable("worldedit.wand." + (navWand ? "nav" : "sel" ) + "wand.info")); } @Command( @@ -372,14 +369,14 @@ public void wand(Player player, LocalSession session, @CommandPermissions("worldedit.wand.toggle") public void toggleWand(Player player) { player.printInfo( - TranslatableComponent.of( + Component.translatable( "worldedit.wand.selwand.now.tool", - TextComponent.of("/tool none", TextColor.AQUA).clickEvent( - ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/tool none")), - TextComponent.of("/tool selwand", TextColor.AQUA).clickEvent( - ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/tool selwand")), - TextComponent.of("//wand", TextColor.AQUA).clickEvent( - ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//wand")) + Component.text("/tool none", NamedTextColor.AQUA).clickEvent( + ClickEvent.runCommand("/tool none")), + Component.text("/tool selwand", NamedTextColor.AQUA).clickEvent( + ClickEvent.runCommand("/tool selwand")), + Component.text("//wand", NamedTextColor.AQUA).clickEvent( + ClickEvent.runCommand("//wand")) ) ); } @@ -415,9 +412,9 @@ public void contract(Actor actor, World world, LocalSession session, session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.printInfo(TranslatableComponent.of("worldedit.contract.contracted", TextComponent.of(oldSize - newSize))); + actor.printInfo(Component.translatable("worldedit.contract.contracted", Component.text(oldSize - newSize))); } catch (RegionOperationException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); } } @@ -444,9 +441,9 @@ public void shift(Actor actor, World world, LocalSession session, session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.printInfo(TranslatableComponent.of("worldedit.shift.shifted")); + actor.printInfo(Component.translatable("worldedit.shift.shifted")); } catch (RegionOperationException e) { - actor.printError(TextComponent.of(e.getMessage())); + actor.printError(Component.text(e.getMessage())); } } @@ -467,7 +464,7 @@ public void outset(Actor actor, World world, LocalSession session, region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); session.getRegionSelector(world).learnChanges(); session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.printInfo(TranslatableComponent.of("worldedit.outset.outset")); + actor.printInfo(Component.translatable("worldedit.outset.outset")); } @Command( @@ -487,7 +484,7 @@ public void inset(Actor actor, World world, LocalSession session, region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); session.getRegionSelector(world).learnChanges(); session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.printInfo(TranslatableComponent.of("worldedit.inset.inset")); + actor.printInfo(Component.translatable("worldedit.inset.inset")); } private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) { @@ -551,7 +548,7 @@ public void trim(Actor actor, World world, LocalSession session, // If anything was found in the first pass, then the remaining variables are guaranteed to be set if (!found) { - throw new StopExecutionException(TranslatableComponent.of( + throw new StopExecutionException(Component.translatable( "worldedit.trim.no-blocks")); } @@ -640,7 +637,7 @@ public void trim(Actor actor, World world, LocalSession session, session.getRegionSelector(world).learnChanges(); session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.printInfo(TranslatableComponent.of("worldedit.trim.trim")); + actor.printInfo(Component.translatable("worldedit.trim.trim")); } @Command( @@ -658,13 +655,13 @@ public void size(Actor actor, World world, LocalSession session, region = clipboard.getRegion(); BlockVector3 origin = clipboard.getOrigin(); - actor.printInfo(TranslatableComponent.of("worldedit.size.offset", TextComponent.of(origin.toString()))); + actor.printInfo(Component.translatable("worldedit.size.offset", Component.text(origin.toString()))); } else { region = session.getSelection(world); - actor.printInfo(TranslatableComponent.of("worldedit.size.type", TextComponent.of(session.getRegionSelector(world).getTypeName()))); + actor.printInfo(Component.translatable("worldedit.size.type", Component.text(session.getRegionSelector(world).getTypeName()))); - for (Component line : session.getRegionSelector(world).getSelectionInfoLines()) { + for (Component line : session.getRegionSelector(world).getSelectionInformationLines()) { actor.printInfo(line); } } @@ -672,9 +669,9 @@ public void size(Actor actor, World world, LocalSession session, .subtract(region.getMinimumPoint()) .add(1, 1, 1); - actor.printInfo(TranslatableComponent.of("worldedit.size.size", TextComponent.of(size.toString()))); - actor.printInfo(TranslatableComponent.of("worldedit.size.distance", TextComponent.of(region.getMaximumPoint().distance(region.getMinimumPoint())))); - actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getVolume()))); + actor.printInfo(Component.translatable("worldedit.size.size", Component.text(size.toString()))); + actor.printInfo(Component.translatable("worldedit.size.distance", Component.text(region.getMaximumPoint().distance(region.getMinimumPoint())))); + actor.printInfo(Component.translatable("worldedit.size.blocks", Component.text(region.getVolume()))); } @Command( @@ -686,7 +683,7 @@ public int count(Actor actor, World world, LocalSession session, EditSession edi @Arg(desc = "The mask of blocks to match") Mask mask) throws WorldEditException { int count = editSession.countBlocks(session.getSelection(world), mask); - actor.printInfo(TranslatableComponent.of("worldedit.count.counted", TextComponent.of(count))); + actor.printInfo(Component.translatable("worldedit.count.counted", Component.text(count))); return count; } @@ -721,13 +718,13 @@ public void distr(Actor actor, World world, LocalSession session, } else { distribution = session.getLastDistribution(); if (distribution == null) { - actor.printError(TranslatableComponent.of("worldedit.distr.no-previous")); + actor.printError(Component.translatable("worldedit.distr.no-previous")); return; } } if (distribution.isEmpty()) { // *Should* always be false - actor.printError(TranslatableComponent.of("worldedit.distr.no-blocks")); + actor.printError(Component.translatable("worldedit.distr.no-blocks")); return; } @@ -737,7 +734,7 @@ public void distr(Actor actor, World world, LocalSession session, if (!actor.isPlayer()) { res.formatForConsole(); } - return res.create(finalPage); + return res.build(finalPage); }, (Component) null); } @@ -754,23 +751,22 @@ public void select(Actor actor, World world, LocalSession session, if (selectorChoiceOrList == null) { session.getRegionSelector(world).clear(); session.dispatchCUISelection(actor); - actor.printInfo(TranslatableComponent.of("worldedit.select.cleared")); + actor.printInfo(Component.translatable("worldedit.select.cleared")); return; } if (!(selectorChoiceOrList instanceof SelectorChoice selectorChoice)) { CommandListBox box = new CommandListBox("Selection modes", null, null); box.setHidingHelp(true); - TextComponentProducer contents = box.getContents(); - contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline(); - box.appendCommand("cuboid", TranslatableComponent.of("worldedit.select.cuboid.description"), "//sel cuboid"); - box.appendCommand("extend", TranslatableComponent.of("worldedit.select.extend.description"), "//sel extend"); - box.appendCommand("poly", TranslatableComponent.of("worldedit.select.poly.description"), "//sel poly"); - box.appendCommand("ellipsoid", TranslatableComponent.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid"); - box.appendCommand("sphere", TranslatableComponent.of("worldedit.select.sphere.description"), "//sel sphere"); - box.appendCommand("cyl", TranslatableComponent.of("worldedit.select.cyl.description"), "//sel cyl"); - box.appendCommand("convex", TranslatableComponent.of("worldedit.select.convex.description"), "//sel convex"); - actor.print(box.create(1)); + box.builder().append(Component.text("Select one of the modes below:")).append(Component.newline()); + box.appendCommand("cuboid", Component.translatable("worldedit.select.cuboid.description"), "//sel cuboid"); + box.appendCommand("extend", Component.translatable("worldedit.select.extend.description"), "//sel extend"); + box.appendCommand("poly", Component.translatable("worldedit.select.poly.description"), "//sel poly"); + box.appendCommand("ellipsoid", Component.translatable("worldedit.select.ellipsoid.description"), "//sel ellipsoid"); + box.appendCommand("sphere", Component.translatable("worldedit.select.sphere.description"), "//sel sphere"); + box.appendCommand("cyl", Component.translatable("worldedit.select.cyl.description"), "//sel cyl"); + box.appendCommand("convex", Component.translatable("worldedit.select.convex.description"), "//sel convex"); + actor.print(box.build(1)); return; } @@ -791,7 +787,7 @@ public void select(Actor actor, World world, LocalSession session, if (found != null) { session.setDefaultRegionSelector(found); - actor.printInfo(TranslatableComponent.of("worldedit.select.default-set", TextComponent.of(found.name()))); + actor.printInfo(Component.translatable("worldedit.select.default-set", Component.text(found.name()))); } else { throw new RuntimeException("Something unexpected happened. Please report this."); } @@ -817,31 +813,31 @@ private static class BlockDistributionResult extends PaginationBox { } @Override - public Component getComponent(int number) { + public Component component(int number) { Countable c = distribution.get(number); - TextComponent.Builder line = TextComponent.builder(); + TextComponent.Builder line = Component.text(); final int count = c.getAmount(); final double perc = count / (double) totalBlocks * 100; final int maxDigits = (int) (Math.log10(totalBlocks) + 1); final int curDigits = (int) (Math.log10(count) + 1); - line.append(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), TextColor.GOLD); + line.append(Component.text(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), NamedTextColor.GOLD)); final int space = maxDigits - curDigits; String pad = Strings.repeat(" ", space == 0 ? 2 : 2 * space + 1); - line.append(String.format("%s%s", count, pad), TextColor.YELLOW); + line.append(Component.text(String.format("%s%s", count, pad), NamedTextColor.YELLOW)); final BlockState state = c.getID(); final BlockType blockType = state.getBlockType(); - Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE); + Component blockName = blockType.getDisplayName().color(NamedTextColor.LIGHT_PURPLE); TextComponent toolTip; if (separateStates && state != blockType.getDefaultState()) { - toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); - blockName = blockName.append(TextComponent.of("*", TextColor.LIGHT_PURPLE)); + toolTip = Component.text(state.getAsString(), NamedTextColor.GRAY); + blockName = blockName.append(Component.text("*", NamedTextColor.LIGHT_PURPLE)); } else { - toolTip = TextComponent.of(blockType.getId(), TextColor.GRAY); + toolTip = Component.text(blockType.getId(), NamedTextColor.GRAY); } - blockName = blockName.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, toolTip)); + blockName = blockName.hoverEvent(HoverEvent.showText(toolTip)); line.append(blockName); return line.build(); @@ -853,10 +849,10 @@ public int getComponentsSize() { } @Override - public Component create(int page) throws InvalidComponentException { - super.getContents().append(TranslatableComponent.of("worldedit.distr.total", TextColor.GRAY, TextComponent.of(totalBlocks))) - .append(TextComponent.newline()); - return super.create(page); + public Component build(int page) throws InvalidComponentException { + super.builder().append(Component.translatable("worldedit.distr.total", NamedTextColor.GRAY, Component.text(totalBlocks))) + .append(Component.newline()); + return super.build(page); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java index 842b165618..6409680dbf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java @@ -28,13 +28,11 @@ import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.component.PaginationBox; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.PaginationBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.experimental.Snapshot; import com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase; @@ -74,7 +72,7 @@ public SnapshotCommands(WorldEdit we) { static void checkSnapshotsConfigured(LocalConfiguration localConfiguration) { if (!localConfiguration.snapshotsConfigured) { - throw new StopExecutionException(TranslatableComponent.of( + throw new StopExecutionException(Component.translatable( "worldedit.restore.not-configured" )); } @@ -118,11 +116,11 @@ void list(Actor actor, World world, } if (!snapshots.isEmpty()) { - actor.print(new SnapshotListBox(world.getName(), snapshots).create(page)); + actor.print(new SnapshotListBox(world.getName(), snapshots).build(page)); } else { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.restore.none-for-specific-world", - TextComponent.of(world.getName()) + Component.text(world.getName()) )); if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) { @@ -169,9 +167,9 @@ void use(Actor actor, World world, LocalSession session, session.getSnapshotExperimental().close(); } session.setSnapshot(null); - actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest")); + actor.printInfo(Component.translatable("worldedit.snapshot.use.newest")); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); + actor.printError(Component.translatable("worldedit.restore.none-for-world")); } } else { URI uri = resolveSnapshotName(config, name); @@ -181,11 +179,11 @@ void use(Actor actor, World world, LocalSession session, session.getSnapshotExperimental().close(); } session.setSnapshotExperimental(snapshot.get()); - actor.printInfo(TranslatableComponent.of( - "worldedit.snapshot.use", TextComponent.of(name) + actor.printInfo(Component.translatable( + "worldedit.snapshot.use", Component.text(name) )); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); } } } @@ -207,7 +205,7 @@ void sel(Actor actor, World world, LocalSession session, } if (index < 1) { - actor.printError(TranslatableComponent.of("worldedit.snapshot.index-above-0")); + actor.printError(Component.translatable("worldedit.snapshot.index-above-0")); return; } @@ -218,24 +216,24 @@ void sel(Actor actor, World world, LocalSession session, .collect(toList()); } if (snapshots.size() < index) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.snapshot.index-oob", - TextComponent.of(snapshots.size()) + Component.text(snapshots.size()) )); return; } Snapshot snapshot = snapshots.get(index - 1); if (snapshot == null) { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); return; } if (session.getSnapshotExperimental() != null) { session.getSnapshotExperimental().close(); } session.setSnapshotExperimental(snapshot); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.snapshot.use", - TextComponent.of(snapshot.getInfo().getDisplayName()) + Component.text(snapshot.getInfo().getDisplayName()) )); } @@ -263,18 +261,18 @@ void before(Actor actor, World world, LocalSession session, } if (snapshot == null) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.snapshot.none-before", - TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) + Component.text(dateFormat.withZone(session.getTimeZone()).format(date))) ); } else { if (session.getSnapshotExperimental() != null) { session.getSnapshotExperimental().close(); } session.setSnapshotExperimental(snapshot); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.snapshot.use", - TextComponent.of(snapshot.getInfo().getDisplayName()) + Component.text(snapshot.getInfo().getDisplayName()) )); } } @@ -302,18 +300,18 @@ void after(Actor actor, World world, LocalSession session, .findFirst().orElse(null); } if (snapshot == null) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.snapshot.none-after", - TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) + Component.text(dateFormat.withZone(session.getTimeZone()).format(date))) ); } else { if (session.getSnapshotExperimental() != null) { session.getSnapshotExperimental().close(); } session.setSnapshotExperimental(snapshot); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.snapshot.use", - TextComponent.of(snapshot.getInfo().getDisplayName()) + Component.text(snapshot.getInfo().getDisplayName()) )); } } @@ -327,12 +325,12 @@ private static class SnapshotListBox extends PaginationBox { } @Override - public Component getComponent(int number) { + public Component component(int number) { final Snapshot snapshot = snapshots.get(number); String displayName = snapshot.getInfo().getDisplayName(); - return TextComponent.of(number + 1 + ". ", TextColor.GOLD) - .append(TextComponent.builder(displayName, TextColor.LIGHT_PURPLE) - .hoverEvent(HoverEvent.showText(TextComponent.of("Click to use"))) + return Component.text(number + 1 + ". ", NamedTextColor.GOLD) + .append(Component.text(displayName, NamedTextColor.LIGHT_PURPLE) + .hoverEvent(HoverEvent.showText(Component.text("Click to use"))) .clickEvent(ClickEvent.runCommand("/snap use " + displayName))); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java index 34a1a9c124..948a591b07 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotUtilCommands.java @@ -29,8 +29,7 @@ import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.experimental.Snapshot; import com.sk89q.worldedit.world.snapshot.experimental.SnapshotRestore; @@ -83,7 +82,7 @@ public void restore(Actor actor, World world, LocalSession session, EditSession URI uri = resolveSnapshotName(config, snapshotName); Optional snapOpt = config.snapshotDatabase.getSnapshot(uri); if (!snapOpt.isPresent()) { - actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); + actor.printError(Component.translatable("worldedit.restore.not-available")); return; } snapshot = snapOpt.get(); @@ -100,16 +99,16 @@ public void restore(Actor actor, World world, LocalSession session, EditSession } if (snapshot == null) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.restore.none-for-specific-world", - TextComponent.of(world.getName()) + Component.text(world.getName()) )); return; } } - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.restore.loaded", - TextComponent.of(snapshot.getInfo().getDisplayName()) + Component.text(snapshot.getInfo().getDisplayName()) )); try { @@ -122,17 +121,17 @@ public void restore(Actor actor, World world, LocalSession session, EditSession if (restore.hadTotalFailure()) { String error = restore.getLastErrorMessage(); if (!restore.getMissingChunks().isEmpty()) { - actor.printError(TranslatableComponent.of("worldedit.restore.chunk-not-present")); + actor.printError(Component.translatable("worldedit.restore.chunk-not-present")); } else if (error != null) { - actor.printError(TranslatableComponent.of("worldedit.restore.block-place-failed")); - actor.printError(TranslatableComponent.of("worldedit.restore.block-place-error", TextComponent.of(error))); + actor.printError(Component.translatable("worldedit.restore.block-place-failed")); + actor.printError(Component.translatable("worldedit.restore.block-place-error", Component.text(error))); } else { - actor.printError(TranslatableComponent.of("worldedit.restore.chunk-load-failed")); + actor.printError(Component.translatable("worldedit.restore.chunk-load-failed")); } } else { - actor.printInfo(TranslatableComponent.of("worldedit.restore.restored", - TextComponent.of(restore.getMissingChunks().size()), - TextComponent.of(restore.getErrorChunks().size()))); + actor.printInfo(Component.translatable("worldedit.restore.restored", + Component.text(restore.getMissingChunks().size()), + Component.text(restore.getErrorChunks().size()))); } } finally { try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java index c14a54c126..31e04ebc80 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SuperPickaxeCommands.java @@ -29,8 +29,7 @@ import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -51,7 +50,7 @@ public SuperPickaxeCommands(WorldEdit we) { public void single(Player player, LocalSession session) throws WorldEditException { session.setSuperPickaxe(new SinglePickaxe()); session.enableSuperPickAxe(); - player.printInfo(TranslatableComponent.of("worldedit.tool.superpickaxe.mode.single")); + player.printInfo(Component.translatable("worldedit.tool.superpickaxe.mode.single")); } @Command( @@ -66,13 +65,13 @@ public void area(Player player, LocalSession session, LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { - player.printError(TranslatableComponent.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); + player.printError(Component.translatable("worldedit.tool.superpickaxe.max-range", Component.text(config.maxSuperPickaxeSize))); return; } session.setSuperPickaxe(new AreaPickaxe(range)); session.enableSuperPickAxe(); - player.printInfo(TranslatableComponent.of("worldedit.tool.superpickaxe.mode.area")); + player.printInfo(Component.translatable("worldedit.tool.superpickaxe.mode.area")); } @Command( @@ -88,12 +87,12 @@ public void recursive(Player player, LocalSession session, LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { - player.printError(TranslatableComponent.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); + player.printError(Component.translatable("worldedit.tool.superpickaxe.max-range", Component.text(config.maxSuperPickaxeSize))); return; } session.setSuperPickaxe(new RecursivePickaxe(range)); session.enableSuperPickAxe(); - player.printInfo(TranslatableComponent.of("worldedit.tool.superpickaxe.mode.recursive")); + player.printInfo(Component.translatable("worldedit.tool.superpickaxe.mode.recursive")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index 0e9723817c..2b56c3a354 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -48,11 +48,9 @@ import com.sk89q.worldedit.internal.command.CommandUtil; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.piston.CommandManager; @@ -71,9 +69,8 @@ @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ToolCommands { - private static final Component UNBIND_COMMAND_COMPONENT = TextComponent.builder("/tool unbind", TextColor.AQUA) - .clickEvent(ClickEvent.suggestCommand("/tool unbind")) - .build(); + private static final Component UNBIND_COMMAND_COMPONENT = Component.text("/tool unbind", NamedTextColor.AQUA) + .clickEvent(ClickEvent.suggestCommand("/tool unbind")); public static void register(CommandRegistrationHandler registration, CommandManager commandManager, @@ -119,13 +116,13 @@ public static void register(CommandRegistrationHandler registration, .collect(Collectors.toSet()); commandManager.register("tool", command -> { command.addPart(SubCommandPart.builder( - TranslatableComponent.of("tool"), - TextComponent.of("The tool to bind") + Component.translatable("tool"), + Component.text("The tool to bind") ) .withCommands(nonGlobalCommands) .required() .build()); - command.description(TextComponent.of("Binds a tool to the item in your hand")); + command.description(Component.text("Binds a tool to the item in your hand")); command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build()); }); @@ -148,21 +145,21 @@ static void setToolNone(Player player, LocalSession session, boolean isBrush) || type.getId().equals(session.getNavWandItem()); if (set) { session.setTool(type, null); - player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip")); + player.printInfo(Component.translatable(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip")); } else { - player.printInfo(TranslatableComponent.of("worldedit.tool.none.to.unequip")); + player.printInfo(Component.translatable("worldedit.tool.none.to.unequip")); } } static void sendUnbindInstruction(Player sender, Component commandComponent) { - sender.printDebug(TranslatableComponent.of("worldedit.tool.unbind-instruction", commandComponent)); + sender.printDebug(Component.translatable("worldedit.tool.unbind-instruction", commandComponent)); } private static void setTool(Player player, LocalSession session, Tool tool, String translationKey) throws InvalidToolBindException { BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND); session.setTool(itemStack.getType(), tool); - player.printInfo(TranslatableComponent.of(translationKey, itemStack.getRichName())); + player.printInfo(Component.translatable(translationKey, itemStack.getDisplayName())); sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT); } @@ -269,7 +266,7 @@ public void floodFill(Player player, LocalSession session, LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { - player.printError(TranslatableComponent.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); + player.printError(Component.translatable("worldedit.tool.superpickaxe.max-range", Component.text(config.maxSuperPickaxeSize))); return; } setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip"); @@ -308,15 +305,15 @@ public void longrangebuildtool(Player player, LocalSession session, Component primaryName; Component secondaryName; if (primary instanceof BlockStateHolder) { - primaryName = ((BlockStateHolder) primary).getBlockType().getRichName(); + primaryName = ((BlockStateHolder) primary).getBlockType().getDisplayName(); } else { - primaryName = TextComponent.of("pattern"); + primaryName = Component.text("pattern"); } if (secondary instanceof BlockStateHolder) { - secondaryName = ((BlockStateHolder) secondary).getBlockType().getRichName(); + secondaryName = ((BlockStateHolder) secondary).getBlockType().getDisplayName(); } else { - secondaryName = TextComponent.of("pattern"); + secondaryName = Component.text("pattern"); } - player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", primaryName, secondaryName)); + player.printInfo(Component.translatable("worldedit.tool.lrbuild.set", primaryName, secondaryName)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java index 62963676cd..5d6a4704bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolUtilCommands.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.HandSide; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -56,15 +56,15 @@ public void togglePickaxe(Player player, LocalSession session, Boolean superPickaxe) { boolean hasSuperPickAxe = session.hasSuperPickAxe(); if (superPickaxe != null && superPickaxe == hasSuperPickAxe) { - player.printError(TranslatableComponent.of(superPickaxe ? "worldedit.tool.superpickaxe.enabled.already" : "worldedit.tool.superpickaxe.disabled.already")); + player.printError(Component.translatable(superPickaxe ? "worldedit.tool.superpickaxe.enabled.already" : "worldedit.tool.superpickaxe.disabled.already")); return; } if (hasSuperPickAxe) { session.disableSuperPickAxe(); - player.printInfo(TranslatableComponent.of("worldedit.tool.superpickaxe.disabled")); + player.printInfo(Component.translatable("worldedit.tool.superpickaxe.disabled")); } else { session.enableSuperPickAxe(); - player.printInfo(TranslatableComponent.of("worldedit.tool.superpickaxe.enabled")); + player.printInfo(Component.translatable("worldedit.tool.superpickaxe.enabled")); } } @@ -79,14 +79,14 @@ public void mask(Player player, LocalSession session, Mask mask) throws WorldEditException { BrushTool brushTool = session.getBrush(player.getItemInHand(HandSide.MAIN_HAND).getType()); if (brushTool == null) { - player.printError(TranslatableComponent.of("worldedit.brush.none.equipped")); + player.printError(Component.translatable("worldedit.brush.none.equipped")); return; } brushTool.setMask(mask); if (mask == null) { - player.printInfo(TranslatableComponent.of("worldedit.tool.mask.disabled")); + player.printInfo(Component.translatable("worldedit.tool.mask.disabled")); } else { - player.printInfo(TranslatableComponent.of("worldedit.tool.mask.set")); + player.printInfo(Component.translatable("worldedit.tool.mask.set")); } } @@ -101,11 +101,11 @@ public void material(Player player, LocalSession session, Pattern pattern) throws WorldEditException { BrushTool brushTool = session.getBrush(player.getItemInHand(HandSide.MAIN_HAND).getType()); if (brushTool == null) { - player.printError(TranslatableComponent.of("worldedit.brush.none.equipped")); + player.printError(Component.translatable("worldedit.brush.none.equipped")); return; } brushTool.setFill(pattern); - player.printInfo(TranslatableComponent.of("worldedit.tool.material.set")); + player.printInfo(Component.translatable("worldedit.tool.material.set")); } @Command( @@ -118,11 +118,11 @@ public void range(Player player, LocalSession session, int range) throws WorldEditException { BrushTool brushTool = session.getBrush(player.getItemInHand(HandSide.MAIN_HAND).getType()); if (brushTool == null) { - player.printError(TranslatableComponent.of("worldedit.brush.none.equipped")); + player.printError(Component.translatable("worldedit.brush.none.equipped")); return; } brushTool.setRange(range); - player.printInfo(TranslatableComponent.of("worldedit.tool.range.set")); + player.printInfo(Component.translatable("worldedit.tool.range.set")); } @Command( @@ -137,11 +137,11 @@ public void size(Player player, LocalSession session, BrushTool brushTool = session.getBrush(player.getItemInHand(HandSide.MAIN_HAND).getType()); if (brushTool == null) { - player.printError(TranslatableComponent.of("worldedit.brush.none.equipped")); + player.printError(Component.translatable("worldedit.brush.none.equipped")); return; } brushTool.setSize(size); - player.printInfo(TranslatableComponent.of("worldedit.tool.size.set")); + player.printInfo(Component.translatable("worldedit.tool.size.set")); } @Command( @@ -154,14 +154,14 @@ public void traceMask(Player player, LocalSession session, Mask mask) throws WorldEditException { BrushTool brushTool = session.getBrush(player.getItemInHand(HandSide.MAIN_HAND).getType()); if (brushTool == null) { - player.printError(TranslatableComponent.of("worldedit.brush.none.equipped")); + player.printError(Component.translatable("worldedit.brush.none.equipped")); return; } brushTool.setTraceMask(mask); if (mask == null) { - player.printInfo(TranslatableComponent.of("worldedit.tool.tracemask.disabled")); + player.printInfo(Component.translatable("worldedit.tool.tracemask.disabled")); } else { - player.printInfo(TranslatableComponent.of("worldedit.tool.tracemask.set")); + player.printInfo(Component.translatable("worldedit.tool.tracemask.set")); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 5e79641b7d..82069df4ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -51,11 +51,8 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.component.SubtleFormat; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; import org.enginehub.piston.annotation.Command; @@ -104,7 +101,7 @@ public int fill(Actor actor, LocalSession session, EditSession editSession, BlockVector3 pos = session.getPlacementPosition(actor); int affected = editSession.fillXZ(pos, pattern, radius, depth, false); - actor.printInfo(TranslatableComponent.of("worldedit.fill.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.fill.created", Component.text(affected))); return affected; } @@ -128,7 +125,7 @@ public int fillr(Actor actor, LocalSession session, EditSession editSession, BlockVector3 pos = session.getPlacementPosition(actor); int affected = editSession.fillXZ(pos, pattern, radius, depth, true); - actor.printInfo(TranslatableComponent.of("worldedit.fillr.created", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.fillr.created", Component.text(affected))); return affected; } @@ -146,7 +143,7 @@ public int drain(Actor actor, LocalSession session, EditSession editSession, radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.drainArea(session.getPlacementPosition(actor), radius, waterlogged); - actor.printInfo(TranslatableComponent.of("worldedit.drain.drained", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.drain.drained", Component.text(affected))); return affected; } @@ -163,7 +160,7 @@ public int fixLava(Actor actor, LocalSession session, EditSession editSession, radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.LAVA); - actor.printInfo(TranslatableComponent.of("worldedit.fixlava.fixed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.fixlava.fixed", Component.text(affected))); return affected; } @@ -180,7 +177,7 @@ public int fixWater(Actor actor, LocalSession session, EditSession editSession, radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.WATER); - actor.printInfo(TranslatableComponent.of("worldedit.fixwater.fixed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.fixwater.fixed", Component.text(affected))); return affected; } @@ -204,7 +201,7 @@ public int removeAbove(Actor actor, LocalSession session, EditSession editSessio we.checkMaxRadius(size); int affected = editSession.removeAbove(session.getPlacementPosition(actor), size, height); - actor.printInfo(TranslatableComponent.of("worldedit.removeabove.removed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.removeabove.removed", Component.text(affected))); return affected; } @@ -228,7 +225,7 @@ public int removeBelow(Actor actor, LocalSession session, EditSession editSessio we.checkMaxRadius(size); int affected = editSession.removeBelow(session.getPlacementPosition(actor), size, height); - actor.printInfo(TranslatableComponent.of("worldedit.removebelow.removed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.removebelow.removed", Component.text(affected))); return affected; } @@ -248,7 +245,7 @@ public int removeNear(Actor actor, LocalSession session, EditSession editSession we.checkMaxRadius(radius); int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, radius); - actor.printInfo(TranslatableComponent.of("worldedit.removenear.removed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.removenear.removed", Component.text(affected))); return affected; } @@ -279,7 +276,7 @@ public int replaceNear(Actor actor, World world, LocalSession session, EditSessi } int affected = editSession.replaceBlocks(region, from, to); - actor.printInfo(TranslatableComponent.of("worldedit.replacenear.replaced", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.replacenear.replaced", Component.text(affected))); return affected; } @@ -309,8 +306,8 @@ public int snow(Actor actor, LocalSession session, EditSession editSession, CylinderRegion region = new CylinderRegion(position, Vector2.at(size, size), position.getBlockY() - height, position.getBlockY() + height); int affected = editSession.simulateSnow(region, stack); - actor.printInfo(TranslatableComponent.of( - "worldedit.snow.created", TextComponent.of(affected) + actor.printInfo(Component.translatable( + "worldedit.snow.created", Component.text(affected) )); return affected; } @@ -336,8 +333,8 @@ public int thaw(Actor actor, LocalSession session, EditSession editSession, we.checkMaxRadius(size); int affected = editSession.thaw(session.getPlacementPosition(actor), size, height); - actor.printInfo(TranslatableComponent.of( - "worldedit.thaw.removed", TextComponent.of(affected) + actor.printInfo(Component.translatable( + "worldedit.thaw.removed", Component.text(affected) )); return affected; } @@ -368,8 +365,8 @@ public int green(Actor actor, LocalSession session, EditSession editSession, final int affected = editSession.green( session.getPlacementPosition(actor), size, height, onlyNormalDirt ); - actor.printInfo(TranslatableComponent.of( - "worldedit.green.changed", TextComponent.of(affected) + actor.printInfo(Component.translatable( + "worldedit.green.changed", Component.text(affected) )); return affected; } @@ -393,7 +390,7 @@ public int extinguish(Actor actor, LocalSession session, EditSession editSession Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE); int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size); - actor.printInfo(TranslatableComponent.of("worldedit.extinguish.removed", TextComponent.of(affected))); + actor.printInfo(Component.translatable("worldedit.extinguish.removed", Component.text(affected))); return affected; } @@ -429,7 +426,7 @@ public int butcher(Actor actor, if (radius == null) { radius = config.butcherDefaultRadius; } else if (radius < -1) { - actor.printError(TranslatableComponent.of("worldedit.butcher.explain-all")); + actor.printError(Component.translatable("worldedit.butcher.explain-all")); return 0; } else if (radius == -1) { if (config.butcherMaxRadius != -1) { @@ -453,10 +450,10 @@ public int butcher(Actor actor, int killed = killMatchingEntities(radius, actor, flags::createFunction); - actor.printInfo(TranslatableComponent.of( + actor.printInfo(Component.translatable( "worldedit.butcher.killed", - TextComponent.of(killed), - TextComponent.of(radius) + Component.text(killed), + Component.text(radius) )); return killed; @@ -475,12 +472,12 @@ public int remove(Actor actor, @Arg(desc = "The radius of the cuboid to remove from") int radius) throws WorldEditException { if (radius < -1) { - actor.printError(TranslatableComponent.of("worldedit.remove.explain-all")); + actor.printError(Component.translatable("worldedit.remove.explain-all")); return 0; } int removed = killMatchingEntities(radius, actor, remover::createFunction); - actor.printInfo(TranslatableComponent.of("worldedit.remove.removed", TextComponent.of(removed))); + actor.printInfo(Component.translatable("worldedit.remove.removed", Component.text(removed))); return removed; } @@ -530,10 +527,10 @@ public void calc(Actor actor, try { expression = Expression.compile(String.join(" ", input)); } catch (ExpressionException e) { - actor.printError(TranslatableComponent.of( + actor.printError(Component.translatable( "worldedit.calc.invalid.with-error", - TextComponent.of(String.join(" ", input)), - TextComponent.of(e.getMessage()) + Component.text(String.join(" ", input)), + Component.text(e.getMessage()) )); return; } @@ -541,7 +538,7 @@ public void calc(Actor actor, double result = expression.evaluate( new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); String formatted = Double.isNaN(result) ? "NaN" : formatForLocale(actor.getLocale()).format(result); - return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); + return Component.text(input + " = ").append(Component.text(formatted, NamedTextColor.LIGHT_PURPLE)); }, (Component) null); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 488b14ac2f..cee37a5705 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -32,12 +32,11 @@ import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.PlatformManager; -import com.sk89q.worldedit.util.formatting.component.MessageBox; -import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.adventure.MessageBox; import com.sk89q.worldedit.util.paste.ActorCallbackPaste; import com.sk89q.worldedit.util.paste.PasteMetadata; import com.sk89q.worldedit.util.report.ConfigReport; @@ -76,32 +75,32 @@ public WorldEditCommands(WorldEdit we) { desc = "Get WorldEdit version" ) public void version(Actor actor) { - actor.printInfo(TranslatableComponent.of("worldedit.version.version", TextComponent.of(WorldEdit.getVersion()))); - actor.printInfo(TextComponent.of("https://github.com/EngineHub/WorldEdit/")); + actor.printInfo(Component.translatable("worldedit.version.version", Component.text(WorldEdit.getVersion()))); + actor.printInfo(Component.text("https://github.com/EngineHub/WorldEdit/")); PlatformManager pm = we.getPlatformManager(); - TextComponentProducer producer = new TextComponentProducer(); + TextComponent.Builder producer = Component.text(); for (Platform platform : pm.getPlatforms()) { producer.append( - TextComponent.of("* ", TextColor.GRAY) - .append(TextComponent.of(platform.getPlatformName()) - .hoverEvent(HoverEvent.showText(TextComponent.of(platform.getId())))) - .append(TextComponent.of("(" + platform.getPlatformVersion() + ")")) - ).newline(); + Component.text("* ", NamedTextColor.GRAY) + .append(Component.text(platform.getPlatformName()) + .hoverEvent(HoverEvent.showText(Component.text(platform.getId())))) + .append(Component.text("(" + platform.getPlatformVersion() + ")")) + ).append(Component.newline()); } - actor.print(new MessageBox("Platforms", producer, TextColor.GRAY).create()); + actor.print(new MessageBox("Platforms", producer.build(), NamedTextColor.GRAY).build()); - producer.reset(); + producer = Component.text(); for (Capability capability : Capability.values()) { Platform platform = pm.queryCapability(capability); producer.append( - TextComponent.of(capability.name(), TextColor.GRAY) - .append(TextComponent.of(": ") - .append(TextComponent.of(platform != null ? platform.getPlatformName() : "none"))) - ).newline(); + Component.text(capability.name(), NamedTextColor.GRAY) + .append(Component.text(": ") + .append(Component.text(platform != null ? platform.getPlatformName() : "none"))) + ).append(Component.newline()); } - actor.print(new MessageBox("Capabilities", producer, TextColor.GRAY).create()); + actor.print(new MessageBox("Capabilities", producer.build(), NamedTextColor.GRAY).build()); } @Command( @@ -112,7 +111,7 @@ public void version(Actor actor) { public void reload(Actor actor) { we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload(); we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration())); - actor.printInfo(TranslatableComponent.of("worldedit.reload.config")); + actor.printInfo(Component.translatable("worldedit.reload.config")); } @Command( @@ -131,9 +130,9 @@ public void report(Actor actor, try { Path dest = we.getConfiguration().getWorkingDirectoryPath().resolve("report.txt"); Files.writeString(dest, result, StandardCharsets.UTF_8); - actor.printInfo(TranslatableComponent.of("worldedit.report.written", TextComponent.of(dest.toAbsolutePath().toString()))); + actor.printInfo(Component.translatable("worldedit.report.written", Component.text(dest.toAbsolutePath().toString()))); } catch (IOException e) { - actor.printError(TranslatableComponent.of("worldedit.report.error", TextComponent.of(e.getMessage()))); + actor.printError(Component.translatable("worldedit.report.error", Component.text(e.getMessage()))); } if (pastebin) { @@ -141,7 +140,7 @@ public void report(Actor actor, PasteMetadata metadata = new PasteMetadata(); metadata.author = actor.getName(); metadata.extension = "report"; - ActorCallbackPaste.pastebin(we.getSupervisor(), actor, result, metadata, TranslatableComponent.builder("worldedit.report.callback")); + ActorCallbackPaste.pastebin(we.getSupervisor(), actor, result, metadata, Component.translatable("worldedit.report.callback")); } } @@ -157,14 +156,14 @@ void trace(Actor actor, LocalSession session, if (hookMode != null) { newMode = hookMode == HookMode.ACTIVE; if (newMode == previousMode) { - actor.printError(TranslatableComponent.of(previousMode ? "worldedit.trace.active.already" : "worldedit.trace.inactive.already")); + actor.printError(Component.translatable(previousMode ? "worldedit.trace.active.already" : "worldedit.trace.inactive.already")); return; } } else { newMode = !previousMode; } session.setTracingActions(newMode); - actor.printInfo(TranslatableComponent.of(newMode ? "worldedit.trace.active" : "worldedit.trace.inactive")); + actor.printInfo(Component.translatable(newMode ? "worldedit.trace.active" : "worldedit.trace.inactive")); } @Command( @@ -186,13 +185,13 @@ public void tz(Actor actor, LocalSession session, try { ZoneId tz = ZoneId.of(timezone); session.setTimezone(tz); - actor.printInfo(TranslatableComponent.of("worldedit.timezone.set", TextComponent.of(tz.getDisplayName( + actor.printInfo(Component.translatable("worldedit.timezone.set", Component.text(tz.getDisplayName( TextStyle.FULL, actor.getLocale() )))); - actor.printInfo(TranslatableComponent.of("worldedit.timezone.current", - TextComponent.of(dateFormat.withLocale(actor.getLocale()).format(ZonedDateTime.now(tz))))); + actor.printInfo(Component.translatable("worldedit.timezone.current", + Component.text(dateFormat.withLocale(actor.getLocale()).format(ZonedDateTime.now(tz))))); } catch (ZoneRulesException e) { - actor.printError(TranslatableComponent.of("worldedit.timezone.invalid")); + actor.printError(Component.translatable("worldedit.timezone.invalid")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/AbstractDirectionConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/AbstractDirectionConverter.java index 1765d94e61..11b131c292 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/AbstractDirectionConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/AbstractDirectionConverter.java @@ -28,8 +28,7 @@ import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.MultiDirection; import com.sk89q.worldedit.internal.annotation.OptionalArg; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -106,7 +105,7 @@ public ConversionResult convert(String argument, InjectedValueAccess context) @Override public Component describeAcceptableArguments() { - return TextComponent.of("`me` to use facing direction, or any " + return Component.text("`me` to use facing direction, or any " + (includeDiagonals ? "direction" : "non-diagonal direction")); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Chunk3dVectorConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Chunk3dVectorConverter.java index 68fd64f817..ce91b1d880 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Chunk3dVectorConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/Chunk3dVectorConverter.java @@ -24,8 +24,7 @@ import com.google.common.reflect.TypeToken; import com.sk89q.worldedit.internal.annotation.Chunk3d; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ArgumentConverters; @@ -77,7 +76,7 @@ private Chunk3dVectorConverter(ArgumentConverter componentConverter, @Override public Component describeAcceptableArguments() { - return TextComponent.of("any " + acceptableArguments); + return Component.text("any " + acceptableArguments); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardFormatConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardFormatConverter.java index cfa0a1ed46..bed79a2acd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardFormatConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardFormatConverter.java @@ -22,8 +22,8 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.share.ClipboardShareDestination; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -48,7 +48,7 @@ public static void register(CommandManager commandManager) { private final TextComponent choices; private ClipboardFormatConverter() { - this.choices = TextComponent.of("any clipboard format"); + this.choices = Component.text("any clipboard format"); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardShareDestinationConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardShareDestinationConverter.java index 5af81bb1d2..d0384c01c0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardShareDestinationConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ClipboardShareDestinationConverter.java @@ -21,8 +21,8 @@ import com.sk89q.worldedit.extent.clipboard.io.share.ClipboardShareDestination; import com.sk89q.worldedit.extent.clipboard.io.share.ClipboardShareDestinations; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -47,7 +47,7 @@ public static void register(CommandManager commandManager) { private final TextComponent choices; private ClipboardShareDestinationConverter() { - this.choices = TextComponent.of("any clipboard share destination"); + this.choices = Component.text("any clipboard share destination"); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/CommaSeparatedValuesConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/CommaSeparatedValuesConverter.java index d4f3c92d82..71a2e8834e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/CommaSeparatedValuesConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/CommaSeparatedValuesConverter.java @@ -23,8 +23,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; import org.enginehub.piston.converter.SuccessfulConversion; @@ -35,7 +35,6 @@ import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; -import static com.sk89q.worldedit.util.formatting.text.TextComponent.space; public class CommaSeparatedValuesConverter implements ArgumentConverter { @@ -71,13 +70,13 @@ private CommaSeparatedValuesConverter(ArgumentConverter delegate, int maximum @Override public Component describeAcceptableArguments() { - TextComponent.Builder result = TextComponent.builder(""); + TextComponent.Builder result = Component.text(); if (maximum > -1) { - result.append(TextComponent.of("up to ")) - .append(TextComponent.of(maximum)) - .append(space()); + result.append(Component.text("up to ")) + .append(Component.text(maximum)) + .append(Component.space()); } - result.append(TextComponent.of("comma separated values of: ")) + result.append(Component.text("comma separated values of: ")) .append(delegate.describeAcceptableArguments()); return result.build(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/EntityRemoverConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/EntityRemoverConverter.java index 8286409d19..71897491dd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/EntityRemoverConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/EntityRemoverConverter.java @@ -21,8 +21,7 @@ import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.command.util.EntityRemover; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -49,7 +48,7 @@ private EntityRemoverConverter() { @Override public Component describeAcceptableArguments() { - return TextComponent.of( + return Component.text( "projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all" ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java index ea3e07f5bb..9f7b00a98c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java @@ -36,8 +36,7 @@ import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.request.RequestExtent; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; @@ -145,6 +144,6 @@ public List getSuggestions(String input, InjectedValueAccess context) { @Override public Component describeAcceptableArguments() { - return TextComponent.of("any " + description); + return Component.text("any " + description); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/HeightConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/HeightConverter.java index 9906e7f743..24c20f8ae2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/HeightConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/HeightConverter.java @@ -23,8 +23,7 @@ import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.internal.annotation.VertHeight; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ArgumentConverters; @@ -59,7 +58,7 @@ private HeightConverter() { @Override public Component describeAcceptableArguments() { - return TextComponent.of("Any integer"); + return Component.text("Any integer"); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/OffsetConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/OffsetConverter.java index 890626000e..b620d4bf55 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/OffsetConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/OffsetConverter.java @@ -30,8 +30,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -61,9 +60,9 @@ private OffsetConverter(WorldEdit worldEdit) { @Override public Component describeAcceptableArguments() { - return TextComponent.builder() + return Component.text() .append(directionVectorConverter.describeAcceptableArguments()) - .append(", or ") + .append(Component.text(", or ")) .append(vectorConverter.describeAcceptableArguments()) .build(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegistryConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegistryConverter.java index ed5e2cc1ae..a3153865cc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegistryConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/RegistryConverter.java @@ -23,8 +23,8 @@ import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.registry.Keyed; import com.sk89q.worldedit.registry.Registry; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; @@ -93,7 +93,7 @@ private static RegistryConverter from(Class registry private RegistryConverter(Registry registry) { this.registry = registry; - this.choices = TextComponent.of("any " + registry.getName()); + this.choices = Component.text("any " + registry.getName()); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SelectorChoice.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SelectorChoice.java index e6a87e724b..4559f2f3cd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SelectorChoice.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SelectorChoice.java @@ -29,9 +29,7 @@ import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector; import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector; import com.sk89q.worldedit.regions.selector.SphereRegionSelector; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.Optional; @@ -45,8 +43,8 @@ public enum SelectorChoice implements SelectorChoiceOrList { public void explainNewSelector(Actor actor) { super.explainNewSelector(actor); Optional limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit(); - limit.ifPresent(integer -> actor.printInfo(TranslatableComponent.of( - "worldedit.select.poly.limit-message", TextComponent.of(integer) + limit.ifPresent(integer -> actor.printInfo(Component.translatable( + "worldedit.select.poly.limit-message", Component.text(integer) ))); } }, @@ -58,8 +56,8 @@ public void explainNewSelector(Actor actor) { public void explainNewSelector(Actor actor) { super.explainNewSelector(actor); Optional limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit(); - limit.ifPresent(integer -> actor.printInfo(TranslatableComponent.of( - "worldedit.select.convex.limit-message", TextComponent.of(integer) + limit.ifPresent(integer -> actor.printInfo(Component.translatable( + "worldedit.select.convex.limit-message", Component.text(integer) ))); } }, @@ -74,7 +72,7 @@ public void explainNewSelector(Actor actor) { String message) { this.newFromWorld = newFromWorld; this.newFromOld = newFromOld; - this.messageComponent = TranslatableComponent.of(message); + this.messageComponent = Component.translatable(message); } public RegionSelector createNewSelector(World world) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectConverter.java index 4d5fc97d51..62b9f0efb8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectConverter.java @@ -21,8 +21,8 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.util.SideEffect; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -43,7 +43,7 @@ public static void register(CommandManager commandManager) { commandManager.registerConverter(Key.of(SideEffect.class), new SideEffectConverter()); } - private final TextComponent choices = TextComponent.of("any side effect"); + private final TextComponent choices = Component.text("any side effect"); private SideEffectConverter() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectSetConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectSetConverter.java index 509b993812..b18ebc4385 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectSetConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectSetConverter.java @@ -21,8 +21,8 @@ import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -44,7 +44,7 @@ public static void register(CommandManager commandManager) { ); } - private final TextComponent choices = TextComponent.of("any side effects"); + private final TextComponent choices = Component.text("any side effects"); private final CommaSeparatedValuesConverter sideEffectConverter; private SideEffectSetConverter(CommaSeparatedValuesConverter sideEffectConverter) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/VectorConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/VectorConverter.java index 31436b6238..439d4cd9cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/VectorConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/VectorConverter.java @@ -25,8 +25,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector2; import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ArgumentConverters; @@ -95,7 +94,7 @@ private VectorConverter(ArgumentConverter componentConverter, @Override public Component describeAcceptableArguments() { - return TextComponent.of("any " + acceptableArguments); + return Component.text("any " + acceptableArguments); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/WorldConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/WorldConverter.java index af6ce8b41a..e4f04a859a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/WorldConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/WorldConverter.java @@ -21,8 +21,8 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; import com.sk89q.worldedit.world.World; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; @@ -47,7 +47,7 @@ public static void register(CommandManager commandManager) { private final TextComponent choices; private WorldConverter() { - this.choices = TextComponent.of("any world"); + this.choices = Component.text("any world"); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java index f86f5e49b8..142c899384 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ZonedDateTimeConverter.java @@ -20,8 +20,7 @@ package com.sk89q.worldedit.command.argument; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; @@ -45,7 +44,7 @@ private ZonedDateTimeConverter() { @Override public Component describeAcceptableArguments() { - return TextComponent.of("any date"); + return Component.text("any date"); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java index a211128a4d..eaed0fa185 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -87,7 +87,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla } } } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java index 201e67a42e..e0f2b6080d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java @@ -31,8 +31,7 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; @@ -65,12 +64,12 @@ private boolean handleCycle(LocalConfiguration config, Player player, LocalSessi if (!config.allowedDataCycleBlocks.isEmpty() && !player.hasPermission("worldedit.override.data-cycler") && !config.allowedDataCycleBlocks.contains(block.getBlockType().getId())) { - player.printError(TranslatableComponent.of("worldedit.tool.data-cycler.block-not-permitted")); + player.printError(Component.translatable("worldedit.tool.data-cycler.block-not-permitted")); return true; } if (block.getStates().keySet().isEmpty()) { - player.printError(TranslatableComponent.of("worldedit.tool.data-cycler.cant-cycle")); + player.printError(Component.translatable("worldedit.tool.data-cycler.cant-cycle")); } else { Property currentProperty = selectedProperties.get(player.getUniqueId()); @@ -92,13 +91,13 @@ private boolean handleCycle(LocalConfiguration config, Player player, LocalSessi try { editSession.setBlock(blockPoint, newBlock); - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.tool.data-cycler.new-value", - TextComponent.of(currentProperty.getName()), - TextComponent.of(String.valueOf(currentProperty.getValues().get(index))) + Component.text(currentProperty.getName()), + Component.text(String.valueOf(currentProperty.getValues().get(index))) )); } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } @@ -109,7 +108,7 @@ private boolean handleCycle(LocalConfiguration config, Player player, LocalSessi index = (index + 1) % properties.size(); currentProperty = properties.get(index); selectedProperties.put(player.getUniqueId(), currentProperty); - player.printInfo(TranslatableComponent.of("worldedit.tool.data-cycler.cycling", TextComponent.of(currentProperty.getName()))); + player.printInfo(Component.translatable("worldedit.tool.data-cycler.cycling", Component.text(currentProperty.getName()))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index c3ffc486fa..b6c66c11d3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -31,7 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BaseBlock; import javax.annotation.Nullable; @@ -81,7 +81,7 @@ public boolean actSecondary(Platform server, LocalConfiguration config, Player p if (targetBlock != null) { pattern = targetBlock; - player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", targetBlock.getBlockType().getRichName())); + player.printInfo(Component.translatable("worldedit.tool.repl.switched", targetBlock.getBlockType().getDisplayName())); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index a7e3fcb661..ad99bf253f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -33,7 +33,7 @@ import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import javax.annotation.Nullable; @@ -197,7 +197,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla Location target = player.getBlockTrace(getRange(), true, traceMask); if (target == null) { - player.printError(TranslatableComponent.of("worldedit.tool.no-block")); + player.printError(Component.translatable("worldedit.tool.no-block")); return true; } @@ -221,7 +221,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla try { brush.build(editSession, target.toVector().toBlockPoint(), material, size); } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java index 5d62d7abd0..0618dfda5f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; /** * A wand that can be used at a distance. @@ -79,7 +79,7 @@ private Location getTarget(Player player) { } if (target == null) { - player.printError(TranslatableComponent.of("worldedit.tool.no-block")); + player.printError(Component.translatable("worldedit.tool.no-block")); return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 58a0361e26..ef52e3b209 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockState; @@ -75,7 +75,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); if (!isTreeBlock(state.getBlockType())) { - player.printError(TranslatableComponent.of("worldedit.tool.deltree.not-tree")); + player.printError(Component.translatable("worldedit.tool.deltree.not-tree")); return true; } @@ -83,7 +83,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, try { final Set blockSet = bfs(world, clicked.toVector().toBlockPoint()); if (blockSet == null) { - player.printError(TranslatableComponent.of("worldedit.tool.deltree.not-floating")); + player.printError(Component.translatable("worldedit.tool.deltree.not-floating")); return true; } @@ -94,7 +94,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, } } } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java index 03c7f0e097..a2a6690bcc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -76,7 +76,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla try { recurse(editSession, origin, origin, range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/InvalidToolBindException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/InvalidToolBindException.java index a951285157..0bf5025361 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/InvalidToolBindException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/InvalidToolBindException.java @@ -20,13 +20,19 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; public class InvalidToolBindException extends WorldEditException { private final ItemType item; + @Deprecated + public InvalidToolBindException(ItemType item, com.sk89q.worldedit.util.formatting.text.Component msg) { + super(msg); + this.item = item; + } + public InvalidToolBindException(ItemType item, Component msg) { super(msg); this.item = item; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java index 0137157451..bc3d2faa37 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java @@ -31,7 +31,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BaseBlock; /** @@ -123,7 +123,7 @@ private Location getTargetFace(Player player) { } if (target == null) { - player.printError(TranslatableComponent.of("worldedit.tool.no-block")); + player.printError(Component.translatable("worldedit.tool.no-block")); return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java index 9365fd67c1..fd585bbec8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/NavigationWand.java @@ -25,7 +25,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; public class NavigationWand implements DoubleActionTraceTool { @@ -45,7 +45,7 @@ public boolean actSecondary(Platform server, LocalConfiguration config, Player p if (pos != null) { player.findFreePosition(pos); } else { - player.printError(TranslatableComponent.of("worldedit.jumpto.none")); + player.printError(Component.translatable("worldedit.jumpto.none")); } return true; } @@ -61,7 +61,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla } if (!player.passThroughForwardWall(Math.max(1, maxDist - 10))) { - player.printError(TranslatableComponent.of("worldedit.thru.obstructed")); + player.printError(Component.translatable("worldedit.thru.obstructed")); } return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 365a896a9e..edc2c5255c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -28,10 +28,10 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.registry.LegacyMapper; @@ -55,25 +55,25 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); BaseBlock block = world.getFullBlock(blockPoint); - TextComponent.Builder builder = TextComponent.builder(); - builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); - builder.append(block.getBlockType().getRichName().color(TextColor.YELLOW)); - builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover")))); + TextComponent.Builder builder = Component.text(); + builder.append(Component.text("@" + clicked.toVector().toBlockPoint() + ": ", NamedTextColor.BLUE)); + builder.append(block.getBlockType().getDisplayName().color(NamedTextColor.YELLOW)); + builder.append(Component.text(" (" + block + ") ", NamedTextColor.GRAY) + .hoverEvent(HoverEvent.showText(Component.translatable("worldedit.tool.info.blockstate.hover")))); final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); if (BlockStateIdAccess.isValidInternalId(internalId)) { - builder.append(TextComponent.of(" (" + internalId + ") ", TextColor.DARK_GRAY) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.internalid.hover")))); + builder.append(Component.text(" (" + internalId + ") ", NamedTextColor.DARK_GRAY) + .hoverEvent(HoverEvent.showText(Component.translatable("worldedit.tool.info.internalid.hover")))); } final int[] legacy = LegacyMapper.getInstance().getLegacyFromBlock(block.toImmutableState()); if (legacy != null) { - builder.append(TextComponent.of(" (" + legacy[0] + ":" + legacy[1] + ") ", TextColor.DARK_GRAY) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.legacy.hover")))); + builder.append(Component.text(" (" + legacy[0] + ":" + legacy[1] + ") ", NamedTextColor.DARK_GRAY) + .hoverEvent(HoverEvent.showText(Component.translatable("worldedit.tool.info.legacy.hover")))); } - builder.append(TextComponent.of(" (" + world.getBlockLightLevel(blockPoint) + "/" - + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", TextColor.WHITE) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.light.hover")))); + builder.append(Component.text(" (" + world.getBlockLightLevel(blockPoint) + "/" + + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", NamedTextColor.WHITE) + .hoverEvent(HoverEvent.showText(Component.translatable("worldedit.tool.info.light.hover")))); player.print(builder.build()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index e114b77078..1aa0ea5d34 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -77,7 +77,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla recurse(server, editSession, world, clicked.toVector().toBlockPoint(), clicked.toVector().toBlockPoint(), range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java index cbccb4625b..6f69bb2602 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -59,7 +59,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java index 439f19beb7..7ecb60cd98 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import javax.annotation.Nullable; @@ -66,10 +66,10 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla } if (!successful) { - player.printError(TranslatableComponent.of("worldedit.tool.tree.obstructed")); + player.printError(Component.translatable("worldedit.tool.tree.obstructed")); } } catch (MaxChangedBlocksException e) { - player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); + player.printError(Component.translatable("worldedit.tool.max-block-changes")); } finally { session.remember(editSession); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java index 3a5fb6bea6..d47f5ecd82 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java @@ -26,10 +26,9 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.command.exception.ExceptionConverter; import com.sk89q.worldedit.internal.util.LogManagerCompat; -import com.sk89q.worldedit.util.formatting.component.ErrorFormat; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.util.task.FutureForwardingTask; import com.sk89q.worldedit.util.task.Supervisor; import org.apache.logging.log4j.Logger; @@ -88,25 +87,43 @@ public AsyncCommandBuilder registerWithSupervisor(Supervisor supervisor, Stri @Deprecated public AsyncCommandBuilder sendMessageAfterDelay(String message) { - return sendMessageAfterDelay(TextComponent.of(checkNotNull(message))); + return setDelayMessage(Component.text(checkNotNull(message))); } @Deprecated - public AsyncCommandBuilder sendMessageAfterDelay(Component message) { + public AsyncCommandBuilder sendMessageAfterDelay(com.sk89q.worldedit.util.formatting.text.Component message) { return setDelayMessage(message); } + @Deprecated + public AsyncCommandBuilder setDelayMessage(com.sk89q.worldedit.util.formatting.text.Component message) { + return setDelayMessage(LegacyTextHelper.adapt(message)); + } + public AsyncCommandBuilder setDelayMessage(Component message) { this.delayMessage = checkNotNull(message); return this; } + @Deprecated + public AsyncCommandBuilder setWorkingMessage(com.sk89q.worldedit.util.formatting.text.Component message) { + return setWorkingMessage(LegacyTextHelper.adapt(message)); + } + public AsyncCommandBuilder setWorkingMessage(Component message) { checkNotNull(this.delayMessage, "Must have a delay message if using a working message"); this.workingMessage = checkNotNull(message); return this; } + @Deprecated + public AsyncCommandBuilder onSuccess(@Nullable com.sk89q.worldedit.util.formatting.text.Component message, @Nullable Consumer consumer) { + checkArgument(message != null || consumer != null, "Can't have null message AND consumer"); + this.successMessage = message == null ? null : LegacyTextHelper.adapt(message); + this.consumer = consumer; + return this; + } + public AsyncCommandBuilder onSuccess(@Nullable Component message, @Nullable Consumer consumer) { checkArgument(message != null || consumer != null, "Can't have null message AND consumer"); this.successMessage = message; @@ -116,11 +133,19 @@ public AsyncCommandBuilder onSuccess(@Nullable Component message, @Nullable C public AsyncCommandBuilder onSuccess(@Nullable String message, @Nullable Consumer consumer) { checkArgument(message != null || consumer != null, "Can't have null message AND consumer"); - this.successMessage = message == null ? null : TextComponent.of(message, TextColor.LIGHT_PURPLE); + this.successMessage = message == null ? null : Component.text(message, NamedTextColor.LIGHT_PURPLE); this.consumer = consumer; return this; } + @Deprecated + public AsyncCommandBuilder onFailure(@Nullable com.sk89q.worldedit.util.formatting.text.Component message, @Nullable ExceptionConverter exceptionConverter) { + checkArgument(message != null || exceptionConverter != null, "Can't have null message AND exceptionConverter"); + this.failureMessage = message == null ? null : LegacyTextHelper.adapt(message); + this.exceptionConverter = exceptionConverter; + return this; + } + public AsyncCommandBuilder onFailure(@Nullable Component message, @Nullable ExceptionConverter exceptionConverter) { checkArgument(message != null || exceptionConverter != null, "Can't have null message AND exceptionConverter"); this.failureMessage = message; @@ -130,7 +155,7 @@ public AsyncCommandBuilder onFailure(@Nullable Component message, @Nullable E public AsyncCommandBuilder onFailure(@Nullable String message, @Nullable ExceptionConverter exceptionConverter) { checkArgument(message != null || exceptionConverter != null, "Can't have null message AND exceptionConverter"); - this.failureMessage = message == null ? null : ErrorFormat.wrap(message); + this.failureMessage = message == null ? null : Component.text(message, NamedTextColor.RED); this.exceptionConverter = exceptionConverter; return this; } @@ -163,7 +188,7 @@ private T runTask() { sender.print(successMessage); } } catch (Throwable orig) { - Component failure = failureMessage != null ? failureMessage : TextComponent.of("An error occurred"); + Component failure = failureMessage != null ? failureMessage : Component.text("An error occurred"); try { if (exceptionConverter != null) { try { @@ -180,18 +205,18 @@ private T runTask() { if (message == null) { if (Strings.isNullOrEmpty(converted.getMessage())) { - message = TextComponent.of("Unknown error."); + message = Component.text("Unknown error."); } else { message = converted.getRichMessage(); } } - sender.printError(failure.append(TextComponent.of(": ")).append(message)); + sender.printError(failure.append(Component.text(": ")).append(message)); } } else { throw orig; } } catch (Throwable unknown) { - sender.printError(failure.append(TextComponent.of(": Unknown error. Please see console."))); + sender.printError(failure.append(Component.text(": Unknown error. Please see console."))); LOGGER.error("Uncaught exception occurred in task: " + description, orig); } } @@ -211,7 +236,7 @@ private Component tryExtractOldCommandException(CommandException converted) { if (parentCause instanceof com.sk89q.minecraft.util.commands.CommandException) { final String msg = parentCause.getMessage(); if (!Strings.isNullOrEmpty(msg)) { - message = TextComponent.of(msg); + message = Component.text(msg); } break; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/FutureProgressListener.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/FutureProgressListener.java index 9f41bae07d..c0fc670417 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/FutureProgressListener.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/FutureProgressListener.java @@ -22,8 +22,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.Timer; import javax.annotation.Nullable; @@ -40,7 +39,7 @@ public class FutureProgressListener implements Runnable { @Deprecated public FutureProgressListener(Actor sender, String message) { - this(sender, TextComponent.of(message)); + this(sender, Component.text(message)); } public FutureProgressListener(Actor sender, Component message) { @@ -62,7 +61,7 @@ public void run() { @Deprecated public static void addProgressListener(ListenableFuture future, Actor sender, String message) { - addProgressListener(future, sender, TextComponent.of(message)); + addProgressListener(future, sender, Component.text(message)); } public static void addProgressListener(ListenableFuture future, Actor sender, Component message) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/MessageTimerTask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/MessageTimerTask.java index ee5de1a2e3..ccf2ec174d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/MessageTimerTask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/MessageTimerTask.java @@ -20,8 +20,7 @@ package com.sk89q.worldedit.command.util; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.TimerTask; import javax.annotation.Nullable; @@ -39,7 +38,7 @@ public class MessageTimerTask extends TimerTask { @Deprecated MessageTimerTask(Actor sender, String message) { - this(sender, TextComponent.of(message), null); + this(sender, Component.text(message), null); } MessageTimerTask(Actor sender, Component message, @Nullable Component workingMessage) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java index 1df62762e7..507ec3a1d4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java @@ -23,11 +23,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.component.CommandListBox; -import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; -import com.sk89q.worldedit.util.formatting.component.InvalidComponentException; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.adventure.CommandListBox; +import com.sk89q.worldedit.util.formatting.adventure.CommandUsageBox; +import com.sk89q.worldedit.util.formatting.adventure.InvalidComponentException; import org.enginehub.piston.Command; import org.enginehub.piston.CommandManager; import org.enginehub.piston.inject.InjectedValueStore; @@ -82,7 +81,7 @@ public static void help(List commandPath, int page, boolean listSubComma List visited = new ArrayList<>(); Command currentCommand = detectCommand(manager, commandPath.get(0)); if (currentCommand == null) { - actor.printError(TranslatableComponent.of("worldedit.help.command-not-found", TextComponent.of(commandPath.get(0)))); + actor.printError(Component.translatable("worldedit.help.command-not-found", Component.text(commandPath.get(0)))); return; } visited.add(currentCommand); @@ -93,12 +92,12 @@ public static void help(List commandPath, int page, boolean listSubComma Map subCommands = getSubCommands(currentCommand); if (subCommands.isEmpty()) { - actor.printError(TranslatableComponent.of("worldedit.help.no-subcommands", - TextComponent.of(toCommandString(visited)), TextComponent.of(subCommand))); + actor.printError(Component.translatable("worldedit.help.no-subcommands", + Component.text(toCommandString(visited)), Component.text(subCommand))); // full help for single command CommandUsageBox box = new CommandUsageBox(visited, visited.stream() .map(Command::getName).collect(Collectors.joining(" ")), helpRootCommand); - actor.print(box.create()); + actor.print(box.build()); return; } @@ -106,8 +105,8 @@ public static void help(List commandPath, int page, boolean listSubComma currentCommand = subCommands.get(subCommand); visited.add(currentCommand); } else { - actor.printError(TranslatableComponent.of("worldedit.help.subcommand-not-found", - TextComponent.of(subCommand), TextComponent.of(toCommandString(visited)))); + actor.printError(Component.translatable("worldedit.help.subcommand-not-found", + Component.text(subCommand), Component.text(toCommandString(visited)))); // list subcommands for currentCommand printCommands(page, getSubCommands(Iterables.getLast(visited)).values().stream(), actor, visited, helpRootCommand); return; @@ -119,7 +118,7 @@ public static void help(List commandPath, int page, boolean listSubComma if (subCommands.isEmpty() || !listSubCommands) { // Create the message CommandUsageBox box = new CommandUsageBox(visited, toCommandString(visited), helpRootCommand); - actor.print(box.create()); + actor.print(box.build()); } else { printCommands(page, subCommands.values().stream(), actor, visited, helpRootCommand); } @@ -158,7 +157,7 @@ private static void printCommands(int page, Stream commandStream, Actor box.appendCommand(alias, mapping.getDescription(), command); } - actor.print(box.create(page)); + actor.print(box.build(page)); } private PrintCommandHelp() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/WorldEditAsyncCommandBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/WorldEditAsyncCommandBuilder.java index 9f89216de7..3ff38a9f21 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/WorldEditAsyncCommandBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/WorldEditAsyncCommandBuilder.java @@ -21,8 +21,7 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.concurrent.Callable; import javax.annotation.Nullable; @@ -36,7 +35,7 @@ private WorldEditAsyncCommandBuilder() { @Deprecated public static void createAndSendMessage(Actor actor, Callable task, @Nullable String desc) { - createAndSendMessage(actor, task, desc != null ? TextComponent.of(desc) : null); + createAndSendMessage(actor, task, desc != null ? Component.text(desc) : null); } public static void createAndSendMessage(Actor actor, Callable task, @Nullable Component desc) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java index 1d3513ccfe..39514d856f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/MaskFactory.java @@ -41,8 +41,7 @@ import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.internal.registry.AbstractFactory; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.ArrayList; import java.util.List; @@ -111,14 +110,14 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars } } if (match == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(component))); + throw new NoMatchException(Component.translatable("worldedit.error.no-match", Component.text(component))); } masks.add(match); } switch (masks.size()) { case 0: - throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.no-match", Component.text(input))); case 1: return masks.get(0); default: diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index f5216d9c68..2f48818430 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -41,9 +41,8 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.HandSide; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -76,14 +75,14 @@ private static BaseBlock getBlockInHand(Actor actor, HandSide handSide) throws I try { return ((Player) actor).getBlockInHand(handSide); } catch (NotABlockException e) { - throw new InputParseException(e.getRichMessage()); + throw new InputParseException(e.getTextMessage()); } catch (WorldEditException e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.unknown", e.getRichMessage()), e); + throw new InputParseException(Component.translatable("worldedit.error.unknown", e.getTextMessage()), e); } } else { - throw new InputParseException(TranslatableComponent.of( + throw new InputParseException(Component.translatable( "worldedit.error.parser.player-only", - TextComponent.of(handSide == HandSide.MAIN_HAND ? "hand" : "offhand") + Component.text(handSide == HandSide.MAIN_HAND ? "hand" : "offhand") )); } } @@ -152,8 +151,8 @@ private static Map, Object> parseProperties(BlockType type, String[] String[] parts = parseableData.split("="); if (parts.length != 2) { throw new InputParseException( - TranslatableComponent.of("worldedit.error.parser.bad-state-format", - TextComponent.of(parseableData)) + Component.translatable("worldedit.error.parser.bad-state-format", + Component.text(parseableData)) ); } @@ -161,10 +160,10 @@ private static Map, Object> parseProperties(BlockType type, String[] Property propertyKey = (Property) type.getPropertyMap().get(parts[0]); if (propertyKey == null) { if (context.getActor() != null) { - throw new NoMatchException(TranslatableComponent.of( + throw new NoMatchException(Component.translatable( "worldedit.error.parser.unknown-property", - TextComponent.of(parts[0]), - TextComponent.of(type.getId()) + Component.text(parts[0]), + Component.text(type.getId()) )); } else { WorldEdit.logger.debug("Unknown property " + parts[0] + " for block " + type.getId()); @@ -172,19 +171,19 @@ private static Map, Object> parseProperties(BlockType type, String[] return Map.of(); } if (blockStates.containsKey(propertyKey)) { - throw new InputParseException(TranslatableComponent.of( + throw new InputParseException(Component.translatable( "worldedit.error.parser.duplicate-property", - TextComponent.of(parts[0]) + Component.text(parts[0]) )); } Object value; try { value = propertyKey.getValueFor(parts[1]); } catch (IllegalArgumentException e) { - throw new NoMatchException(TranslatableComponent.of( + throw new NoMatchException(Component.translatable( "worldedit.error.parser.unknown-value", - TextComponent.of(parts[1]), - TextComponent.of(propertyKey.getName()) + Component.text(parts[1]), + Component.text(propertyKey.getName()) )); } @@ -192,9 +191,9 @@ private static Map, Object> parseProperties(BlockType type, String[] } catch (InputParseException e) { throw e; // Pass-through } catch (Exception e) { - throw new InputParseException(TranslatableComponent.of( + throw new InputParseException(Component.translatable( "worldedit.error.parser.bad-state-format", - TextComponent.of(parseableData) + Component.text(parseableData) )); } } @@ -256,7 +255,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa Map, Object> blockStates = new HashMap<>(); String[] blockAndExtraData = input.trim().split("\\|"); if (blockAndExtraData.length == 0) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-block", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-block", Component.text(input))); } if (context.isTryingLegacy()) { // Perform a legacy wool colour mapping @@ -271,7 +270,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa try { String[] split = blockAndExtraData[0].split(":", 2); if (split.length == 0) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.invalid-colon")); + throw new InputParseException(Component.translatable("worldedit.error.parser.invalid-colon")); } else if (split.length == 1) { state = LegacyMapper.getInstance().getBlockFromLegacy(Integer.parseInt(split[0])); } else { @@ -300,11 +299,11 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa String stateString = null; if (stateStart != -1 && (nbtStart == -1 || stateStart < nbtStart)) { if (stateStart + 1 >= blockAndExtraData[0].length()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.hanging-lbracket", TextComponent.of(stateStart))); + throw new InputParseException(Component.translatable("worldedit.error.parser.hanging-lbracket", Component.text(stateStart))); } int stateEnd = blockAndExtraData[0].indexOf(']'); if (stateEnd < 0) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-rbracket")); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-rbracket")); } stateString = blockAndExtraData[0].substring(stateStart + 1, stateEnd); } @@ -312,19 +311,19 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa String nbtString = null; if (nbtStart != -1) { if (nbtStart + 1 >= blockAndExtraData[0].length()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.hanging-lbrace", TextComponent.of(nbtStart))); + throw new InputParseException(Component.translatable("worldedit.error.parser.hanging-lbrace", Component.text(nbtStart))); } int nbtEnd = blockAndExtraData[0].lastIndexOf('}'); if (nbtEnd < 0) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-rbrace")); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-rbrace")); } nbtString = blockAndExtraData[0].substring(nbtStart, nbtEnd + 1); } if (typeString.isEmpty()) { - throw new InputParseException(TranslatableComponent.of( + throw new InputParseException(Component.translatable( "worldedit.error.parser.bad-state-format", - TextComponent.of(blockAndExtraData[0]) + Component.text(blockAndExtraData[0]) )); } String[] stateProperties = EMPTY_STRING_ARRAY; @@ -359,7 +358,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa try { primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition(); } catch (IncompleteRegionException e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.incomplete-region")); + throw new InputParseException(Component.translatable("worldedit.error.incomplete-region")); } final BaseBlock blockInHand = world.getFullBlock(primaryPosition); @@ -372,7 +371,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa } if (blockType == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-block", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-block", Component.text(input))); } blockStates.putAll(parseProperties(blockType, stateProperties, context)); @@ -401,10 +400,10 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa try { otherTag = LinStringIO.readFromStringUsing(nbtString, LinCompoundTag::readFrom); } catch (NbtParseException e) { - throw new NoMatchException(TranslatableComponent.of( + throw new NoMatchException(Component.translatable( "worldedit.error.parser.invalid-nbt", - TextComponent.of(input), - TextComponent.of(e.getMessage()) + Component.text(input), + Component.text(e.getMessage()) )); } if (blockNbtData == null) { @@ -416,7 +415,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa } // this should be impossible but IntelliJ isn't that smart if (blockType == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-block", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-block", Component.text(input))); } // Check if the item is allowed @@ -424,7 +423,7 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa Actor actor = context.requireActor(); if (actor != null && !actor.hasPermission("worldedit.anyblock") && worldEdit.getConfiguration().disallowedBlocks.contains(blockType.getId())) { - throw new DisallowedUsageException(TranslatableComponent.of("worldedit.error.disallowed-block", TextComponent.of(input))); + throw new DisallowedUsageException(Component.translatable("worldedit.error.disallowed-block", Component.text(input))); } } @@ -451,11 +450,11 @@ private BaseBlock parseLogic(String input, ParserContext context) throws InputPa mobName = blockAndExtraData[1]; EntityType ent = EntityTypes.get(mobName.toLowerCase(Locale.ROOT)); if (ent == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-entity", TextComponent.of(mobName))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-entity", Component.text(mobName))); } mobName = ent.getId(); if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-mob", TextComponent.of(mobName))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-mob", Component.text(mobName))); } } else { mobName = EntityTypes.PIG.getId(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java index 4f3bdc927a..212fb6b0e5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java @@ -30,9 +30,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.util.HandSide; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; @@ -66,7 +65,7 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input try { String[] split = input.split(":"); if (split.length == 0) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.invalid-colon")); + throw new InputParseException(Component.translatable("worldedit.error.parser.invalid-colon")); } else if (split.length == 1) { itemType = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(split[0])); } else { @@ -89,11 +88,11 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input } else { typeString = input.substring(0, nbtStart); if (nbtStart + 1 >= input.length()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.hanging-lbrace", TextComponent.of(nbtStart))); + throw new InputParseException(Component.translatable("worldedit.error.parser.hanging-lbrace", Component.text(nbtStart))); } int stateEnd = input.lastIndexOf('}'); if (stateEnd < 0) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-rbrace")); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-rbrace")); } nbtString = input.substring(nbtStart); } @@ -111,7 +110,7 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input } if (itemType == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-item", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-item", Component.text(input))); } if (nbtString != null) { @@ -119,10 +118,10 @@ public BaseItem parseFromInput(String input, ParserContext context) throws Input try { otherTag = LinStringIO.readFromStringUsing(nbtString, LinCompoundTag::readFrom); } catch (NbtParseException e) { - throw new NoMatchException(TranslatableComponent.of( + throw new NoMatchException(Component.translatable( "worldedit.error.invalid-nbt", - TextComponent.of(input), - TextComponent.of(e.getMessage()) + Component.text(input), + Component.text(e.getMessage()) )); } if (itemNbtData == null) { @@ -142,9 +141,9 @@ private BaseItemStack getItemInHand(Actor actor, HandSide handSide) throws Input if (actor instanceof Player) { return ((Player) actor).getItemInHand(handSide); } else { - throw new InputParseException(TranslatableComponent.of( + throw new InputParseException(Component.translatable( "worldedit.error.parser.player-only", - TextComponent.of(handSide == HandSide.MAIN_HAND ? "hand" : "offhand") + Component.text(handSide == HandSide.MAIN_HAND ? "hand" : "offhand") )); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BiomeMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BiomeMaskParser.java index 8e487f45a7..75e4c2ba0e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BiomeMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BiomeMaskParser.java @@ -28,8 +28,7 @@ import com.sk89q.worldedit.function.mask.BiomeMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.biome.BiomeType; import java.util.Arrays; @@ -74,7 +73,7 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars for (String biomeName : Splitter.on(",").split(input.substring(1))) { BiomeType biome = BiomeType.REGISTRY.get(biomeName); if (biome == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-biome", TextComponent.of(biomeName))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-biome", Component.text(biomeName))); } biomes.add(biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java index 2f167aab97..ee938f03ac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java @@ -27,8 +27,7 @@ import com.sk89q.worldedit.function.mask.BlockCategoryMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockCategory; import java.util.Locale; @@ -54,7 +53,7 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars // This means it's a tag mask. BlockCategory category = BlockCategory.REGISTRY.get(input.substring(2).toLowerCase(Locale.ROOT)); if (category == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-tag", TextComponent.of(input.substring(2)))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-tag", Component.text(input.substring(2)))); } else { return new BlockCategoryMask(context.requireExtent(), category); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockStateMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockStateMaskParser.java index cc361cb496..8215f74ece 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockStateMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockStateMaskParser.java @@ -26,8 +26,7 @@ import com.sk89q.worldedit.function.mask.BlockStateMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.stream.Stream; @@ -58,7 +57,7 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars Splitter.on(',').omitEmptyStrings().trimResults().withKeyValueSeparator('=').split(states), strict); } catch (Exception e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.bad-state-format", TextComponent.of(states)), e); + throw new InputParseException(Component.translatable("worldedit.error.parser.bad-state-format", Component.text(states)), e); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExpressionMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExpressionMaskParser.java index 269f4c4811..702f9812f0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExpressionMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ExpressionMaskParser.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.session.SessionOwner; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.function.IntSupplier; import java.util.stream.Stream; @@ -67,7 +67,7 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars } return new ExpressionMask(exp); } catch (ExpressionException e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.invalid-expression")); + throw new InputParseException(Component.translatable("worldedit.error.parser.invalid-expression")); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NegateMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NegateMaskParser.java index 8059ddf957..dce3e31e25 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NegateMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/NegateMaskParser.java @@ -25,7 +25,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.stream.Stream; @@ -55,7 +55,7 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars if (input.length() > 1) { return Masks.negate(worldEdit.getMaskFactory().parseFromInput(input.substring(1), context)); } else { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.negate-nothing")); + throw new InputParseException(Component.translatable("worldedit.error.parser.negate-nothing")); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RegionMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RegionMaskParser.java index 524d8b2cff..14d48574c3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RegionMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/RegionMaskParser.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.RegionMask; import com.sk89q.worldedit.internal.registry.SimpleInputParser; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.List; @@ -49,7 +49,7 @@ public Mask parseFromSimpleInput(String input, ParserContext context) throws Inp try { return new RegionMask(context.requireSession().getSelection(context.requireWorld()).clone()); } catch (IncompleteRegionException e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.incomplete-region")); + throw new InputParseException(Component.translatable("worldedit.error.incomplete-region")); } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java index 1bf16d8aa4..6419e1fbc4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java @@ -27,8 +27,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; @@ -61,13 +60,13 @@ public Pattern parseFromInput(String input, ParserContext context) throws InputP BlockCategory category = BlockCategory.REGISTRY.get(tag); if (category == null) { - throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-tag", TextComponent.of(tag))); + throw new NoMatchException(Component.translatable("worldedit.error.unknown-tag", Component.text(tag))); } RandomPattern randomPattern = new RandomPattern(); Set blocks = category.getAll(); if (blocks.isEmpty()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.empty-tag", TextComponent.of(category.getId()))); + throw new InputParseException(Component.translatable("worldedit.error.empty-tag", Component.text(category.getId()))); } if (anyState) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java index 5c50c9b73e..3c2069c23a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/ClipboardPatternParser.java @@ -30,7 +30,7 @@ import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.Locale; import java.util.stream.Stream; @@ -79,11 +79,11 @@ public Pattern parseFromInput(String input, ParserContext context) throws InputP String coords = offsetParts[1]; if (coords.length() < 7 // min length of `[x,y,z]` || coords.charAt(0) != '[' || coords.charAt(coords.length() - 1) != ']') { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.clipboard.missing-offset")); + throw new InputParseException(Component.translatable("worldedit.error.parser.clipboard.missing-offset")); } String[] offsetSplit = coords.substring(1, coords.length() - 1).split(","); if (offsetSplit.length != 3) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.clipboard.missing-coordinates")); + throw new InputParseException(Component.translatable("worldedit.error.parser.clipboard.missing-coordinates")); } offset = BlockVector3.at( Integer.parseInt(offsetSplit[0]), @@ -98,10 +98,10 @@ public Pattern parseFromInput(String input, ParserContext context) throws InputP Clipboard clipboard = holder.getClipboard(); return new ClipboardPattern(clipboard, offset); } catch (EmptyClipboardException e) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.empty-clipboard")); + throw new InputParseException(Component.translatable("worldedit.error.empty-clipboard")); } } else { - throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-session")); + throw new InputParseException(Component.translatable("worldedit.error.missing-session")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomPatternParser.java index ab8e0cffe0..cb465151a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomPatternParser.java @@ -26,8 +26,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.List; import java.util.stream.Stream; @@ -78,7 +77,7 @@ public Pattern parseFromInput(String input, ParserContext context) throws InputP String[] p = token.split("%"); if (p.length < 2) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-random-type", TextComponent.of(input))); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-random-type", Component.text(input))); } else { chance = Double.parseDouble(p[0]); innerPattern = worldEdit.getPatternFactory().parseFromInput(p[1], context); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/TypeOrStateApplyingPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/TypeOrStateApplyingPatternParser.java index f343115bf7..0a7e654b51 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/TypeOrStateApplyingPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/TypeOrStateApplyingPatternParser.java @@ -30,8 +30,7 @@ import com.sk89q.worldedit.function.pattern.StateApplyingPattern; import com.sk89q.worldedit.function.pattern.TypeApplyingPattern; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -89,28 +88,28 @@ public Pattern parseFromInput(String input, ParserContext context) throws InputP } else { // states given if (!parts[1].endsWith("]")) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-rbracket")); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-rbracket")); } final String[] states = parts[1].substring(0, parts[1].length() - 1).split(","); Map statesToSet = new HashMap<>(); for (String state : states) { if (state.isEmpty()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.empty-state")); + throw new InputParseException(Component.translatable("worldedit.error.parser.empty-state")); } String[] propVal = state.split("=", 2); if (propVal.length != 2) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.missing-equals-separator")); + throw new InputParseException(Component.translatable("worldedit.error.parser.missing-equals-separator")); } final String prop = propVal[0]; if (prop.isEmpty()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.empty-property")); + throw new InputParseException(Component.translatable("worldedit.error.parser.empty-property")); } final String value = propVal[1]; if (value.isEmpty()) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.empty-value")); + throw new InputParseException(Component.translatable("worldedit.error.parser.empty-value")); } if (statesToSet.put(prop, value) != null) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.parser.duplicate-property", TextComponent.of(prop))); + throw new InputParseException(Component.translatable("worldedit.error.parser.duplicate-property", Component.text(prop))); } } if (type.isEmpty()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/DisallowedUsageException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/DisallowedUsageException.java index 63f3e3b363..ea54400e2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/DisallowedUsageException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/DisallowedUsageException.java @@ -19,13 +19,24 @@ package com.sk89q.worldedit.extension.input; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Thrown when usage is disallowed. */ public class DisallowedUsageException extends InputParseException { + /** + * Create with a message. + * + * @param message the message + * @deprecated use {@link DisallowedUsageException#DisallowedUsageException(Component)} instead + */ + @Deprecated + public DisallowedUsageException(com.sk89q.worldedit.util.formatting.text.Component message) { + super(message); + } + /** * Create with a message. * @@ -45,6 +56,19 @@ public DisallowedUsageException(String message) { super(message); } + + /** + * Create with a message and a cause. + * + * @param message the message + * @param cause the cause + * @deprecated use {@link DisallowedUsageException#DisallowedUsageException(Component, Throwable)} instead + */ + @Deprecated + public DisallowedUsageException(com.sk89q.worldedit.util.formatting.text.Component message, Throwable cause) { + super(message, cause); + } + /** * Create with a message and a cause. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/InputParseException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/InputParseException.java index 27e06ff17d..b1ac6880c3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/InputParseException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/InputParseException.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.extension.input; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Thrown when parsed input results in an error. @@ -36,6 +36,17 @@ public InputParseException(Component message) { super(message); } + /** + * Throw with a message. + * + * @param message the message + * @deprecated Use {@link InputParseException#InputParseException(Component)} instead + */ + @Deprecated + public InputParseException(com.sk89q.worldedit.util.formatting.text.Component message) { + super(message); + } + /** * Throw with a message. * @@ -56,6 +67,18 @@ public InputParseException(Component message, Throwable cause) { super(message, cause); } + /** + * Throw with a message and a cause. + * + * @param message the message + * @param cause the cause + * @deprecated Use {@link InputParseException#InputParseException(Component, Throwable)} instead + */ + @Deprecated + public InputParseException(com.sk89q.worldedit.util.formatting.text.Component message, Throwable cause) { + super(message, cause); + } + /** * Throw with a message and a cause. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/NoMatchException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/NoMatchException.java index 7734816b50..f85fab4b30 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/NoMatchException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/NoMatchException.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.extension.input; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Thrown when a match fails when input is parsed. @@ -35,6 +35,17 @@ public NoMatchException(Component message) { super(message); } + /** + * Create with a message. + * + * @param message the message + * @deprecated Use {@link NoMatchException#NoMatchException(Component)} + */ + @Deprecated + public NoMatchException(com.sk89q.worldedit.util.formatting.text.Component message) { + super(message); + } + /** * Create with a message. * @@ -55,6 +66,18 @@ public NoMatchException(Component message, Throwable cause) { super(message, cause); } + /** + * Create with a message and a cause. + * + * @param message the message + * @param cause the cause + * @deprecated Use {@link NoMatchException#NoMatchException(Component, Throwable)} + */ + @Deprecated + public NoMatchException(com.sk89q.worldedit.util.formatting.text.Component message, Throwable cause) { + super(message, cause); + } + /** * Create with a message and a cause. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java index 20fe0f7b40..6cebcd69c3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/input/ParserContext.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.extension.factory.MaskFactory; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import javax.annotation.Nullable; @@ -147,7 +147,7 @@ public void setActor(@Nullable Actor actor) { public Extent requireExtent() throws InputParseException { Extent extent = getExtent(); if (extent == null) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-extent")); + throw new InputParseException(Component.translatable("worldedit.error.missing-extent")); } return extent; } @@ -161,7 +161,7 @@ public Extent requireExtent() throws InputParseException { public LocalSession requireSession() throws InputParseException { LocalSession session = getSession(); if (session == null) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-session")); + throw new InputParseException(Component.translatable("worldedit.error.missing-session")); } return session; } @@ -175,7 +175,7 @@ public LocalSession requireSession() throws InputParseException { public World requireWorld() throws InputParseException { World world = getWorld(); if (world == null) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-world")); + throw new InputParseException(Component.translatable("worldedit.error.missing-world")); } return world; } @@ -189,7 +189,7 @@ public World requireWorld() throws InputParseException { public Actor requireActor() throws InputParseException { Actor actor = getActor(); if (actor == null) { - throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-actor")); + throw new InputParseException(Component.translatable("worldedit.error.missing-actor")); } return actor; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index 4282fc80f3..118b11befe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -34,8 +34,8 @@ import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TargetBlock; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.auth.AuthorizationException; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockCategories; @@ -498,13 +498,13 @@ public boolean trySetPosition(Vector3 pos) { @Override public File openFileOpenDialog(String[] extensions) { - printError(TranslatableComponent.of("worldedit.platform.no-file-dialog")); + printError(Component.translatable("worldedit.platform.no-file-dialog")); return null; } @Override public File openFileSaveDialog(String[] extensions) { - printError(TranslatableComponent.of("worldedit.platform.no-file-dialog")); + printError(Component.translatable("worldedit.platform.no-file-dialog")); return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java index cc613dac5b..9924e228de 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java @@ -22,9 +22,10 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.util.Identifiable; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.auth.Subject; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import java.io.File; import java.util.Locale; @@ -66,7 +67,11 @@ default String getDisplayName() { * @deprecated Use component-based functions (printDebug) */ @Deprecated - void printDebug(String msg); + default void printDebug(String msg) { + for (String part : msg.split("\n")) { + print(Component.text(part, NamedTextColor.GRAY)); + } + } /** * Print a WorldEdit message. @@ -75,7 +80,11 @@ default String getDisplayName() { * @deprecated Use component-based functions (printInfo) */ @Deprecated - void print(String msg); + default void print(String msg) { + for (String part : msg.split("\n")) { + print(Component.text(part, NamedTextColor.LIGHT_PURPLE)); + } + } /** * Print a WorldEdit error. @@ -84,7 +93,11 @@ default String getDisplayName() { * @deprecated Use component-based functions (printError) */ @Deprecated - void printError(String msg); + default void printError(String msg) { + for (String part : msg.split("\n")) { + print(Component.text(part, NamedTextColor.RED)); + } + } /** * Print a WorldEdit error. @@ -92,7 +105,7 @@ default String getDisplayName() { * @param component The component to print */ default void printError(Component component) { - print(component.color(TextColor.RED)); + print(component.color(NamedTextColor.RED)); } /** @@ -101,7 +114,7 @@ default void printError(Component component) { * @param component The component to print */ default void printInfo(Component component) { - print(component.color(TextColor.LIGHT_PURPLE)); + print(component.color(NamedTextColor.LIGHT_PURPLE)); } /** @@ -110,7 +123,7 @@ default void printInfo(Component component) { * @param component The component to print */ default void printDebug(Component component) { - print(component.color(TextColor.GRAY)); + print(component.color(NamedTextColor.GRAY)); } /** @@ -120,6 +133,50 @@ default void printDebug(Component component) { */ void print(Component component); + /** + * Print a WorldEdit error. + * + * @param component The component to print + * @deprecated Use {@link #printError(Component)} instead. + */ + @Deprecated + default void printError(com.sk89q.worldedit.util.formatting.text.Component component) { + print(LegacyTextHelper.adapt(component).color(NamedTextColor.RED)); + } + + /** + * Print a WorldEdit message. + * + * @param component The component to print + * @deprecated Use {@link #printInfo(Component)} instead. + */ + @Deprecated + default void printInfo(com.sk89q.worldedit.util.formatting.text.Component component) { + print(LegacyTextHelper.adapt(component).color(NamedTextColor.LIGHT_PURPLE)); + } + + /** + * Print a WorldEdit message. + * + * @param component The component to print + * @deprecated Use {@link #printDebug(Component)} instead. + */ + @Deprecated + default void printDebug(com.sk89q.worldedit.util.formatting.text.Component component) { + print(LegacyTextHelper.adapt(component).color(NamedTextColor.GRAY)); + } + + /** + * Print a {@link Component}. + * + * @param component The component to print + * @deprecated Use {@link #print(Component)} instead. + */ + @Deprecated + default void print(com.sk89q.worldedit.util.formatting.text.Component component) { + print(LegacyTextHelper.adapt(component)); + } + /** * Returns true if the actor can destroy bedrock. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 8a28f81fca..ad66cc9dc6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -107,10 +107,9 @@ import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.request.Request; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.eventbus.Subscribe; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.world.World; @@ -296,7 +295,7 @@ private void registerSubCommands(String name, List aliases, String Consumer additionalConfig) { commandManager.register(name, cmd -> { cmd.aliases(aliases); - cmd.description(TextComponent.of(desc)); + cmd.description(Component.text(desc)); cmd.action(Command.Action.NULL_ACTION); CommandManager manager = commandManagerService.newCommandManager(); @@ -308,8 +307,8 @@ private void registerSubCommands(String name, List aliases, String additionalConfig.accept(manager); final List subCommands = manager.getAllCommands().collect(Collectors.toList()); - cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"), - TextComponent.of("Sub-command to run.")) + cmd.addPart(SubCommandPart.builder(Component.translatable("worldedit.argument.action"), + Component.text("Sub-command to run.")) .withCommands(subCommands) .required() .build()); @@ -517,19 +516,19 @@ public void handleCommand(CommandEvent event) { } } catch (ConditionFailedException e) { if (e.getCondition() instanceof PermissionCondition) { - actor.printError(TranslatableComponent.of("worldedit.command.permissions")); + actor.printError(Component.translatable("worldedit.command.permissions")); } else { actor.print(e.getRichMessage()); } } catch (UsageException e) { - actor.print(TextComponent.builder("") - .color(TextColor.RED) + actor.print(Component.text() + .color(NamedTextColor.RED) .append(e.getRichMessage()) .build()); ImmutableList cmd = e.getCommands(); if (!cmd.isEmpty()) { actor.printError( - TranslatableComponent.of("worldedit.error.incorrect-usage", + Component.translatable("worldedit.error.incorrect-usage", HelpGenerator.create(e.getCommandParseResult()).getUsage()) ); } @@ -553,11 +552,11 @@ public void handleCommand(CommandEvent event) { double timeS = (time / 1000.0); int changed = editSession.getBlockChangeCount(); double throughput = timeS == 0 ? changed : changed / timeS; - actor.printDebug(TranslatableComponent.of( + actor.printDebug(Component.translatable( "worldedit.command.time-elapsed", - TextComponent.of(timeS), - TextComponent.of(changed), - TextComponent.of(Math.round(throughput)) + Component.text(timeS), + Component.text(changed), + Component.text(Math.round(throughput)) )); } @@ -577,7 +576,7 @@ private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor store.injectValue(Key.of(Player.class, OptionalArg.class), ValueProvider.constant((Player) actor)); } else { store.injectValue(Key.of(Player.class), context -> { - throw new CommandException(TranslatableComponent.of("worldedit.command.player-only"), ImmutableList.of()); + throw new CommandException(Component.translatable("worldedit.command.player-only"), ImmutableList.of()); }); } store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index 7811d2fd79..790672bca9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -29,8 +29,7 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; @@ -117,25 +116,7 @@ public World getWorld() { @Override @Deprecated public void printRaw(String msg) { - basePlayer.print(TextComponent.of(msg)); - } - - @Override - @Deprecated - public void printDebug(String msg) { - basePlayer.printDebug(TextComponent.of(msg)); - } - - @Override - @Deprecated - public void print(String msg) { - basePlayer.printInfo(TextComponent.of(msg)); - } - - @Override - @Deprecated - public void printError(String msg) { - basePlayer.printError(TextComponent.of(msg)); + basePlayer.print(Component.text(msg)); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 1eb0b64d3b..f50bbc8a4d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.extent.clipboard; -import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operation; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/BuiltInClipboardShareDestinations.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/BuiltInClipboardShareDestinations.java index 94117ea32f..76a56af0c4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/BuiltInClipboardShareDestinations.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/BuiltInClipboardShareDestinations.java @@ -23,8 +23,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; import com.sk89q.worldedit.util.paste.EngineHubPaste; import com.sk89q.worldedit.util.paste.PasteMetadata; @@ -62,7 +62,7 @@ public Consumer share(ClipboardShareMetadata metadata, ShareOutputProvide URL url = pasteService.paste(new String(Base64.getEncoder().encode(outputStream.toByteArray()), StandardCharsets.UTF_8), pasteMetadata).call(); String urlString = url.toExternalForm() + ".schem"; - return actor -> actor.printInfo(TextComponent.of(urlString).clickEvent(ClickEvent.openUrl(urlString))); + return actor -> actor.printInfo(Component.text(urlString).clickEvent(ClickEvent.openUrl(urlString))); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index 06579cbc3d..2932306425 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -35,10 +35,8 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; @@ -191,9 +189,9 @@ public void cancel() { @Override - public Iterable getStatusMessages() { - return ImmutableList.of(TranslatableComponent.of("worldedit.operation.deform.expression", - TextComponent.of(expression.getSource()).color(TextColor.LIGHT_PURPLE))); + public Iterable getMessages() { + return ImmutableList.of(Component.translatable("worldedit.operation.deform.expression", + Component.text(expression.getSource()).color(NamedTextColor.LIGHT_PURPLE))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java index 2446c9d6df..9ae6159188 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/DelegateOperation.java @@ -21,7 +21,7 @@ import com.google.common.collect.Iterables; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import static com.google.common.base.Preconditions.checkNotNull; @@ -60,8 +60,8 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return Iterables.concat(original.getStatusMessages(), delegate.getStatusMessages()); + public Iterable getMessages() { + return Iterables.concat(original.getMessages(), delegate.getMessages()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index bfd651ca29..ed308c98bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -39,10 +39,8 @@ import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import java.util.List; @@ -333,14 +331,14 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { + public Iterable getMessages() { return ImmutableList.of( - TranslatableComponent.of("worldedit.operation.affected.block", - TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), - TranslatableComponent.of("worldedit.operation.affected.biome", - TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), - TranslatableComponent.of("worldedit.operation.affected.entity", - TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) + Component.translatable("worldedit.operation.affected.block", + Component.text(affectedBlocks)).color(NamedTextColor.LIGHT_PURPLE), + Component.translatable("worldedit.operation.affected.biome", + Component.text(affectedBiomeCols)).color(NamedTextColor.LIGHT_PURPLE), + Component.translatable("worldedit.operation.affected.entity", + Component.text(affectedEntities)).color(NamedTextColor.LIGHT_PURPLE) ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java index 3b2e06959b..6823aa9ca5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java @@ -21,10 +21,11 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -79,8 +80,29 @@ default void addStatusMessages(List messages) { * operation. * * @return The status messages + * @deprecated use {@link #getMessages()} instead. default implementation returns an empty list. */ - default Iterable getStatusMessages() { + @Deprecated + default Iterable getStatusMessages() { + return Collections.emptyList(); + } + /** + * Gets an iterable of messages that describe the current status of the + * operation. + * + * @return The status messages + */ + default Iterable getMessages() { + // TODO Remove legacy code for text3 Components with WorldEdit 8.0.0 + Iterable legacyComponents = getStatusMessages(); + if (legacyComponents.iterator().hasNext()) { + List components = new ArrayList<>(); + for (com.sk89q.worldedit.util.formatting.text.Component legacyComponent : legacyComponents) { + components.add(LegacyTextHelper.adapt(legacyComponent)); + } + return components; + } + // TODO Remove legacy code WorldEdit 8.0.0 List oldMessages = new ArrayList<>(); addStatusMessages(oldMessages); @@ -91,6 +113,6 @@ default Iterable getStatusMessages() { warnedDeprecatedClasses.add(className); } } - return oldMessages.stream().map(TextComponent::of).collect(Collectors.toList()); + return oldMessages.stream().map(Component::text).collect(Collectors.toList()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java index f9a494c840..918e8cce70 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/OperationQueue.java @@ -22,7 +22,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.ArrayDeque; import java.util.Collection; @@ -107,8 +107,8 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return Iterables.concat(operations.stream().map(Operation::getStatusMessages).toList()); + public Iterable getMessages() { + return Iterables.concat(operations.stream().map(Operation::getMessages).toList()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 59e57b0c73..61655006ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -26,10 +26,8 @@ import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import java.util.ArrayDeque; import java.util.ArrayList; @@ -186,11 +184,11 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return ImmutableList.of(TranslatableComponent.of( + public Iterable getMessages() { + return ImmutableList.of(Component.translatable( "worldedit.operation.affected.block", - TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + Component.text(getAffected()) + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java index f506082519..f9af889c53 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java @@ -25,10 +25,8 @@ import com.sk89q.worldedit.function.EntityFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import java.util.Iterator; @@ -81,11 +79,11 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return ImmutableList.of(TranslatableComponent.of( + public Iterable getMessages() { + return ImmutableList.of(Component.translatable( "worldedit.operation.affected.entity", - TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + Component.text(getAffected()) + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 0012437339..a85543c007 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -26,10 +26,8 @@ import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.FlatRegion; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import static com.google.common.base.Preconditions.checkNotNull; @@ -81,11 +79,11 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return ImmutableList.of(TranslatableComponent.of( + public Iterable getMessages() { + return ImmutableList.of(Component.translatable( "worldedit.operation.affected.column", - TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + Component.text(getAffected()) + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 3a627d9355..959b3edb49 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -26,10 +26,8 @@ import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; /** * Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}. @@ -70,11 +68,11 @@ public void cancel() { } @Override - public Iterable getStatusMessages() { - return ImmutableList.of(TranslatableComponent.of( + public Iterable getMessages() { + return ImmutableList.of(Component.translatable( "worldedit.operation.affected.block", - TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + Component.text(getAffected()) + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java index 63206564af..7da3633882 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java @@ -24,11 +24,10 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.PlatformCommandManager; import com.sk89q.worldedit.internal.util.Substring; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; -import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.NoInputCommandParameters; @@ -50,14 +49,14 @@ public class CommandUtil { - private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated."); + private static final Component DEPRECATION_MARKER = Component.text("This command is deprecated."); private static Component makeDeprecatedFooter(String reason, Component replacement) { - return TextComponent.builder() + return Component.text() .append(DEPRECATION_MARKER) - .append(" " + reason + ".") - .append(TextComponent.newline()) - .append(replacement.color(TextColor.GOLD)) + .append(Component.text(" " + reason + ".")) + .append(Component.newline()) + .append(replacement.color(NamedTextColor.GOLD)) .build(); } @@ -85,12 +84,11 @@ static ReplacementMessageGenerator forNewCommand(NewCommandGenerator generator) } public static Component createNewCommandReplacementText(String suggestedCommand) { - return TextComponent.builder("Please use ", TextColor.GOLD) - .append(TextComponent.of(suggestedCommand) + return Component.text("Please use ", NamedTextColor.GOLD) + .append(Component.text(suggestedCommand) .decoration(TextDecoration.UNDERLINED, true) .clickEvent(ClickEvent.suggestCommand(suggestedCommand))) - .append(" instead.") - .build(); + .append(Component.text(" instead.")); } public static Command deprecate(Command command, String reason, @@ -107,7 +105,7 @@ public static Command deprecate(Command command, String reason, deprecatedCommandWarning(parameters, command, reason, replacementMessageGenerator)) .footer(command.getFooter() .map(existingFooter -> existingFooter - .append(TextComponent.newline()) + .append(Component.newline()) .append(deprecatedWarning)) .orElse(deprecatedWarning)) .build(); @@ -141,7 +139,7 @@ private static boolean anyComponent(Component component, Predicate te private static Component replaceDeprecation(Component component) { if (component.children().stream().anyMatch(Predicate.isEqual(DEPRECATION_MARKER))) { - return TextComponent.empty(); + return Component.empty(); } return component.children( component.children().stream() @@ -183,9 +181,7 @@ private static void sendDeprecationMessage( ) { Component replacement = generator.getReplacement(command, parameters); actor.print( - TextComponent.builder(reason + ". ", TextColor.GOLD) - .append(replacement) - .build() + Component.text(reason + ". ", NamedTextColor.GOLD).append(replacement) ); } @@ -269,7 +265,7 @@ private static Optional suggestLast(Substring last, Substring suggestion * @param message the message for failure */ public static void checkCommandArgument(boolean condition, String message) { - checkCommandArgument(condition, TextComponent.of(message)); + checkCommandArgument(condition, Component.text(message)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java index 22cc824e00..422c3244d0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/WorldEditExceptionConverter.java @@ -36,9 +36,7 @@ import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.regions.RegionOperationException; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.InvalidFilenameException; @@ -64,7 +62,7 @@ public WorldEditExceptionConverter(WorldEdit worldEdit) { } private CommandException newCommandException(String message, Throwable cause) { - return newCommandException(TextComponent.of(String.valueOf(message)), cause); + return newCommandException(Component.text(String.valueOf(message)), cause); } private CommandException newCommandException(Component message, Throwable cause) { @@ -76,47 +74,47 @@ public void convert(NumberFormatException e) throws CommandException { final Matcher matcher = numberFormat.matcher(e.getMessage()); if (matcher.matches()) { - throw newCommandException(TranslatableComponent.of("worldedit.error.invalid-number.matches", TextComponent.of(matcher.group(1))), e); + throw newCommandException(Component.translatable("worldedit.error.invalid-number.matches", Component.text(matcher.group(1))), e); } else { - throw newCommandException(TranslatableComponent.of("worldedit.error.invalid-number"), e); + throw newCommandException(Component.translatable("worldedit.error.invalid-number"), e); } } @ExceptionMatch public void convert(IncompleteRegionException e) throws CommandException { - throw newCommandException(TranslatableComponent.of("worldedit.error.incomplete-region"), e); + throw newCommandException(Component.translatable("worldedit.error.incomplete-region"), e); } @ExceptionMatch public void convert(MissingWorldException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch public void convert(NoMatchException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @Deprecated @ExceptionMatch public void convert(InvalidItemException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch public void convert(DisallowedUsageException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch public void convert(MaxChangedBlocksException e) throws CommandException { - throw newCommandException(TranslatableComponent.of("worldedit.error.max-changes", TextComponent.of(e.getBlockLimit())), e); + throw newCommandException(Component.translatable("worldedit.error.max-changes", Component.text(e.getBlockLimit())), e); } @ExceptionMatch public void convert(MaxBrushRadiusException e) throws CommandException { throw newCommandException( - TranslatableComponent.of("worldedit.error.max-brush-radius", TextComponent.of(worldEdit.getConfiguration().maxBrushRadius)), + Component.translatable("worldedit.error.max-brush-radius", Component.text(worldEdit.getConfiguration().maxBrushRadius)), e ); } @@ -124,24 +122,24 @@ public void convert(MaxBrushRadiusException e) throws CommandException { @ExceptionMatch public void convert(MaxRadiusException e) throws CommandException { throw newCommandException( - TranslatableComponent.of("worldedit.error.max-radius", TextComponent.of(worldEdit.getConfiguration().maxRadius)), + Component.translatable("worldedit.error.max-radius", Component.text(worldEdit.getConfiguration().maxRadius)), e ); } @ExceptionMatch public void convert(UnknownDirectionException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch public void convert(InsufficientArgumentsException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch public void convert(RegionOperationException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } @ExceptionMatch @@ -151,13 +149,13 @@ public void convert(ExpressionException e) throws CommandException { @ExceptionMatch public void convert(EmptyClipboardException e) throws CommandException { - throw newCommandException(TranslatableComponent.of("worldedit.error.empty-clipboard"), e); + throw newCommandException(Component.translatable("worldedit.error.empty-clipboard"), e); } @ExceptionMatch public void convert(InvalidFilenameException e) throws CommandException { throw newCommandException( - TranslatableComponent.of("worldedit.error.invalid-filename", TextComponent.of(e.getFilename()), e.getRichMessage()), + Component.translatable("worldedit.error.invalid-filename", Component.text(e.getFilename()), e.getTextMessage()), e ); } @@ -165,7 +163,7 @@ public void convert(InvalidFilenameException e) throws CommandException { @ExceptionMatch public void convert(FilenameResolutionException e) throws CommandException { throw newCommandException( - TranslatableComponent.of("worldedit.error.file-resolution", TextComponent.of(e.getFilename()), e.getRichMessage()), + Component.translatable("worldedit.error.file-resolution", Component.text(e.getFilename()), e.getTextMessage()), e ); } @@ -173,19 +171,19 @@ public void convert(FilenameResolutionException e) throws CommandException { @ExceptionMatch public void convert(InvalidToolBindException e) throws CommandException { throw newCommandException( - TranslatableComponent.of("worldedit.tool.error.cannot-bind", e.getItemType().getRichName(), e.getRichMessage()), + Component.translatable("worldedit.tool.error.cannot-bind", e.getItemType().getDisplayName(), e.getTextMessage()), e ); } @ExceptionMatch public void convert(FileSelectionAbortedException e) throws CommandException { - throw newCommandException(TranslatableComponent.of("worldedit.error.file-aborted"), e); + throw newCommandException(Component.translatable("worldedit.error.file-aborted"), e); } @ExceptionMatch public void convert(WorldEditException e) throws CommandException { - throw newCommandException(e.getRichMessage(), e); + throw newCommandException(e.getTextMessage(), e); } // Prevent investigation into UsageExceptions diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java index 008a112311..572061b468 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/registry/AbstractFactory.java @@ -23,8 +23,7 @@ import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import java.util.ArrayList; import java.util.Collections; @@ -81,7 +80,7 @@ public E parseFromInput(String input, ParserContext context) throws InputParseEx } } - throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input))); + throw new NoMatchException(Component.translatable("worldedit.error.no-match", Component.text(input))); } @Deprecated diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/ErrorReporting.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/ErrorReporting.java index 9bdb555ad6..b379ce0d20 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/ErrorReporting.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/ErrorReporting.java @@ -21,21 +21,20 @@ import com.google.common.base.Throwables; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; /** * Simple class for handling error reporting to users. */ public class ErrorReporting { public static void trigger(Actor actor, Throwable error) { - actor.printError(TranslatableComponent.of("worldedit.command.error.report")); - TextComponent.Builder errorBuilder = TextComponent.builder(error.getClass().getName() + ": " + error.getMessage()); + actor.printError(Component.translatable("worldedit.command.error.report")); + Component errorBuilder = Component.text(error.getClass().getName() + ": " + error.getMessage()); if (actor.hasPermission("worldedit.error.detailed")) { - errorBuilder = errorBuilder.hoverEvent(HoverEvent.showText(TextComponent.of(Throwables.getStackTraceAsString(error)))); + errorBuilder = errorBuilder.hoverEvent(HoverEvent.showText(Component.text(Throwables.getStackTraceAsString(error)))); } - actor.print(errorBuilder.build()); + actor.print(errorBuilder); } private ErrorReporting() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index a60ac22d44..d025d92785 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -27,7 +27,7 @@ import com.sk89q.worldedit.math.geom.Polygons; import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator; import com.sk89q.worldedit.regions.iterator.FlatRegionIterator; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.math.BigDecimal; @@ -220,7 +220,7 @@ private BlockVector2 calculateDiff2D(BlockVector3... changes) throws RegionOpera } if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.cylinder.error.even-horizontal")); + throw new RegionOperationException(Component.translatable("worldedit.selection.cylinder.error.even-horizontal")); } return diff.divide(2).floor(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index 43680f80bb..9ed638dbee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -22,7 +22,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -114,7 +114,7 @@ private BlockVector3 calculateDiff(BlockVector3... changes) throws RegionOperati BlockVector3 diff = BlockVector3.ZERO.add(changes); if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.ellipsoid.error.even-horizontal")); + throw new RegionOperationException(Component.translatable("worldedit.selection.ellipsoid.error.even-horizontal")); } return diff.divide(2).floor(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java index b3e80ca26e..6cf7b52860 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java @@ -22,7 +22,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.Collections; @@ -75,17 +75,17 @@ public int getLength() { @Override public void expand(BlockVector3... changes) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable")); + throw new RegionOperationException(Component.translatable("worldedit.selection.null.error.immutable")); } @Override public void contract(BlockVector3... changes) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable")); + throw new RegionOperationException(Component.translatable("worldedit.selection.null.error.immutable")); } @Override public void shift(BlockVector3 change) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.null.error.immutable")); + throw new RegionOperationException(Component.translatable("worldedit.selection.null.error.immutable")); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index 885920be2f..22d4c2e3c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -23,7 +23,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator; import com.sk89q.worldedit.regions.iterator.FlatRegionIterator; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.math.BigDecimal; @@ -246,7 +246,7 @@ public int getLength() { public void expand(BlockVector3... changes) throws RegionOperationException { for (BlockVector3 change : changes) { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.polygon2d.error.expand-only-vertical")); + throw new RegionOperationException(Component.translatable("worldedit.selection.polygon2d.error.expand-only-vertical")); } int changeY = change.getBlockY(); if (changeY > 0) { @@ -262,7 +262,7 @@ public void expand(BlockVector3... changes) throws RegionOperationException { public void contract(BlockVector3... changes) throws RegionOperationException { for (BlockVector3 change : changes) { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.polygon2d.error.contract-only-vertical")); + throw new RegionOperationException(Component.translatable("worldedit.selection.polygon2d.error.contract-only-vertical")); } int changeY = change.getBlockY(); if (changeY > 0) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java index e9f725e35b..5c7dfd461d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java @@ -21,7 +21,7 @@ import com.google.common.collect.Iterators; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -110,13 +110,13 @@ public BlockVector3 getMaximumPoint() { @Override public void expand(BlockVector3... changes) throws RegionOperationException { checkNotNull(changes); - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.intersection.error.cannot-expand")); + throw new RegionOperationException(Component.translatable("worldedit.selection.intersection.error.cannot-expand")); } @Override public void contract(BlockVector3... changes) throws RegionOperationException { checkNotNull(changes); - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.intersection.error.cannot-contract")); + throw new RegionOperationException(Component.translatable("worldedit.selection.intersection.error.cannot-contract")); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java index a6701cf987..f58d6cac22 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionOperationException.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.regions; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; public class RegionOperationException extends WorldEditException { @@ -29,6 +29,11 @@ public RegionOperationException(String msg) { super(msg); } + @Deprecated + public RegionOperationException(com.sk89q.worldedit.util.formatting.text.Component msg) { + super(msg); + } + public RegionOperationException(Component msg) { super(msg); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 3d7a0efc36..5fd9d198ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -27,9 +27,9 @@ import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.world.World; import java.util.List; @@ -190,10 +190,20 @@ default List getInformationLines() { * Get lines of information about the selection. * * @return a list of lines describing the region. + * @deprecated */ - default List getSelectionInfoLines() { + default List getSelectionInfoLines() { + return getSelectionInformationLines().stream().map(LegacyTextHelper::adapt).toList(); + } + + /** + * Get lines of information about the selection. + * + * @return a list of lines describing the region. + */ + default List getSelectionInformationLines() { return getInformationLines().stream() - .map(line -> TextComponent.of(line, TextColor.LIGHT_PURPLE)) + .map(line -> Component.text(line, NamedTextColor.LIGHT_PURPLE)) .collect(Collectors.toList()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java index 4aa5754f9c..5384bf730b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -134,17 +134,17 @@ public int getLength() { @Override public void expand(BlockVector3... changes) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-expand")); + throw new RegionOperationException(Component.translatable("worldedit.selection.transform.error.cannot-expand")); } @Override public void contract(BlockVector3... changes) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-contract")); + throw new RegionOperationException(Component.translatable("worldedit.selection.transform.error.cannot-contract")); } @Override public void shift(BlockVector3 change) throws RegionOperationException { - throw new RegionOperationException(TranslatableComponent.of("worldedit.selection.transform.error.cannot-change")); + throw new RegionOperationException(Component.translatable("worldedit.selection.transform.error.cannot-change")); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java index 6e023128b7..f718834538 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java @@ -33,9 +33,7 @@ import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.polyhedron.Triangle; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -185,11 +183,11 @@ public String getTypeName() { } @Override - public List getSelectionInfoLines() { + public List getSelectionInformationLines() { List ret = new ArrayList<>(); - ret.add(TranslatableComponent.of("worldedit.selection.convex.info.vertices", TextComponent.of(region.getVertices().size()))); - ret.add(TranslatableComponent.of("worldedit.selection.convex.info.triangles", TextComponent.of(region.getTriangles().size()))); + ret.add(Component.translatable("worldedit.selection.convex.info.vertices", Component.text(region.getVertices().size()))); + ret.add(Component.translatable("worldedit.selection.convex.info.triangles", Component.text(region.getTriangles().size()))); return ret; } @@ -203,7 +201,7 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID())); session.describeCUI(player); - player.printInfo(TranslatableComponent.of("worldedit.selection.convex.explain.primary", TextComponent.of(pos.toString()))); + player.printInfo(Component.translatable("worldedit.selection.convex.explain.primary", Component.text(pos.toString()))); } @Override @@ -214,7 +212,7 @@ public void explainSecondarySelection(Actor player, LocalSession session, BlockV session.describeCUI(player); - player.printInfo(TranslatableComponent.of("worldedit.selection.convex.explain.secondary", TextComponent.of(pos.toString()))); + player.printInfo(Component.translatable("worldedit.selection.convex.explain.secondary", Component.text(pos.toString()))); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index 05b1061ec1..ca5db4a7ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -30,11 +30,9 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -158,13 +156,13 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec checkNotNull(pos); if (position1 != null && position2 != null) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.cuboid.explain.primary-area", - TextComponent.of(position1.toString()), - TextComponent.of(region.getVolume()) + Component.text(position1.toString()), + Component.text(region.getVolume()) )); } else if (position1 != null) { - player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.primary", TextComponent.of(position1.toString()))); + player.printInfo(Component.translatable("worldedit.selection.cuboid.explain.primary", Component.text(position1.toString()))); } session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getVolume())); @@ -177,13 +175,13 @@ public void explainSecondarySelection(Actor player, LocalSession session, BlockV checkNotNull(pos); if (position1 != null && position2 != null) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.cuboid.explain.secondary-area", - TextComponent.of(position2.toString()), - TextComponent.of(region.getVolume()) + Component.text(position2.toString()), + Component.text(region.getVolume()) )); } else if (position2 != null) { - player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.secondary", TextComponent.of(position2.toString()))); + player.printInfo(Component.translatable("worldedit.selection.cuboid.explain.secondary", Component.text(position2.toString()))); } session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getVolume())); @@ -253,19 +251,19 @@ public String getTypeName() { } @Override - public List getSelectionInfoLines() { + public List getSelectionInformationLines() { final List lines = new ArrayList<>(); if (position1 != null) { - lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos1", TextComponent.of(position1.toString()) - .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, position1.toParserString())) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); + lines.add(Component.translatable("worldedit.selection.cuboid.info.pos1", Component.text(position1.toString()) + .clickEvent(ClickEvent.copyToClipboard(position1.toParserString())) + .hoverEvent(HoverEvent.showText(Component.text("Click to copy"))))); } if (position2 != null) { - lines.add(TranslatableComponent.of("worldedit.selection.cuboid.info.pos2", TextComponent.of(position2.toString()) - .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, position2.toParserString())) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); + lines.add(Component.translatable("worldedit.selection.cuboid.info.pos2", Component.text(position2.toString()) + .clickEvent(ClickEvent.copyToClipboard(position2.toParserString())) + .hoverEvent(HoverEvent.showText(Component.text("Click to copy"))))); } return lines; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java index 7a685cbe9d..e90caeacd2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java @@ -34,11 +34,9 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.text.NumberFormat; @@ -184,7 +182,7 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { @Override public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { - player.printInfo(TranslatableComponent.of("worldedit.selection.cylinder.explain.primary", TextComponent.of(pos.toString()))); + player.printInfo(Component.translatable("worldedit.selection.cylinder.explain.primary", Component.text(pos.toString()))); session.describeCUI(player); } @@ -192,14 +190,14 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec @Override public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (selectedCenter) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.cylinder.explain.secondary", - TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getX())), - TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getZ())), - TextComponent.of(region.getVolume()) + Component.text(NUMBER_FORMAT.format(region.getRadius().getX())), + Component.text(NUMBER_FORMAT.format(region.getRadius().getZ())), + Component.text(region.getVolume()) )); } else { - player.printError(TranslatableComponent.of("worldedit.selection.cylinder.explain.secondary-missing")); + player.printError(Component.translatable("worldedit.selection.cylinder.explain.secondary-missing")); return; } @@ -255,17 +253,17 @@ public String getTypeName() { } @Override - public List getSelectionInfoLines() { + public List getSelectionInformationLines() { final List lines = new ArrayList<>(); if (!region.getCenter().equals(Vector3.ZERO)) { Vector3 center = region.getCenter(); - lines.add(TranslatableComponent.of("worldedit.selection.cylinder.info.center", TextComponent.of(center.toString()) - .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); + lines.add(Component.translatable("worldedit.selection.cylinder.info.center", Component.text(center.toString()) + .clickEvent(ClickEvent.copyToClipboard(center.toParserString())) + .hoverEvent(HoverEvent.showText(Component.text("Click to copy"))))); } if (!region.getRadius().equals(Vector2.ZERO)) { - lines.add(TranslatableComponent.of("worldedit.selection.cylinder.info.radius", TextComponent.of(region.getRadius().toString()))); + lines.add(Component.translatable("worldedit.selection.cylinder.info.radius", Component.text(region.getRadius().toString()))); } return lines; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index 32036bfa69..d359f1a9c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -31,11 +31,9 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -161,15 +159,15 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { @Override public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.ellipsoid.explain.primary-area", - TextComponent.of(region.getCenter().toString()), - TextComponent.of(region.getVolume()) + Component.text(region.getCenter().toString()), + Component.text(region.getVolume()) )); } else { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.ellipsoid.explain.primary", - TextComponent.of(region.getCenter().toString()) + Component.text(region.getCenter().toString()) )); } @@ -179,15 +177,15 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec @Override public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.ellipsoid.explain.secondary-area", - TextComponent.of(region.getRadius().toString()), - TextComponent.of(region.getVolume()) + Component.text(region.getRadius().toString()), + Component.text(region.getVolume()) )); } else { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.ellipsoid.explain.secondary", - TextComponent.of(region.getRadius().toString()) + Component.text(region.getRadius().toString()) )); } @@ -235,19 +233,19 @@ public String getTypeName() { } @Override - public List getSelectionInfoLines() { + public List getSelectionInformationLines() { final List lines = new ArrayList<>(); final Vector3 center = region.getCenter(); if (center.lengthSq() > 0) { - lines.add(TranslatableComponent.of("worldedit.selection.ellipsoid.info.center", TextComponent.of(center.toString()) - .clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy"))))); + lines.add(Component.translatable("worldedit.selection.ellipsoid.info.center", Component.text(center.toString()) + .clickEvent(ClickEvent.copyToClipboard(center.toParserString())) + .hoverEvent(HoverEvent.showText(Component.text("Click to copy"))))); } final Vector3 radius = region.getRadius(); if (radius.lengthSq() > 0) { - lines.add(TranslatableComponent.of("worldedit.selection.ellipsoid.info.radius", TextComponent.of(radius.toString()))); + lines.add(Component.translatable("worldedit.selection.ellipsoid.info.radius", Component.text(radius.toString()))); } return lines; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java index 82cd540d3f..215b25b9d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java @@ -24,8 +24,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import javax.annotation.Nullable; @@ -131,10 +130,10 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { @Override public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.extend.explain.primary", - TextComponent.of(pos.toString()), - TextComponent.of(region.getVolume()) + Component.text(pos.toString()), + Component.text(region.getVolume()) )); explainRegionAdjust(player, session); @@ -142,10 +141,10 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec @Override public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.extend.explain.secondary", - TextComponent.of(pos.toString()), - TextComponent.of(region.getVolume()) + Component.text(pos.toString()), + Component.text(region.getVolume()) )); explainRegionAdjust(player, session); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java index c959db9247..7d643e8635 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java @@ -32,9 +32,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import java.util.Collections; @@ -165,7 +163,7 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { @Override public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { - player.printInfo(TranslatableComponent.of("worldedit.selection.polygon2d.explain.primary", TextComponent.of(pos.toString()))); + player.printInfo(Component.translatable("worldedit.selection.polygon2d.explain.primary", Component.text(pos.toString()))); session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID())); session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getVolume())); @@ -174,10 +172,10 @@ public void explainPrimarySelection(Actor player, LocalSession session, BlockVec @Override public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.polygon2d.explain.secondary", - TextComponent.of(region.size()), - TextComponent.of(pos.toString()) + Component.text(region.size()), + Component.text(pos.toString()) )); session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getVolume())); @@ -236,8 +234,8 @@ public String getTypeName() { } @Override - public List getSelectionInfoLines() { - return Collections.singletonList(TranslatableComponent.of("worldedit.selection.polygon2d.info", TextComponent.of(region.size()))); + public List getSelectionInformationLines() { + return Collections.singletonList(Component.translatable("worldedit.selection.polygon2d.info", Component.text(region.size()))); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java index 0d0f1ea2d8..71905a423f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java @@ -25,8 +25,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.World; import javax.annotation.Nullable; @@ -94,13 +93,13 @@ public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { @Override public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { - player.printInfo(TranslatableComponent.of( + player.printInfo(Component.translatable( "worldedit.selection.sphere.explain.secondary-defined", - TextComponent.of(region.getRadius().getX()), - TextComponent.of(region.getVolume()) + Component.text(region.getRadius().getX()), + Component.text(region.getVolume()) )); } else { - player.printInfo(TranslatableComponent.of("worldedit.selection.sphere.explain.secondary", TextComponent.of(region.getRadius().getX()))); + player.printInfo(Component.translatable("worldedit.selection.sphere.explain.secondary", Component.text(region.getRadius().getX()))); } session.describeCUI(player); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java index d4e4cdf0e1..443c2f0d3e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/CraftScriptContext.java @@ -33,8 +33,7 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.expression.invoke.ReturnException; import com.sk89q.worldedit.session.request.Request; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.world.block.BaseBlock; @@ -119,7 +118,7 @@ public List getEditSessions() { * @param message a message */ public void print(String message) { - player.printInfo(TextComponent.of(message)); + player.printInfo(Component.text(message)); } /** @@ -128,7 +127,7 @@ public void print(String message) { * @param message a message */ public void error(String message) { - player.printError(TextComponent.of(message)); + player.printError(Component.text(message)); } /** @@ -137,7 +136,7 @@ public void error(String message) { * @param message a message */ public void printRaw(String message) { - player.print(TextComponent.of(message)); + player.print(Component.text(message)); } /** @@ -151,7 +150,7 @@ public void printRaw(String message) { public void checkArgs(int min, int max, String usage) throws InsufficientArgumentsException { if (args.length <= min || (max != -1 && args.length - 1 > max)) { - throw new InsufficientArgumentsException(TranslatableComponent.of("worldedit.error.incorrect-usage", TextComponent.of(usage))); + throw new InsufficientArgumentsException(Component.translatable("worldedit.error.incorrect-usage", Component.text(usage))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java index 15d3d89140..edcf62dd47 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java @@ -23,9 +23,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; public class Placement { private final PlacementType placementType; @@ -53,15 +52,20 @@ public boolean canBeUsedBy(Actor actor) { return placementType.canBeUsedBy(actor); } - public Component getInfo() { + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component getInfo() { + return LegacyTextHelper.adapt(getInformation()); + } + + public Component getInformation() { if (offset.equals(BlockVector3.ZERO)) { - return TranslatableComponent.of(placementType.getTranslationKey()); + return Component.translatable(placementType.getTranslationKey()); } else { - return TranslatableComponent.of( + return Component.translatable( placementType.getTranslationKeyWithOffset(), - TextComponent.of(offset.getX()), - TextComponent.of(offset.getY()), - TextComponent.of(offset.getZ()) + Component.text(offset.getX()), + Component.text(offset.getY()), + Component.text(offset.getZ()) ); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/auth/AuthorizationException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/auth/AuthorizationException.java index ee2d55ac92..bf84ea6cfa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/auth/AuthorizationException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/auth/AuthorizationException.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.auth; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Raised when authorization is not granted. @@ -30,6 +30,11 @@ public class AuthorizationException extends WorldEditException { public AuthorizationException() { } + @Deprecated + public AuthorizationException(com.sk89q.worldedit.util.formatting.text.Component message) { + super(message); + } + public AuthorizationException(Component message) { super(message); } @@ -39,6 +44,11 @@ public AuthorizationException(String message) { super(message); } + @Deprecated + public AuthorizationException(com.sk89q.worldedit.util.formatting.text.Component message, Throwable cause) { + super(message, cause); + } + public AuthorizationException(Component message, Throwable cause) { super(message, cause); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/LegacyTextHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/LegacyTextHelper.java new file mode 100644 index 0000000000..f5669e4246 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/LegacyTextHelper.java @@ -0,0 +1,45 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting; + +import com.google.common.base.Preconditions; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; + +/** + * Converts adventure text components to kyori text components. + * @deprecated only used to convert from text3 to adventure and back + */ +@Deprecated +public class LegacyTextHelper { + public static Component adapt(com.sk89q.worldedit.util.formatting.text.Component toAdapt) { + Preconditions.checkNotNull(toAdapt); + return GsonComponentSerializer.gson().deserialize( + com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(toAdapt) + ); + } + + public static com.sk89q.worldedit.util.formatting.text.Component adapt(Component toAdapt) { + Preconditions.checkNotNull(toAdapt); + return com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer.INSTANCE.deserialize( + GsonComponentSerializer.gson().serialize(toAdapt) + ); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java index fd50c81d7e..31ae323e5f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.util.formatting; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.enginehub.piston.config.ConfigHolder; import org.enginehub.piston.config.ConfigRenderer; import org.enginehub.piston.config.TextConfig; @@ -36,15 +37,25 @@ public class WorldEditText { CONFIG_HOLDER.getConfig(TextConfig.commandPrefix()).setValue("/"); } + @Deprecated + public static com.sk89q.worldedit.util.formatting.text.Component format(com.sk89q.worldedit.util.formatting.text.Component component, Locale locale) { + return LegacyTextHelper.adapt(format(LegacyTextHelper.adapt(component), locale)); + } + public static Component format(Component component, Locale locale) { - return WorldEdit.getInstance().getTranslationManager().convertText( + return WorldEdit.getInstance().getTranslationManager().convert( RENDERER.render(component, CONFIG_HOLDER), locale ); } + @Deprecated + public static String reduceToText(com.sk89q.worldedit.util.formatting.text.Component component, Locale locale) { + return reduceToText(LegacyTextHelper.adapt(component), locale); + } + public static String reduceToText(Component component, Locale locale) { - return TextHelper.reduceToText(format(component, locale)); + return PlainTextComponentSerializer.plainText().serialize(format(component, locale)); } private WorldEditText() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandListBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandListBox.java new file mode 100644 index 0000000000..9e6d30dd26 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandListBox.java @@ -0,0 +1,109 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.google.common.collect.Lists; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; + +import java.util.List; + +public class CommandListBox extends PaginationBox { + + private final List commands = Lists.newArrayList(); + private final String helpCommand; + private boolean hideHelp; + + /** + * Create a new box. + * + * @param title the title + */ + public CommandListBox(String title, String pageCommand, String helpCommand) { + super(title, pageCommand); + this.helpCommand = helpCommand; + } + + @Override + public Component component(int number) { + return commands.get(number).createComponent(hideHelp); + } + + @Override + public int getComponentsSize() { + return commands.size(); + } + + + + public void appendCommand(String alias, Component description) { + appendCommand(alias, description, null); + } + + @Deprecated + public void appendCommand(String alias, String description, String insertion) { + appendCommand(alias, Component.text(description), insertion); + } + + public void appendCommand(String alias, Component description, String insertion) { + commands.add(new CommandEntry(alias, description, insertion)); + } + + public boolean isHidingHelp() { + return hideHelp; + } + + public void setHidingHelp(boolean hideHelp) { + this.hideHelp = hideHelp; + } + + private class CommandEntry { + private final String alias; + private final Component description; + private final String insertion; + + CommandEntry(String alias, Component description, String insertion) { + this.alias = alias; + this.description = description; + this.insertion = insertion; + } + + Component createComponent(boolean hideHelp) { + TextComponent.Builder line = Component.text(); + if (!hideHelp) { + line.append(Component.text("? ") + .clickEvent(ClickEvent.runCommand(CommandListBox.this.helpCommand + " " + insertion)) + .hoverEvent(HoverEvent.showText(Component.text("Additional Help")))); + } + TextComponent command = Component.text(alias, NamedTextColor.GOLD); + if (insertion == null) { + line.append(command); + } else { + line.append(command + .clickEvent(ClickEvent.suggestCommand(insertion)) + .hoverEvent(HoverEvent.showText(Component.text("Click to select")))); + } + return line.append(Component.text(": ")).append(description).build(); + } + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandUsageBox.java new file mode 100644 index 0000000000..9cc8b6096b --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/CommandUsageBox.java @@ -0,0 +1,93 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.google.common.collect.Iterables; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; +import org.enginehub.piston.Command; +import org.enginehub.piston.CommandParameters; +import org.enginehub.piston.config.ColorConfig; +import org.enginehub.piston.util.HelpGenerator; + +import java.util.List; +import javax.annotation.Nullable; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.internal.command.CommandUtil.getSubCommands; + +/** + * A box to describe usage of a command. + */ +public class CommandUsageBox { + + private final TextComponent.Builder builder = Component.text(); + + /** + * Create a new usage box. + * + * @param commands the commands to describe + * @param commandString the commands that were used, such as "/we" or "/brush sphere" + * @param helpRootCommand the command used to get subcommand help + */ + public CommandUsageBox(List commands, String commandString, String helpRootCommand) throws InvalidComponentException { + this(commands, commandString, helpRootCommand, null); + } + + /** + * Create a new usage box. + * + * @param commands the commands to describe + * @param commandString the commands that were used, such as "/we" or "/brush sphere" + * @param helpRootCommand the command used to get subcommand help + * @param parameters list of parameters to use + */ + public CommandUsageBox(List commands, String commandString, String helpRootCommand, + @Nullable CommandParameters parameters) throws InvalidComponentException { + checkNotNull(commands); + checkNotNull(commandString); + checkNotNull(helpRootCommand); + attachCommandUsage(commands, commandString, helpRootCommand); + } + + private void attachCommandUsage(List commands, String commandString, String helpRootCommand) { + TextComponent.Builder b = Component.text(); + b.append(HelpGenerator.create(commands).getFullHelp()); + if (getSubCommands(Iterables.getLast(commands)).size() > 0) { + b.append(Component.newline()) + .append(ColorConfig.helpText().wrap(Component.text("> ") + .append(ColorConfig.mainText().wrap(Component.text("List Subcommands") + .decoration(TextDecoration.ITALIC, true) + .clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString)) + .hoverEvent(HoverEvent.showText(Component.text("List all subcommands of this command"))) + )) + )); + } + MessageBox box = new MessageBox("Help for " + commandString, b.build()); + builder.append(box.build()); + } + + public Component build() { + return builder.build(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/InvalidComponentException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/InvalidComponentException.java new file mode 100644 index 0000000000..34fed3f93a --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/InvalidComponentException.java @@ -0,0 +1,30 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.util.adventure.text.Component; + +public class InvalidComponentException extends WorldEditException { + + public InvalidComponentException(Component message) { + super(message); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/MessageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/MessageBox.java new file mode 100644 index 0000000000..38f1876064 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/MessageBox.java @@ -0,0 +1,91 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.google.common.base.Strings; +import com.google.common.collect.Sets; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.adventure.text.format.TextColor; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; +import com.sk89q.worldedit.util.adventure.text.serializer.plain.PlainTextComponentSerializer; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Makes for a box with a border above and below. + */ +public class MessageBox { + + private static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; + + private final TextComponent.Builder builder = Component.text(); + private final TextColor borderColor; + + public MessageBox(String title, Component contents) { + this(title, contents, NamedTextColor.YELLOW); + } + + public MessageBox(String title, Component contents, NamedTextColor borderColor) { + checkNotNull(title); + this.borderColor = borderColor; + + this.builder.append(centerAndBorder(Component.text(title))).append(Component.newline()); + this.builder.append(contents); + } + + protected Component centerAndBorder(TextComponent text) { + TextComponent.Builder line = Component.text(); + int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - getLength(text); + int side = (int) Math.floor(leftOver / 2.0); + if (side > 0) { + if (side > 1) { + line.append(createBorder(side - 1)); + } + line.append(Component.space()); + } + line.append(text); + if (side > 0) { + line.append(Component.space()); + if (side > 1) { + line.append(createBorder(side - 1)); + } + } + return line.build(); + } + + private static int getLength(TextComponent text) { + return PlainTextComponentSerializer.plainText().serialize(text).length(); + } + + private TextComponent createBorder(int count) { + return Component.text(Strings.repeat("-", count), + borderColor, Sets.newHashSet(TextDecoration.STRIKETHROUGH)); + } + + public Component build() { + return builder.build(); + } + + public TextComponent.Builder builder() { + return builder; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/PaginationBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/PaginationBox.java new file mode 100644 index 0000000000..aabb82cdd8 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/PaginationBox.java @@ -0,0 +1,155 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; + +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +public abstract class PaginationBox extends MessageBox { + + private static final int IDEAL_ROWS_FOR_PLAYER = 8; + + private String pageCommand; + private int componentsPerPage = IDEAL_ROWS_FOR_PLAYER; + private int currentPage = -1; + + /** + * Creates a Paginated component. + * + * @param title The title + */ + protected PaginationBox(String title) { + this(title, null); + } + + public abstract Component component(int number); + + public abstract int getComponentsSize(); + + public void setComponentsPerPage(int componentsPerPage) { + this.componentsPerPage = componentsPerPage; + } + + public void formatForConsole() { + this.pageCommand = null; + this.componentsPerPage = 20; + } + + protected final int getCurrentPage() { + return currentPage; + } + + /** + * Creates a Paginated component. + * + * @param title The title + * @param pageCommand The command to run to switch page, with %page% representing page number + */ + protected PaginationBox(String title, @Nullable String pageCommand) { + super(title, Component.empty()); + + if (pageCommand != null && !pageCommand.contains("%page%")) { + throw new IllegalArgumentException("pageCommand must contain %page% if provided."); + } + this.pageCommand = pageCommand; + } + + public Component build(int page) throws InvalidComponentException { + if (page == 1 && getComponentsSize() == 0) { + return builder().resetStyle().append(Component.text("No results found.")).build(); + } + int pageCount = (int) Math.ceil(getComponentsSize() / (double) componentsPerPage); + if (page < 1 || page > pageCount) { + throw new InvalidComponentException(Component.translatable("worldedit.error.invalid-page")); + } + currentPage = page; + final int lastComp = Math.min(page * componentsPerPage, getComponentsSize()); + for (int i = (page - 1) * componentsPerPage; i < lastComp; i++) { + builder().append(component(i)); + if (i + 1 != lastComp) { + builder().append(Component.newline()); + } + } + if (pageCount == 1) { + return super.build(); + } + builder().append(Component.newline()); + TextComponent pageNumberComponent = Component.text("Page ", NamedTextColor.YELLOW) + .append(Component.text(String.valueOf(page), NamedTextColor.GOLD)) + .append(Component.text(" of ")) + .append(Component.text(String.valueOf(pageCount), NamedTextColor.GOLD)); + if (pageCommand != null) { + TextComponent.Builder navProducer = Component.text(); + if (page > 1) { + TextComponent prevComponent = Component.text("<<< ", NamedTextColor.GOLD) + .clickEvent(ClickEvent.runCommand(pageCommand.replace("%page%", String.valueOf(page - 1)))) + .hoverEvent(HoverEvent.showText(Component.text("Click to navigate"))); + navProducer.append(prevComponent); + } + navProducer.append(pageNumberComponent); + if (page < pageCount) { + TextComponent nextComponent = Component.text(" >>>", NamedTextColor.GOLD) + .clickEvent(ClickEvent.runCommand(pageCommand.replace("%page%", String.valueOf(page + 1)))) + .hoverEvent(HoverEvent.showText(Component.text("Click to navigate"))); + navProducer.append(nextComponent); + } + builder().append(centerAndBorder(navProducer.build())); + } else { + builder().append(centerAndBorder(pageNumberComponent)); + } + return super.build(); + } + + public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List lines) { + return fromText(header, pageCommand, lines.stream() + .map(Component::text) + .collect(Collectors.toList())); + } + + public static PaginationBox fromText(String header, @Nullable String pageCommand, List lines) { + return new ListPaginationBox(header, pageCommand, lines); + } + + private static class ListPaginationBox extends PaginationBox { + private final List lines; + + ListPaginationBox(String header, String pageCommand, List lines) { + super(header, pageCommand); + this.lines = lines; + } + + @Override + public Component component(int number) { + return lines.get(number); + } + + @Override + public int getComponentsSize() { + return lines.size(); + } + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/SideEffectBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/SideEffectBox.java new file mode 100644 index 0000000000..bbf6183727 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/adventure/SideEffectBox.java @@ -0,0 +1,92 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.adventure; + +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.util.SideEffect; +import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; +import com.sk89q.worldedit.util.concurrency.LazyReference; +import com.sk89q.worldedit.util.formatting.WorldEditText; + +import java.util.Comparator; +import java.util.List; +import java.util.Locale; + +public class SideEffectBox extends PaginationBox { + + private static final LazyReference> SIDE_EFFECTS = LazyReference.from(() -> + WorldEdit.getInstance().getPlatformManager().getSupportedSideEffects() + .stream() + .filter(SideEffect::isExposed) + .sorted(Comparator.comparing(effect -> + WorldEditText.reduceToText( + Component.translatable(effect.getDisplayName()), + Locale.US + ) + )) + .toList() + ); + + private final SideEffectSet sideEffectSet; + + private static List getSideEffects() { + return SIDE_EFFECTS.getValue(); + } + + public SideEffectBox(SideEffectSet sideEffectSet) { + super("Side Effects"); + + this.sideEffectSet = sideEffectSet; + } + + private static final SideEffect.State[] SHOWN_VALUES = {SideEffect.State.OFF, SideEffect.State.ON}; + + @Override + public Component component(int number) { + SideEffect effect = getSideEffects().get(number); + SideEffect.State state = this.sideEffectSet.getState(effect); + + TextComponent.Builder builder = Component.text(); + builder.append(Component.translatable(effect.getDisplayName(), NamedTextColor.YELLOW) + .hoverEvent(HoverEvent.showText(Component.translatable(effect.getDescription())))); + for (SideEffect.State uiState : SHOWN_VALUES) { + builder.append(Component.space()); + builder.append(Component.translatable(uiState.getDisplayName(), uiState == state ? NamedTextColor.WHITE : NamedTextColor.GRAY) + .clickEvent(ClickEvent.runCommand("//perf -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US))) + .hoverEvent(HoverEvent.showText(uiState == state + ? Component.translatable("worldedit.sideeffect.box.current") + : Component.translatable("worldedit.sideeffect.box.change-to", Component.translatable(uiState.getDisplayName())) + )) + ); + } + + return builder.build(); + } + + @Override + public int getComponentsSize() { + return getSideEffects().size(); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java index 6f3640d3ea..1943ee22a0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java @@ -25,10 +25,10 @@ /** * Represents a fragment representing a command that is to be typed. */ +@Deprecated public class CodeFormat extends TextComponentProducer { private CodeFormat() { - getBuilder().content("").color(TextColor.AQUA); } /** @@ -38,11 +38,12 @@ private CodeFormat() { * @return The Component */ public static TextComponent wrap(String... texts) { - CodeFormat code = new CodeFormat(); + TextComponent.Builder b = TextComponent.builder(); + b.color(TextColor.AQUA); for (String text: texts) { - code.append(text); + b.append(text); } - return code.create(); + return b.build(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java index b9717c0d38..b7be47e80c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java @@ -28,6 +28,7 @@ import java.util.List; +@Deprecated public class CommandListBox extends PaginationBox { private final List commands = Lists.newArrayList(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index 96c9ec2e60..d59d97141f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -20,10 +20,12 @@ package com.sk89q.worldedit.util.formatting.component; import com.google.common.collect.Iterables; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TextComponent; +import com.sk89q.worldedit.util.adventure.text.event.ClickEvent; +import com.sk89q.worldedit.util.adventure.text.event.HoverEvent; +import com.sk89q.worldedit.util.adventure.text.format.TextDecoration; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParameters; import org.enginehub.piston.config.ColorConfig; @@ -38,6 +40,7 @@ /** * A box to describe usage of a command. */ +@Deprecated public class CommandUsageBox extends TextComponentProducer { /** @@ -68,21 +71,20 @@ public CommandUsageBox(List commands, String commandString, String help } private void attachCommandUsage(List commands, String commandString, String helpRootCommand) { - TextComponentProducer boxContent = new TextComponentProducer() - .append(HelpGenerator.create(commands).getFullHelp()); + TextComponent.Builder b = Component.text(); + b.append(HelpGenerator.create(commands).getFullHelp()); if (getSubCommands(Iterables.getLast(commands)).size() > 0) { - boxContent.append(TextComponent.newline()) - .append(ColorConfig.helpText().wrap(TextComponent.builder("> ") - .append(ColorConfig.mainText().wrap(TextComponent.builder("List Subcommands") + b.append(Component.newline()) + .append(ColorConfig.helpText().wrap(Component.text("> ") + .append(ColorConfig.mainText().wrap(Component.text("List Subcommands") .decoration(TextDecoration.ITALIC, true) .clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString)) - .hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command"))) - .build())) - .build())); + .hoverEvent(HoverEvent.showText(Component.text("List all subcommands of this command"))) + )) + )); } MessageBox box = new MessageBox("Help for " + commandString, - boxContent); - + new TextComponentProducer().append(LegacyTextHelper.adapt(b.build()))); append(box.create()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java index 5b60afb3fc..558e3c6e27 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java @@ -25,13 +25,13 @@ /** * Represents a fragment representing an error. */ +@Deprecated public class ErrorFormat extends TextComponentProducer { /** * Create a new instance. */ private ErrorFormat() { - getBuilder().content("").color(TextColor.RED); } /** @@ -40,12 +40,14 @@ private ErrorFormat() { * @param texts The text * @return The Component */ + @Deprecated public static TextComponent wrap(String... texts) { - ErrorFormat error = new ErrorFormat(); + TextComponent.Builder b = TextComponent.builder(); + b.color(TextColor.RED); for (String component : texts) { - error.append(component); + b.append(component); } - return error.create(); + return b.build(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/InvalidComponentException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/InvalidComponentException.java index 54965f7638..401d488fbd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/InvalidComponentException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/InvalidComponentException.java @@ -20,8 +20,8 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +@Deprecated public class InvalidComponentException extends WorldEditException { @Deprecated @@ -29,7 +29,8 @@ public InvalidComponentException(String message) { super(message); } - public InvalidComponentException(Component message) { + @Deprecated + public InvalidComponentException(com.sk89q.worldedit.util.formatting.text.Component message) { super(message); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java index 60b05743ea..07801e8c18 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java @@ -25,13 +25,13 @@ /** * Represents a fragment representing a label. */ -public class LabelFormat extends TextComponentProducer { +@Deprecated +public class LabelFormat { /** * Create a new instance. */ private LabelFormat() { - getBuilder().content("").color(TextColor.YELLOW); } /** @@ -41,11 +41,12 @@ private LabelFormat() { * @return The Component */ public static TextComponent wrap(String... texts) { - LabelFormat label = new LabelFormat(); + TextComponent.Builder b = TextComponent.builder(); + b.color(TextColor.YELLOW); for (String component : texts) { - label.append(component); + b.append(component); } - return label.create(); + return b.build(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java index 585aa3a6fa..4fd0d65562 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java @@ -31,6 +31,7 @@ /** * Makes for a box with a border above and below. */ +@Deprecated public class MessageBox extends TextComponentProducer { private static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java index 556b8f0513..a79b58d5c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; +@Deprecated public abstract class PaginationBox extends MessageBox { private static final int IDEAL_ROWS_FOR_PLAYER = 8; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java index 6b784a5c94..1b57cc2872 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.concurrency.LazyReference; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; @@ -36,6 +37,7 @@ import java.util.Locale; import java.util.stream.Collectors; +@Deprecated public class SideEffectBox extends PaginationBox { private static final LazyReference> SIDE_EFFECTS = LazyReference.from(() -> @@ -44,7 +46,7 @@ public class SideEffectBox extends PaginationBox { .filter(SideEffect::isExposed) .sorted(Comparator.comparing(effect -> WorldEditText.reduceToText( - TranslatableComponent.of(effect.getDisplayName()), + LegacyTextHelper.adapt(TranslatableComponent.of(effect.getDisplayName())), Locale.US ) )) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java index 735b6cf40c..4ebd6a6d27 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java @@ -25,13 +25,13 @@ /** * Represents a subtle part of the message. */ +@Deprecated public class SubtleFormat extends TextComponentProducer { /** * Create a new instance. */ private SubtleFormat() { - getBuilder().content("").color(TextColor.GRAY); } /** @@ -40,12 +40,14 @@ private SubtleFormat() { * @param texts The text * @return The Component */ + @Deprecated public static TextComponent wrap(String... texts) { - SubtleFormat subtle = new SubtleFormat(); + TextComponent.Builder b = TextComponent.builder(); + b.color(TextColor.GRAY); for (String component : texts) { - subtle.append(component); + b.append(component); } - return subtle.create(); + return b.build(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java index e6018fb4e3..ab63ba9d20 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java @@ -22,9 +22,14 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; +/** + * Utility class to build components. + * @deprecated do not use anymore, use adventure directly + */ +@Deprecated public class TextComponentProducer { - private TextComponent.Builder builder = TextComponent.builder().content(""); + private TextComponent.Builder builder = TextComponent.builder(); public TextComponent.Builder getBuilder() { return builder; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FileSelectionAbortedException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FileSelectionAbortedException.java index 3cf4bb8d2d..d7138ab84d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FileSelectionAbortedException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FileSelectionAbortedException.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.io.file; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; public class FileSelectionAbortedException extends FilenameException { @@ -32,6 +32,11 @@ public FileSelectionAbortedException(String msg) { super("", msg); } + @Deprecated + public FileSelectionAbortedException(com.sk89q.worldedit.util.formatting.text.Component msg) { + super("", msg); + } + public FileSelectionAbortedException(Component msg) { super("", msg); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameException.java index 453129e7dc..97d12c72f4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameException.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.io.file; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; public class FilenameException extends WorldEditException { @@ -31,6 +31,12 @@ public FilenameException(String filename) { this.filename = filename; } + @Deprecated + public FilenameException(String filename, com.sk89q.worldedit.util.formatting.text.Component msg) { + super(msg); + this.filename = filename; + } + public FilenameException(String filename, Component msg) { super(msg); this.filename = filename; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameResolutionException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameResolutionException.java index f229aa4b5f..a7270341bf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameResolutionException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/FilenameResolutionException.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.io.file; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; public class FilenameResolutionException extends FilenameException { @@ -27,6 +27,11 @@ public FilenameResolutionException(String filename) { super(filename); } + @Deprecated + public FilenameResolutionException(String filename, com.sk89q.worldedit.util.formatting.text.Component msg) { + super(filename, msg); + } + public FilenameResolutionException(String filename, Component msg) { super(filename, msg); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/InvalidFilenameException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/InvalidFilenameException.java index e3d6a83245..2e0fa9d89a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/InvalidFilenameException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/InvalidFilenameException.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.io.file; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; public class InvalidFilenameException extends FilenameException { @@ -27,6 +27,11 @@ public InvalidFilenameException(String filename) { super(filename); } + @Deprecated + public InvalidFilenameException(String filename, com.sk89q.worldedit.util.formatting.text.Component msg) { + super(filename, msg); + } + public InvalidFilenameException(String filename, Component msg) { super(filename, msg); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java index f4f13378d4..3d63214d72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/paste/ActorCallbackPaste.java @@ -21,8 +21,8 @@ import com.sk89q.worldedit.command.util.AsyncCommandBuilder; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.TranslatableComponent; import com.sk89q.worldedit.util.task.Supervisor; import java.net.URL; @@ -57,6 +57,28 @@ public static void pastebin(Supervisor supervisor, final Actor sender, String co .buildAndExec(Pasters.getExecutor()); } + /** + * Submit data to a pastebin service and inform the sender of + * success or failure. + * + * @param supervisor The supervisor instance + * @param sender The sender + * @param content The content + * @param successMessage The message builder, given the URL as an arg + * @deprecated Use adventure method instead + */ + @Deprecated + public static void pastebin(Supervisor supervisor, final Actor sender, String content, final com.sk89q.worldedit.util.formatting.text.TranslatableComponent.Builder successMessage) { + Callable task = paster.paste(content); + + AsyncCommandBuilder.wrap(task, sender) + .registerWithSupervisor(supervisor, "Submitting content to a pastebin service.") + .setDelayMessage(Component.translatable("worldedit.pastebin.uploading")) + .onSuccess((String) null, url -> sender.printInfo(successMessage.args(com.sk89q.worldedit.util.formatting.text.TextComponent.of(url.toString())).build())) + .onFailure("Failed to submit paste", null) + .buildAndExec(Pasters.getExecutor()); + } + /** * Submit data to a pastebin service and inform the sender of * success or failure. @@ -71,8 +93,8 @@ public static void pastebin(Supervisor supervisor, final Actor sender, String co AsyncCommandBuilder.wrap(task, sender) .registerWithSupervisor(supervisor, "Submitting content to a pastebin service.") - .setDelayMessage(TranslatableComponent.of("worldedit.pastebin.uploading")) - .onSuccess((String) null, url -> sender.printInfo(successMessage.args(TextComponent.of(url.toString())).build())) + .setDelayMessage(Component.translatable("worldedit.pastebin.uploading")) + .onSuccess((String) null, url -> sender.printInfo(successMessage.args(Component.text(url.toString())).build())) .onFailure("Failed to submit paste", null) .buildAndExec(Pasters.getExecutor()); } @@ -88,13 +110,13 @@ public static void pastebin(Supervisor supervisor, final Actor sender, String co * @param pasteMetadata The paste metadata * @param successMessage The message builder, given the URL as an arg */ - public static void pastebin(Supervisor supervisor, final Actor sender, String content, PasteMetadata pasteMetadata, final TranslatableComponent.Builder successMessage) { + public static void pastebin(Supervisor supervisor, final Actor sender, String content, PasteMetadata pasteMetadata, final TranslatableComponent successMessage) { Callable task = paster.paste(content, pasteMetadata); AsyncCommandBuilder.wrap(task, sender) .registerWithSupervisor(supervisor, "Submitting content to a pastebin service.") - .setDelayMessage(TranslatableComponent.of("worldedit.pastebin.uploading")) - .onSuccess((String) null, url -> sender.printInfo(successMessage.args(TextComponent.of(url.toString())).build())) + .setDelayMessage(Component.translatable("worldedit.pastebin.uploading")) + .onSuccess((String) null, url -> sender.printInfo(successMessage.args(Component.text(url.toString())))) .onFailure("Failed to submit paste", null) .buildAndExec(Pasters.getExecutor()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java index ddeecbcced..72ff8cfcf7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java @@ -27,8 +27,9 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.internal.util.LogManagerCompat; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.renderer.TranslatableComponentRenderer; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.renderer.TranslatableComponentRenderer; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.util.io.ResourceLoader; import com.sk89q.worldedit.util.io.file.ArchiveUnpacker; import org.apache.logging.log4j.Logger; @@ -85,9 +86,11 @@ public static String makeTranslationKey(String type, String id) { return type + '.' + parts[0] + '.' + parts[1].replace('/', '.'); } - private final TranslatableComponentRenderer friendlyComponentRenderer = TranslatableComponentRenderer.from( - this::getTranslation - ); + private final TranslatableComponentRenderer friendlyComponentRenderer = new TranslatableComponentRenderer<>() { + protected @Nullable MessageFormat translate(final String key, final Locale context) { + return getTranslation(context, key); + } + }; private final Table translationTable = Tables.newCustomTable( new ConcurrentHashMap<>(), ConcurrentHashMap::new ); @@ -140,7 +143,12 @@ public void reload() { } } - public Component convertText(Component component, Locale locale) { + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component convertText(com.sk89q.worldedit.util.formatting.text.Component component, Locale locale) { + return LegacyTextHelper.adapt(convert(LegacyTextHelper.adapt(component), locale)); + } + + public Component convert(Component component, Locale locale) { return friendlyComponentRenderer.render(component, locale); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/WorldUnloadedException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/WorldUnloadedException.java index 01f6023c31..de41a1d98e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/WorldUnloadedException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/WorldUnloadedException.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.world; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; /** * Thrown if the world has been unloaded. @@ -31,6 +31,6 @@ public class WorldUnloadedException extends WorldEditException { * Create a new instance. */ public WorldUnloadedException() { - super(TranslatableComponent.of("worldedit.error.world-unloaded")); + super(Component.translatable("worldedit.error.world-unloaded")); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeData.java index 72307720f6..560da81814 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeData.java @@ -35,7 +35,7 @@ public interface BiomeData { * * @return the biome's name * @deprecated This method does not work on the server. - * Use {@link BiomeRegistry#getRichName(BiomeType)}. + * Use {@link BiomeRegistry#getDisplayName(BiomeType)}. */ @Deprecated String getName(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index c094324902..1665c0312b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -20,12 +20,10 @@ package com.sk89q.worldedit.world.block; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.concurrency.LazyReference; import org.enginehub.linbus.format.snbt.LinStringIO; -import org.enginehub.linbus.stream.exception.NbtWriteException; import org.enginehub.linbus.tree.LinCompoundTag; import org.enginehub.linbus.tree.LinStringTag; import org.enginehub.linbus.tree.LinTagType; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index a24be1a824..e467bdbdeb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -27,8 +27,8 @@ import com.sk89q.worldedit.registry.Keyed; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.registry.state.Property; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -101,16 +101,33 @@ public String getId() { return this.id; } - public Component getRichName() { + /** + * Gets the name of the block. + * + * @return The name + * @deprecated Use {@link #getDisplayName()} instead. + */ + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component getRichName() { return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) .getRegistries().getBlockRegistry().getRichName(this); } + /** + * Gets the name of the block. + * + * @return The name + */ + public Component getDisplayName() { + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) + .getRegistries().getBlockRegistry().getDisplayName(this); + } + /** * Gets the name of this block, or the ID if the name cannot be found. * * @return The name, or ID - * @deprecated The name is now translatable, use {@link #getRichName()}. + * @deprecated The name is now translatable, use {@link #getDisplayName()}. */ @Deprecated public String getName() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index a9662b9f4a..6d803e0ab4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -24,8 +24,9 @@ import com.sk89q.worldedit.registry.Keyed; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.util.GuavaUtil; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.concurrency.LazyReference; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.ItemMaterial; @@ -48,7 +49,7 @@ public class ItemType implements Keyed { }); private final LazyReference richName = LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) - .getRegistries().getItemRegistry().getRichName(this) + .getRegistries().getItemRegistry().getDisplayName(this) ); private final LazyReference itemMaterial = LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) @@ -68,7 +69,24 @@ public String getId() { return this.id; } - public Component getRichName() { + + /** + * Gets the name of this item. + * + * @return The name + * @deprecated Use {@link ItemType#getDisplayName()} instead. + */ + @Deprecated + public com.sk89q.worldedit.util.formatting.text.Component getRichName() { + return LegacyTextHelper.adapt(richName.getValue()); + } + + /** + * Gets the name of this item. + * + * @return The name + */ + public Component getDisplayName() { return richName.getValue(); } @@ -76,7 +94,7 @@ public Component getRichName() { * Gets the name of this item, or the ID if the name cannot be found. * * @return The name, or ID - * @deprecated Names are translatable now, use {@link #getRichName()}. + * @deprecated Names are translatable now, use {@link #getDisplayName()}. */ @Deprecated public String getName() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BiomeRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BiomeRegistry.java index 3e18c47773..720dca50b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BiomeRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BiomeRegistry.java @@ -19,7 +19,8 @@ package com.sk89q.worldedit.world.registry; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; @@ -35,8 +36,20 @@ public interface BiomeRegistry { * * @param biomeType the biome type * @return the name of the biome + * @deprecated Use {@link BiomeRegistry#getDisplayName(BiomeType)} instead */ - Component getRichName(BiomeType biomeType); + @Deprecated + default com.sk89q.worldedit.util.formatting.text.Component getRichName(BiomeType biomeType) { + return LegacyTextHelper.adapt(getDisplayName(biomeType)); + } + + /** + * Get the name of the biome, usually as a translatable component. + * + * @param biomeType the biome type + * @return the name of the biome + */ + Component getDisplayName(BiomeType biomeType); /** * Get data about a biome. @@ -44,7 +57,7 @@ public interface BiomeRegistry { * @param biome the biome * @return a data object or null if information is not known * @deprecated This method no longer returns any useful information. - * Use {@link #getRichName(BiomeType)} for the name of the biome. + * Use {@link #getDisplayName(BiomeType)} for the name of the biome. */ @Deprecated @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java index 12f6b51ca1..a3bd2de249 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -38,20 +39,32 @@ public interface BlockRegistry { * * @param blockType the block * @return The name + * @deprecated Use {@link BlockRegistry#getDisplayName} instead */ - Component getRichName(BlockType blockType); + @Deprecated + default com.sk89q.worldedit.util.formatting.text.Component getRichName(BlockType blockType) { + return LegacyTextHelper.adapt(getDisplayName(blockType)); + } + + /** + * Gets the name for the given block. + * + * @param blockType the block + * @return The name + */ + Component getDisplayName(BlockType blockType); /** * Gets the name for the given block. * * @param blockType the block * @return The name, or null if it's unknown - * @deprecated Names are now translatable, use {@link #getRichName(BlockType)}. + * @deprecated Names are now translatable, use {@link #getDisplayName(BlockType)}. */ @Deprecated @Nullable default String getName(BlockType blockType) { - return getRichName(blockType).toString(); + return getDisplayName(blockType).toString(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java index 70f96565c9..7b90b43785 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java @@ -20,9 +20,7 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.translation.TranslationManager; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -39,16 +37,16 @@ public class BundledBlockRegistry implements BlockRegistry { @Override - public Component getRichName(BlockType blockType) { + public Component getDisplayName(BlockType blockType) { BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId()); if (blockEntry != null) { // This is more likely to be "right", but not translated // Some vanilla MC blocks have overrides so we need this name here // Most platforms should be overriding this anyways, so it likely doesn't matter // too much! - return TextComponent.of(blockEntry.localizedName); + return Component.text(blockEntry.localizedName); } - return TranslatableComponent.of( + return Component.translatable( TranslationManager.makeTranslationKey("block", blockType.getId()) ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java index 13e6bb8b06..3472bf7502 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java @@ -19,9 +19,7 @@ package com.sk89q.worldedit.world.registry; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.translation.TranslationManager; import com.sk89q.worldedit.world.item.ItemType; @@ -38,16 +36,16 @@ private BundledItemData.ItemEntry getEntryById(ItemType itemType) { } @Override - public Component getRichName(ItemType itemType) { + public Component getDisplayName(ItemType itemType) { BundledItemData.ItemEntry itemEntry = getEntryById(itemType); if (itemEntry != null && !itemEntry.localizedName.equals("Air")) { // This is more likely to be "right", but not translated // Some vanilla MC items have overrides so we need this name here // Most platforms should be overriding this anyways, so it likely doesn't matter // too much! - return TextComponent.of(itemEntry.localizedName); + return Component.text(itemEntry.localizedName); } - return TranslatableComponent.of( + return Component.translatable( TranslationManager.makeTranslationKey("item", itemType.getId()) ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java index 5035dae504..f90a356f70 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.world.registry; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.formatting.LegacyTextHelper; import com.sk89q.worldedit.world.item.ItemType; import javax.annotation.Nullable; @@ -32,8 +33,32 @@ public interface ItemRegistry { * * @param itemType the item * @return The name + * @deprecated use {@link ItemRegistry#getDisplayName(ItemType)} instead */ - Component getRichName(ItemType itemType); + @Deprecated + default com.sk89q.worldedit.util.formatting.text.Component getRichName(ItemType itemType) { + return LegacyTextHelper.adapt(getDisplayName(itemType)); + } + + /** + * Gets the name for the given item. + * + * @param itemType the item + * @return The name + */ + Component getDisplayName(ItemType itemType); + + /** + * Gets the name for the given item stack. + * + * @param itemStack the item stack + * @return The name + * @deprecated use {@link ItemRegistry#getDisplayName(BaseItemStack)} instead + */ + @Deprecated + default com.sk89q.worldedit.util.formatting.text.Component getRichName(BaseItemStack itemStack) { + return LegacyTextHelper.adapt(getDisplayName(itemStack.getType())); + } /** * Gets the name for the given item stack. @@ -41,8 +66,8 @@ public interface ItemRegistry { * @param itemStack the item stack * @return The name */ - default Component getRichName(BaseItemStack itemStack) { - return getRichName(itemStack.getType()); + default Component getDisplayName(BaseItemStack itemStack) { + return getDisplayName(itemStack.getType()); } /** @@ -50,12 +75,12 @@ default Component getRichName(BaseItemStack itemStack) { * * @param itemType the item * @return The name, or null if it's unknown - * @deprecated Names are now translatable, use {@link #getRichName(ItemType)}. + * @deprecated Names are now translatable, use {@link #getDisplayName(ItemType)}. */ @Deprecated @Nullable default String getName(ItemType itemType) { - return getRichName(itemType).toString(); + return getDisplayName(itemType).toString(); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBiomeRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBiomeRegistry.java index 7951b25a02..c03076fe3c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBiomeRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBiomeRegistry.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.world.registry; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; @@ -39,8 +38,8 @@ public NullBiomeRegistry() { } @Override - public Component getRichName(BiomeType biomeType) { - return TranslatableComponent.of( + public Component getDisplayName(BiomeType biomeType) { + return Component.translatable( TranslationManager.makeTranslationKey("biome", biomeType.getId()) ); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBiomeRegistry.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBiomeRegistry.java index d2e3b1b165..3200d75ef4 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBiomeRegistry.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBiomeRegistry.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.fabric; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -33,8 +32,8 @@ class FabricBiomeRegistry implements BiomeRegistry { @Override - public Component getRichName(BiomeType biomeType) { - return TranslatableComponent.of(Util.makeDescriptionId("biome", new ResourceLocation(biomeType.getId()))); + public Component getDisplayName(BiomeType biomeType) { + return Component.translatable(Util.makeDescriptionId("biome", new ResourceLocation(biomeType.getId()))); } @Deprecated diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockCommandSender.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockCommandSender.java index 02fc468b9e..5097d4f8db 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockCommandSender.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockCommandSender.java @@ -23,16 +23,17 @@ import com.sk89q.worldedit.extension.platform.AbstractCommandBlockActor; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.BaseCommandBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.NotNull; import java.nio.charset.StandardCharsets; import java.util.Locale; @@ -65,27 +66,9 @@ public void printRaw(String msg) { } @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, ChatFormatting.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, ChatFormatting.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, ChatFormatting.RED); - } - - @Override - public void print(Component component) { - sendMessage(net.minecraft.network.chat.Component.Serializer.fromJson( - GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())) + public void print(@NotNull Component component) { + this.sender.sendSystemMessage(net.minecraft.network.chat.Component.Serializer.fromJson( + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) )); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java index 3652a04aba..c583db4a8d 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricBlockRegistry.java @@ -21,8 +21,7 @@ import com.sk89q.worldedit.fabric.internal.FabricTransmogrifier; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -40,8 +39,8 @@ public class FabricBlockRegistry extends BundledBlockRegistry { private final Map materialMap = new HashMap<>(); @Override - public Component getRichName(BlockType blockType) { - return TranslatableComponent.of(FabricAdapter.adapt(blockType).getDescriptionId()); + public Component getDisplayName(BlockType blockType) { + return Component.translatable(FabricAdapter.adapt(blockType).getDescriptionId()); } @Override diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricCommandSender.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricCommandSender.java index 7240319a6c..0513d7ea05 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricCommandSender.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricCommandSender.java @@ -22,10 +22,9 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; import java.util.Locale; @@ -65,47 +64,17 @@ public String getName() { @Deprecated public void printRaw(String msg) { for (String part : msg.split("\n")) { - sendMessage(net.minecraft.network.chat.Component.literal(part)); + print(Component.text(part)); } } - @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, ChatFormatting.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, ChatFormatting.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, ChatFormatting.RED); - } - @Override public void print(Component component) { - sendMessage(net.minecraft.network.chat.Component.Serializer.fromJson( - GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())) + this.sender.sendSystemMessage(net.minecraft.network.chat.Component.Serializer.fromJson( + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) )); } - private void sendColorized(String msg, ChatFormatting formatting) { - for (String part : msg.split("\n")) { - var component = net.minecraft.network.chat.Component.literal(part); - component.withStyle(formatting); - sendMessage(component); - } - } - - private void sendMessage(net.minecraft.network.chat.Component textComponent) { - this.sender.sendSystemMessage(textComponent); - } - @Override public String[] getGroups() { return new String[0]; diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java index bd3d74c40b..d040abb921 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricItemRegistry.java @@ -20,23 +20,22 @@ package com.sk89q.worldedit.fabric; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; public class FabricItemRegistry extends BundledItemRegistry { @Override - public Component getRichName(ItemType itemType) { - return TranslatableComponent.of( + public Component getDisplayName(ItemType itemType) { + return Component.translatable( FabricAdapter.adapt(itemType).getDescriptionId() ); } @Override - public Component getRichName(BaseItemStack itemStack) { - return TranslatableComponent.of( + public Component getDisplayName(BaseItemStack itemStack) { + return Component.translatable( FabricAdapter.adapt(itemStack).getDescriptionId() ); } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java index d009024a1a..816d9264ed 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java @@ -32,10 +32,10 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.component.TextUtils; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -153,35 +153,11 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, ChatFormatting.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, ChatFormatting.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, ChatFormatting.RED); - } - @Override public void print(Component component) { - this.player.sendSystemMessage(net.minecraft.network.chat.Component.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())))); - } - - private void sendColorized(String msg, ChatFormatting formatting) { - for (String part : msg.split("\n")) { - MutableComponent component = net.minecraft.network.chat.Component.literal(part) - .withStyle(style -> style.withColor(formatting)); - this.player.sendSystemMessage(component); - } + this.player.sendSystemMessage(net.minecraft.network.chat.Component.Serializer.fromJson( + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) + )); } @Override diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java index 1721c52482..af72b0190c 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/internal/FabricEntity.java @@ -26,7 +26,6 @@ import com.sk89q.worldedit.fabric.FabricAdapter; import com.sk89q.worldedit.fabric.FabricEntityProperties; import com.sk89q.worldedit.fabric.FabricWorldEdit; -import com.sk89q.worldedit.fabric.internal.NBTConverter; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.concurrency.LazyReference; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBiomeRegistry.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBiomeRegistry.java index 48b85119a8..6da5aad3ea 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBiomeRegistry.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBiomeRegistry.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.forge; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -33,8 +32,8 @@ class ForgeBiomeRegistry implements BiomeRegistry { @Override - public Component getRichName(BiomeType biomeType) { - return TranslatableComponent.of(Util.makeDescriptionId("biome", new ResourceLocation(biomeType.getId()))); + public Component getDisplayName(BiomeType biomeType) { + return Component.translatable(Util.makeDescriptionId("biome", new ResourceLocation(biomeType.getId()))); } @Deprecated diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockCommandSender.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockCommandSender.java index c454cdc547..4e1eca4a88 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockCommandSender.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockCommandSender.java @@ -23,11 +23,10 @@ import com.sk89q.worldedit.extension.platform.AbstractCommandBlockActor; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.BaseCommandBlock; @@ -66,39 +65,13 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, ChatFormatting.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, ChatFormatting.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, ChatFormatting.RED); - } - @Override public void print(Component component) { sendMessage(net.minecraft.network.chat.Component.Serializer.fromJson( - GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())) + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) )); } - private void sendColorized(String msg, ChatFormatting formatting) { - for (String part : msg.split("\n")) { - var component = net.minecraft.network.chat.Component.literal(part); - component.withStyle(formatting); - sendMessage(component); - } - } - private void sendMessage(net.minecraft.network.chat.Component textComponent) { this.sender.sendSystemMessage(textComponent); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java index b0f6dbb175..5c3afb3130 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java @@ -21,8 +21,7 @@ import com.sk89q.worldedit.forge.internal.ForgeTransmogrifier; import com.sk89q.worldedit.registry.state.Property; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -40,8 +39,8 @@ public class ForgeBlockRegistry extends BundledBlockRegistry { private final Map materialMap = new HashMap<>(); @Override - public Component getRichName(BlockType blockType) { - return TranslatableComponent.of(ForgeAdapter.adapt(blockType).getDescriptionId()); + public Component getDisplayName(BlockType blockType) { + return Component.translatable(ForgeAdapter.adapt(blockType).getDescriptionId()); } @Override diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeCommandSender.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeCommandSender.java index aad1181057..a44dfee6ab 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeCommandSender.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeCommandSender.java @@ -22,9 +22,9 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor; import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; @@ -69,39 +69,13 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, ChatFormatting.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, ChatFormatting.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, ChatFormatting.RED); - } - @Override public void print(Component component) { sendMessage(net.minecraft.network.chat.Component.Serializer.fromJson( - GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())) + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) )); } - private void sendColorized(String msg, ChatFormatting formatting) { - for (String part : msg.split("\n")) { - var component = net.minecraft.network.chat.Component.literal(part); - component.withStyle(formatting); - sendMessage(component); - } - } - private void sendMessage(net.minecraft.network.chat.Component textComponent) { this.sender.sendSystemMessage(textComponent); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java index cd8a1e1409..83d7bc2f4b 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java @@ -20,23 +20,22 @@ package com.sk89q.worldedit.forge; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; public class ForgeItemRegistry extends BundledItemRegistry { @Override - public Component getRichName(ItemType itemType) { - return TranslatableComponent.of( + public Component getDisplayName(ItemType itemType) { + return Component.translatable( ForgeAdapter.adapt(itemType).getDescriptionId() ); } @Override - public Component getRichName(BaseItemStack itemStack) { - return TranslatableComponent.of( + public Component getDisplayName(BaseItemStack itemStack) { + return Component.translatable( ForgeAdapter.adapt(itemStack).getDescriptionId() ); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index d26faeb1b3..5fc71845d0 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -32,10 +32,10 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.component.TextUtils; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -168,7 +168,7 @@ public void printError(String msg) { @Override public void print(Component component) { sendMessage(net.minecraft.network.chat.Component.Serializer.fromJson( - GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())) + GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())) )); } diff --git a/worldedit-libs/bukkit/build.gradle.kts b/worldedit-libs/bukkit/build.gradle.kts index a9d1c255e1..457b7a9b83 100644 --- a/worldedit-libs/bukkit/build.gradle.kts +++ b/worldedit-libs/bukkit/build.gradle.kts @@ -9,5 +9,5 @@ repositories { } dependencies { - "shade"("net.kyori:text-adapter-bukkit:${Versions.TEXT_EXTRAS}") + "shade"("net.kyori:adventure-platform-bukkit:${Versions.KYORI_PLATFORM_BUKKIT}") } diff --git a/worldedit-libs/cli/build.gradle.kts b/worldedit-libs/cli/build.gradle.kts index 388618cea1..14b764ad87 100644 --- a/worldedit-libs/cli/build.gradle.kts +++ b/worldedit-libs/cli/build.gradle.kts @@ -1 +1,6 @@ applyLibrariesConfiguration() +constrainDependenciesToLibsCore() + +dependencies { + "shade"("net.kyori:adventure-text-serializer-ansi:${Versions.KYORI_ADVENTURE}") +} diff --git a/worldedit-libs/core/ap/build.gradle.kts b/worldedit-libs/core/ap/build.gradle.kts index a213eec78d..7104202e58 100644 --- a/worldedit-libs/core/ap/build.gradle.kts +++ b/worldedit-libs/core/ap/build.gradle.kts @@ -1,7 +1,10 @@ applyLibrariesConfiguration() +repositories { // TODO: Remove this once piston is published to enginehub repo + mavenLocal() +} dependencies { - // These are here because they use net.kyori:text-api -- so they need to be relocated too + // These are here because they use net.kyori:adventure -- so they need to be relocated too "shade"("org.enginehub.piston.core-ap:annotations:${Versions.PISTON}") "shade"("org.enginehub.piston.core-ap:processor:${Versions.PISTON}") } diff --git a/worldedit-libs/core/build.gradle.kts b/worldedit-libs/core/build.gradle.kts index a52f840423..2cedd955df 100644 --- a/worldedit-libs/core/build.gradle.kts +++ b/worldedit-libs/core/build.gradle.kts @@ -1,11 +1,15 @@ applyLibrariesConfiguration() +repositories { // TODO: Remove this once piston is published to enginehub repo + mavenLocal() +} + dependencies { - "shade"("net.kyori:text-api:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-gson:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-legacy:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-plain:${Versions.TEXT}") - // These are here because they use net.kyori:text-api -- so they need to be relocated too + "shade"("net.kyori:adventure-api:${Versions.KYORI_ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-gson:${Versions.KYORI_ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-legacy:${Versions.KYORI_ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-plain:${Versions.KYORI_ADVENTURE}") + // These are here because they use net.kyori:adventure -- so they need to be relocated too "shade"("org.enginehub.piston:core:${Versions.PISTON}") "shade"("org.enginehub.piston.core-ap:runtime:${Versions.PISTON}") "shade"("org.enginehub.piston:default-impl:${Versions.PISTON}") @@ -14,4 +18,10 @@ dependencies { "shade"("org.enginehub.lin-bus:lin-bus-stream:${Versions.LIN_BUS}") "shade"("org.enginehub.lin-bus:lin-bus-tree:${Versions.LIN_BUS}") "shade"("org.enginehub.lin-bus.format:lin-bus-format-snbt:${Versions.LIN_BUS}") + + // LEGACY Section: kyori-text is shaded and used in deprecated setups + "shade"("net.kyori:text-api:${Versions.TEXT}") + "shade"("net.kyori:text-serializer-gson:${Versions.TEXT}") + "shade"("net.kyori:text-serializer-legacy:${Versions.TEXT}") + "shade"("net.kyori:text-serializer-plain:${Versions.TEXT}") } diff --git a/worldedit-mod/build.gradle.kts b/worldedit-mod/build.gradle.kts index 51ab062a1c..b35f135e27 100644 --- a/worldedit-mod/build.gradle.kts +++ b/worldedit-mod/build.gradle.kts @@ -16,6 +16,7 @@ tasks.register("jar") { from(zipTree({project(":worldedit-forge").tasks.getByName("shadowJar").outputs.files.singleFile})) { // Duplicated first-party files exclude("META-INF/services/org.enginehub.piston.CommandManagerService") + exclude("META-INF/services/net.kyori.adventure.text.serializer.json.JSONComponentSerializer\$Provider") exclude("lang/") // No-brainer library excludes exclude("com/sk89q/jchronic/") diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBiomeRegistry.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBiomeRegistry.java index 48dafb6a2e..a676cef332 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBiomeRegistry.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBiomeRegistry.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.sponge; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.util.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -35,8 +34,8 @@ class SpongeBiomeRegistry implements BiomeRegistry { @Override - public Component getRichName(com.sk89q.worldedit.world.biome.BiomeType biomeType) { - return TranslatableComponent.of( + public Component getDisplayName(com.sk89q.worldedit.world.biome.BiomeType biomeType) { + return Component.translatable( TranslationManager.makeTranslationKey("biome", biomeType.getId()) ); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockCommandSender.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockCommandSender.java index 45d00da699..3d7d7f5e29 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockCommandSender.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockCommandSender.java @@ -22,10 +22,9 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.AbstractCommandBlockActor; import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.format.NamedTextColor; import com.sk89q.worldedit.util.auth.AuthorizationException; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; @@ -69,30 +68,6 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.LIGHT_PURPLE)); - } - } - - @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.GRAY)); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.RED)); - } - } - @Override public void print(Component component) { sendMessage(SpongeTextAdapter.convert(component, getLocale())); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java index 90f316e455..e73a92f835 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeBlockRegistry.java @@ -21,7 +21,7 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.sponge.internal.SpongeTransmogrifier; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -44,7 +44,7 @@ public class SpongeBlockRegistry extends BundledBlockRegistry { new HashMap<>(); @Override - public Component getRichName(BlockType blockType) { + public Component getDisplayName(BlockType blockType) { return SpongeTextAdapter.convert(Sponge.game().registry(RegistryTypes.BLOCK_TYPE) .value(ResourceKey.resolve(blockType.getId())).asComponent()); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java index a75ee8fc6c..afe7f1e1ec 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java @@ -23,10 +23,9 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.spongepowered.api.entity.living.player.Player; import java.io.File; @@ -69,36 +68,12 @@ public String getName() { @Deprecated public void printRaw(String msg) { for (String part : msg.split("\n")) { - sender.sendMessage(net.kyori.adventure.text.Component.text(part)); + sender.sendMessage(Component.text(part)); } } @Override - @Deprecated - public void print(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.LIGHT_PURPLE)); - } - } - - @Override - @Deprecated - public void printDebug(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.GRAY)); - } - } - - @Override - @Deprecated - public void printError(String msg) { - for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.RED)); - } - } - - @Override - public void print(Component component) { + public void print(com.sk89q.worldedit.util.adventure.text.Component component) { sender.sendMessage(SpongeTextAdapter.convert(component, getLocale())); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeItemRegistry.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeItemRegistry.java index 61dd1222d9..9e7576df37 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeItemRegistry.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeItemRegistry.java @@ -20,8 +20,7 @@ package com.sk89q.worldedit.sponge; import com.sk89q.worldedit.blocks.BaseItemStack; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; import net.minecraft.world.item.ItemStack; @@ -32,14 +31,14 @@ public class SpongeItemRegistry extends BundledItemRegistry { @Override - public Component getRichName(ItemType itemType) { + public Component getDisplayName(ItemType itemType) { return SpongeTextAdapter.convert(Sponge.game().registry(RegistryTypes.ITEM_TYPE) .value(ResourceKey.resolve(itemType.getId())).asComponent()); } @Override - public Component getRichName(BaseItemStack itemStack) { - return TranslatableComponent.of( + public Component getDisplayName(BaseItemStack itemStack) { + return Component.translatable( ((ItemStack) (Object) SpongeAdapter.adapt(itemStack)).getDescriptionId() ); } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 69494744cc..12bd502a86 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -31,7 +31,7 @@ import com.sk89q.worldedit.sponge.internal.NbtAdapter; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.adventure.text.Component; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; @@ -144,37 +144,11 @@ public void printRaw(String msg) { } } - @Override - @Deprecated - public void printDebug(String msg) { - sendColorized(msg, NamedTextColor.GRAY); - } - - @Override - @Deprecated - public void print(String msg) { - sendColorized(msg, NamedTextColor.LIGHT_PURPLE); - } - - @Override - @Deprecated - public void printError(String msg) { - sendColorized(msg, NamedTextColor.RED); - } - @Override public void print(Component component) { player.sendMessage(SpongeTextAdapter.convert(component, getLocale())); } - private void sendColorized(String msg, TextColor formatting) { - for (String part : msg.split("\n")) { - this.player.sendMessage( - LegacyComponentSerializer.legacySection().deserialize(part).color(formatting) - ); - } - } - @Override public boolean trySetPosition(Vector3 pos, float pitch, float yaw) { ServerLocation loc = ServerLocation.of( diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java index 7709737e43..50ff8c0ccb 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.sponge; +import com.sk89q.worldedit.util.adventure.text.Component; +import com.sk89q.worldedit.util.adventure.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.util.formatting.WorldEditText; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import java.util.Locale; @@ -30,11 +30,11 @@ public class SpongeTextAdapter { public static net.kyori.adventure.text.Component convert(Component component, Locale locale) { component = WorldEditText.format(component, locale); return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson() - .deserialize(GsonComponentSerializer.INSTANCE.serialize(component)); + .deserialize(GsonComponentSerializer.gson().serialize(component)); } public static Component convert(net.kyori.adventure.text.Component component) { - return GsonComponentSerializer.INSTANCE.deserialize( + return GsonComponentSerializer.gson().deserialize( net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson() .serialize(component) );