From 428f8e201dadae13446d6e6830f5af5fa92d7551 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 9 Nov 2020 10:38:10 +0100 Subject: [PATCH] Upstream changes (#717) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Perform part of the move of //fast to //perf (#1377) This re-adds a deprecated `//fast` and moves the current logic to `//perf`. Later `//perf` will have its syntax reworked, when Piston finally supports sub-commands properly! * Names via Translation (#1268) * Deprecate BiomeRegistry, etc. * Update some libraries, e.g. text * Move to new translation renderer * Revert "Deprecate BiomeRegistry, etc." This reverts commit 59a5d6c92aec52739a8dc68ac3d23898af7593dd. This was not a good idea for potential mod shenanigans. * Move BiomeData#getName to BiomeRegistry, use i18n * Use getRichName instead of getName * Implement getRichName for NullBiomeRegistry * Add getRichName for blocks * Relocate net.kyori.minecraft * Update adapters for getRichBlockName * Add getRichName for items * Update adapters for getRichItemName * Update adapters JAR for merge (cherry picked from commit cfd26253b6fb59ff6c65a0157a6780be7db4ea5a) * Follow-up fixes for 92f877679622a27b16b9e5cd61cfec1a6545be33 * Don't send deprecation warning and improve info message * Fix click command for perf box (cherry picked from commit 7ee60060c31df2f8b41212b430a0875312189339) * update R3 adapterĀ§ Co-authored-by: Octavia Togami Co-authored-by: NotMyFault Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: Aurora --- buildSrc/src/main/kotlin/LibsConfig.kt | 25 +++- .../worldedit/bukkit/BukkitBiomeRegistry.java | 11 ++ .../worldedit/bukkit/BukkitBlockRegistry.java | 9 ++ .../worldedit/bukkit/BukkitItemRegistry.java | 21 ++- .../worldedit/bukkit/BukkitRegistries.java | 12 +- .../bukkit/adapter/BukkitImplAdapter.java | 28 +++- .../adapter/impl/FAWE_Spigot_v1_15_R2.java | 17 +++ .../adapter/impl/FAWE_Spigot_v1_16_R1.java | 17 +++ .../adapter/impl/FAWE_Spigot_v1_16_R2.java | 17 +++ .../adapter/impl/FAWE_Spigot_v1_16_R3.java | 17 +++ .../java/com/sk89q/worldedit/WorldEdit.java | 10 +- .../sk89q/worldedit/blocks/BaseItemStack.java | 12 +- .../worldedit/command/BiomeCommands.java | 42 +++--- .../worldedit/command/BrushCommands.java | 2 + .../worldedit/command/ChunkCommands.java | 11 +- .../worldedit/command/GeneralCommands.java | 141 +++++++++++++++--- .../worldedit/command/SchematicCommands.java | 2 +- .../worldedit/command/SelectionCommands.java | 2 +- .../sk89q/worldedit/command/ToolCommands.java | 118 ++++++++------- .../worldedit/command/tool/BlockReplacer.java | 2 +- .../worldedit/command/tool/QueryTool.java | 2 +- .../util/SubCommandPermissionCondition.java | 6 +- .../platform/PlatformCommandManager.java | 24 +-- .../internal/command/CommandUtil.java | 78 ++++++---- .../WorldEditExceptionConverter.java | 15 +- .../formatting/component/PaginationBox.java | 55 +++---- .../formatting/component/SideEffectBox.java | 2 +- .../worldedit/world/biome/BiomeData.java | 4 + .../worldedit/world/block/BlockType.java | 65 ++++---- .../world/registry/BiomeRegistry.java | 11 ++ .../world/registry/BlockRegistry.java | 16 +- .../world/registry/BundledBlockRegistry.java | 18 ++- .../world/registry/ItemRegistry.java | 2 +- .../world/registry/NullBiomeRegistry.java | 11 ++ .../src/main/resources/lang/strings.json | 10 +- .../worldedit/fabric/FabricBiomeRegistry.java | 10 ++ .../worldedit/fabric/FabricBlockRegistry.java | 16 +- .../worldedit/fabric/FabricItemRegistry.java | 28 ++-- .../worldedit/forge/ForgeBiomeRegistry.java | 10 ++ .../worldedit/forge/ForgeBlockRegistry.java | 14 +- .../worldedit/forge/ForgeItemRegistry.java | 37 ++--- .../worldedit/sponge/SpongeBiomeRegistry.java | 13 ++ 42 files changed, 660 insertions(+), 303 deletions(-) diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt index 172be5d39..a84f4f5d9 100644 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ b/buildSrc/src/main/kotlin/LibsConfig.kt @@ -25,6 +25,11 @@ fun Project.applyLibrariesConfiguration() { group = "${rootProject.group}.worldedit-libs" + val relocations = mapOf( + "net.kyori.text" to "com.sk89q.worldedit.util.formatting.text", + "net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori" + ) + tasks.register("jar") { configurations = listOf(project.configurations["shade"]) archiveClassifier.set("") @@ -36,13 +41,15 @@ fun Project.applyLibrariesConfiguration() { exclude(dependency("org.slf4j:slf4j-api")) } - relocate("net.kyori.text", "com.sk89q.worldedit.util.formatting.text") + relocations.forEach { (from, to) -> + relocate(from, to) + } } val altConfigFiles = { artifactType: String -> val deps = configurations["shade"].incoming.dependencies .filterIsInstance() .map { it.copy() } - .map { dependency: ModuleDependency -> + .map { dependency -> dependency.artifact { name = dependency.name type = artifactType @@ -61,13 +68,15 @@ fun Project.applyLibrariesConfiguration() { from({ altConfigFiles("sources") }) - val filePattern = Regex("(.*)net/kyori/text((?:/|$).*)") - val textPattern = Regex("net\\.kyori\\.text") - eachFile { - filter { - it.replaceFirst(textPattern, "com.sk89q.worldedit.util.formatting.text") + relocations.forEach { (from, to) -> + val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)") + val textPattern = Regex.fromLiteral(from) + eachFile { + filter { + it.replaceFirst(textPattern, to) + } + path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2") } - path = path.replaceFirst(filePattern, "$1com/sk89q/worldedit/util/formatting/text$2") } archiveClassifier.set("sources") } 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 d61d833fe..5bccb3283 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,6 +19,9 @@ 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.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -34,6 +37,14 @@ class BukkitBiomeRegistry implements BiomeRegistry { BukkitBiomeRegistry() { } + @Override + public Component getRichName(BiomeType biomeType) { + return TranslatableComponent.of( + TranslationManager.makeTranslationKey("biome", biomeType.getId()) + ); + } + + @Deprecated @Nullable @Override public BiomeData getData(BiomeType biome) { 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 6decfd7f2..221980f2d 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,6 +20,7 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -39,6 +40,14 @@ public class BukkitBlockRegistry extends BundledBlockRegistry { private BukkitBlockMaterial[] materialMap; + @Override + public Component getRichName(BlockType blockType) { + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichBlockName(blockType); + } + return super.getRichName(blockType); + } + @Nullable @Override public BlockMaterial getMaterial(BlockType blockType) { 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 2c49a6a5f..b76c06fbd 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 @@ -19,13 +19,32 @@ package com.sk89q.worldedit.bukkit; +import com.sk89q.worldedit.blocks.BaseItemStack; +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; import org.bukkit.Material; import java.util.ArrayList; import java.util.Collection; -public class BukkitItemRegistry extends BundledItemRegistry { +class BukkitItemRegistry extends BundledItemRegistry { + @Override + public Component getRichName(ItemType itemType) { + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemType); + } + return super.getRichName(itemType); + } + + @Override + public Component getRichName(BaseItemStack itemStack) { + if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { + return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichItemName(itemStack); + } + return super.getRichName(itemStack); + } + @Override public Collection values() { ArrayList values = new ArrayList<>(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java index 005526a00..db865281b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BlockCategoryRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry; -import com.sk89q.worldedit.world.registry.BundledItemRegistry; import com.sk89q.worldedit.world.registry.BundledRegistries; import com.sk89q.worldedit.world.registry.EntityRegistry; import com.sk89q.worldedit.world.registry.ItemCategoryRegistry; @@ -35,8 +34,8 @@ class BukkitRegistries extends BundledRegistries { private static final BukkitRegistries INSTANCE = new BukkitRegistries(); private final BlockRegistry blockRegistry = new BukkitBlockRegistry(); - private final ItemRegistry itemRegistry = new BukkitItemRegistry(); private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry(); + private final ItemRegistry itemRegistry = new BukkitItemRegistry(); private final EntityRegistry entityRegistry = new BukkitEntityRegistry(); private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry(); private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry(); @@ -57,6 +56,11 @@ class BukkitRegistries extends BundledRegistries { return biomeRegistry; } + @Override + public ItemRegistry getItemRegistry() { + return itemRegistry; + } + @Override public BlockCategoryRegistry getBlockCategoryRegistry() { return blockCategoryRegistry; @@ -81,8 +85,4 @@ class BukkitRegistries extends BundledRegistries { return INSTANCE; } - @Override - public ItemRegistry getItemRegistry() { - return itemRegistry; - } } 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 cd3e86499..52286440a 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 @@ -36,12 +36,14 @@ import com.sk89q.worldedit.regions.Region; 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.world.DataFixer; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import org.bukkit.Location; import org.bukkit.World; @@ -52,10 +54,10 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nullable; import java.util.Map; import java.util.OptionalInt; import java.util.Set; -import javax.annotation.Nullable; /** * An interface for adapters of various Bukkit implementations. @@ -127,6 +129,30 @@ public interface BukkitImplAdapter extends IBukkitAdapter { @Nullable Entity createEntity(Location location, BaseEntity state); + /** + * Gets the name for the given block. + * + * @param blockType the block + * @return The name + */ + Component getRichBlockName(BlockType blockType); + + /** + * Gets the name for the given item. + * + * @param itemType the item + * @return The name + */ + Component getRichItemName(ItemType itemType); + + /** + * Gets the name for the given item stack. + * + * @param itemStack the item stack + * @return The name + */ + Component getRichItemName(BaseItemStack itemStack); + /** * Get a map of {@code string -> property}. * diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java index e97f894cd..58e86eb92 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_15_R2.java @@ -48,6 +48,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -57,6 +58,7 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_15_R1.BiomeBase; import net.minecraft.server.v1_15_R1.Block; @@ -279,6 +281,21 @@ public final class FAWE_Spigot_v1_15_R2 extends CachedBukkitAdapter implements I } } + @Override + public Component getRichBlockName(BlockType blockType) { + return parent.getRichBlockName(blockType); + } + + @Override + public Component getRichItemName(ItemType itemType) { + return parent.getRichItemName(itemType); + } + + @Override + public Component getRichItemName(BaseItemStack itemStack) { + return parent.getRichItemName(itemStack); + } + @Override public OptionalInt getInternalBlockStateId(BlockState state) { BlockMaterial_1_15_2 material = (BlockMaterial_1_15_2) state.getMaterial(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java index cda1690cd..cd3625917 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R1.java @@ -47,6 +47,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -56,6 +57,7 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_16_R1.BiomeBase; import net.minecraft.server.v1_16_R1.Block; @@ -278,6 +280,21 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I } } + @Override + public Component getRichBlockName(BlockType blockType) { + return parent.getRichBlockName(blockType); + } + + @Override + public Component getRichItemName(ItemType itemType) { + return parent.getRichItemName(itemType); + } + + @Override + public Component getRichItemName(BaseItemStack itemStack) { + return parent.getRichItemName(itemStack); + } + @Override public OptionalInt getInternalBlockStateId(BlockState state) { BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R2.java index 056988439..17564978a 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R2.java @@ -47,6 +47,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -56,6 +57,7 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_16_R2.BiomeBase; import net.minecraft.server.v1_16_R2.Block; @@ -279,6 +281,21 @@ public final class FAWE_Spigot_v1_16_R2 extends CachedBukkitAdapter implements I } } + @Override + public Component getRichBlockName(BlockType blockType) { + return parent.getRichBlockName(blockType); + } + + @Override + public Component getRichItemName(ItemType itemType) { + return parent.getRichItemName(itemType); + } + + @Override + public Component getRichItemName(BaseItemStack itemStack) { + return parent.getRichItemName(itemStack); + } + @Override public OptionalInt getInternalBlockStateId(BlockState state) { BlockMaterial_1_16_2 material = (BlockMaterial_1_16_2) state.getMaterial(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R3.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R3.java index dd03395a8..79fc3499b 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R3.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_16_R3.java @@ -48,6 +48,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; @@ -57,6 +58,7 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.registry.BlockMaterial; import net.minecraft.server.v1_16_R3.BiomeBase; import net.minecraft.server.v1_16_R3.Block; @@ -280,6 +282,21 @@ public final class FAWE_Spigot_v1_16_R3 extends CachedBukkitAdapter implements I } } + @Override + public Component getRichBlockName(BlockType blockType) { + return parent.getRichBlockName(blockType); + } + + @Override + public Component getRichItemName(ItemType itemType) { + return parent.getRichItemName(itemType); + } + + @Override + public Component getRichItemName(BaseItemStack itemStack) { + return parent.getRichItemName(itemStack); + } + @Override public OptionalInt getInternalBlockStateId(BlockState state) { BlockMaterial_1_16_4 material = (BlockMaterial_1_16_4) state.getMaterial(); 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 25c14e5e4..289c82bb7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -591,15 +591,17 @@ public final class WorldEdit { Map missingBlocks = editSession.popMissingBlocks(); if (!missingBlocks.isEmpty()) { - StringBuilder str = new StringBuilder(); + TextComponent.Builder str = TextComponent.builder(); str.append("Missing these blocks: "); int size = missingBlocks.size(); int i = 0; for (Map.Entry blockTypeIntegerEntry : missingBlocks.entrySet()) { - str.append((blockTypeIntegerEntry.getKey()).getName()); + str.append((blockTypeIntegerEntry.getKey()).getRichName()); - str.append(" [Amt: ").append(blockTypeIntegerEntry.getValue()).append("]"); + str.append(" [Amt: ") + .append(String.valueOf(blockTypeIntegerEntry.getValue())) + .append("]"); ++i; @@ -608,7 +610,7 @@ public final class WorldEdit { } } - actor.printError(str.toString()); + actor.printError(str.build()); } } 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 291875342..2f22ebb93 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 @@ -20,6 +20,9 @@ package com.sk89q.worldedit.blocks; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.item.ItemType; /** @@ -65,7 +68,7 @@ public class BaseItemStack extends BaseItem { /** * Get the number of items in the stack. - * + * * @return the amount */ public int getAmount() { @@ -74,10 +77,15 @@ public class BaseItemStack extends BaseItem { /** * Set the amount of items in the stack. - * + * * @param amount the amount to set */ public void setAmount(int amount) { this.amount = amount; } + + public Component getRichName() { + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) + .getRegistries().getItemRegistry().getRichName(this); + } } 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 c4fc98694..15a9e32e7 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 @@ -49,7 +49,6 @@ 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.world.World; -import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; import org.enginehub.piston.annotation.Command; @@ -87,23 +86,19 @@ public class BiomeCommands { @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) { WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { - BiomeRegistry biomeRegistry = - WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) - .getRegistries().getBiomeRegistry(); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); - PaginationBox paginationBox = PaginationBox - .fromStrings("Available Biomes", "/biomelist -p %page%", - BiomeType.REGISTRY.values().stream().map(biomeType -> { - String id = biomeType.getId(); - final BiomeData data = biomeRegistry.getData(biomeType); - if (data != null) { - String name = data.getName(); - return id + " (" + name + ")"; - } else { - return id; - } - }).collect(Collectors.toList())); - return paginationBox.create(page); + PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%", + BiomeType.REGISTRY.values().stream() + .map(biomeType -> TextComponent.builder() + .append(biomeType.getId()) + .append(" (") + .append(biomeRegistry.getRichName(biomeType)) + .append(")") + .build()) + .collect(Collectors.toList())); + return paginationBox.create(page); }, (Component) null); } @@ -150,14 +145,11 @@ public class BiomeCommands { messageKey = "worldedit.biomeinfo.selection"; } - List components = biomes.stream().map(biome -> { - BiomeData data = biomeRegistry.getData(biome); - if (data != null) { - return TextComponent.of(data.getName()).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId()))); - } else { - return TextComponent.of(biome.getId()); - } - }).collect(Collectors.toList()); + List components = biomes.stream().map(biome -> + biomeRegistry.getRichName(biome).hoverEvent( + HoverEvent.showText(TextComponent.of(biome.getId())) + ) + ).collect(Collectors.toList()); player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", ")))); } 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 9d97eb8a8..4b46dd480 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 @@ -153,6 +153,7 @@ public class BrushCommands { this.worldEdit = worldEdit; } + /* Covered by ToolCommands @Command( name = "none", aliases = "unbind", @@ -161,6 +162,7 @@ public class BrushCommands { void none(Player player, LocalSession session) throws WorldEditException { ToolCommands.setToolNone(player, session, true); } + */ @Command(name = "blendball", aliases = { 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 38ef18f21..2b075e56c 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 @@ -174,17 +174,22 @@ public class ChunkCommands { .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop")))); } - private static class ChunkListPaginationBox extends PaginationBox.ListPaginationBox { + private static class ChunkListPaginationBox extends PaginationBox { //private final Region region; private final List chunks = null; ChunkListPaginationBox(Region region) { - super("Selected Chunks", "/listchunks -p %page%", region.getChunks()); + super("Selected Chunks", "/listchunks -p %page%"); } @Override public Component getComponent(int number) { - return create(number); + return TextComponent.of(chunks.get(number).toString()); + } + + @Override + public int getComponentsSize() { + return chunks.size(); } } } 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 cbc0fcff1..670c3b589 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 @@ -28,6 +28,7 @@ import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.RandomTextureUtil; import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.TextureUtil; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; @@ -36,6 +37,7 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.HookMode; +import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.extension.input.InputParseException; @@ -44,6 +46,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; +import com.sk89q.worldedit.internal.command.CommandUtil; import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.formatting.component.PaginationBox; @@ -54,6 +58,9 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.item.ItemType; +import org.enginehub.piston.CommandManager; +import org.enginehub.piston.CommandManagerService; +import org.enginehub.piston.CommandParameters; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -65,8 +72,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.concurrent.Callable; +import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; @@ -76,6 +85,65 @@ import static com.google.common.base.Preconditions.checkNotNull; @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class GeneralCommands { + public static void register(CommandRegistrationHandler registration, + CommandManager commandManager, + CommandManagerService commandManagerService, + WorldEdit worldEdit) { + // Collect the tool commands + CommandManager collect = commandManagerService.newCommandManager(); + + registration.register( + collect, + GeneralCommandsRegistration.builder(), + new GeneralCommands(worldEdit) + ); + + + Set commands = collect.getAllCommands() + .collect(Collectors.toSet()); + for (org.enginehub.piston.Command command : commands) { + /*if in FAWE, //fast will remain for now + (command.getName().equals("/fast")) { + + // deprecate to `//perf` + commandManager.register(CommandUtil.deprecate( + command, "//fast duplicates //perf " + + "and will be removed in WorldEdit 8", + GeneralCommands::replaceFastForPerf + )); + continue; + } + */ + + commandManager.register(command); + } + } + + private static Component replaceFastForPerf(org.enginehub.piston.Command oldCmd, + CommandParameters oldParams) { + if (oldParams.getMetadata() == null) { + return CommandUtil.createNewCommandReplacementText("//perf"); + } + ImmutableList args = oldParams.getMetadata().getArguments(); + if (args.isEmpty()) { + return TextComponent.of("There is not yet a replacement for //fast" + + " with no arguments"); + } + String arg0 = args.get(0).toLowerCase(Locale.ENGLISH); + String flipped; + switch (arg0) { + case "on": + flipped = "off"; + break; + case "off": + flipped = "on"; + break; + default: + return TextComponent.of("There is no replacement for //fast " + arg0); + } + return CommandUtil.createNewCommandReplacementText("//perf " + flipped); + } + private final WorldEdit worldEdit; /** @@ -145,22 +213,48 @@ public class GeneralCommands { @Command( name = "/fast", - desc = "Toggle fast mode side effects" + desc = "Toggle fast mode" ) @CommandPermissions("worldedit.fast") - public void fast(Actor actor, LocalSession session, - @Arg(desc = "The side effect", def = "") - SideEffect sideEffect, - @Arg(desc = "The new side effect state", def = "") - SideEffect.State newState, - @Switch(name = 'h', desc = "Show the info box") - boolean showInfoBox) throws WorldEditException { + @Deprecated + void fast(Actor actor, LocalSession session, + @Arg(desc = "The new fast mode state", def = "") + Boolean fastMode) { + boolean hasFastMode = session.hasFastMode(); + if (fastMode != null && fastMode == hasFastMode) { + actor.printError(TranslatableComponent.of(fastMode ? "worldedit.fast.enabled.already" : "worldedit.fast.disabled.already")); + return; + } + + if (hasFastMode) { + session.setFastMode(false); + actor.printInfo(TranslatableComponent.of("worldedit.fast.disabled")); + } else { + session.setFastMode(true); + actor.printInfo(TranslatableComponent.of("worldedit.fast.enabled")); + } + } + + @Command( + name = "/perf", + desc = "Toggle side effects for performance", + descFooter = "Note that this command is GOING to change in the future." + + " Do not depend on the exact format of this command yet." + ) + @CommandPermissions("worldedit.perf") + void perf(Actor actor, LocalSession session, + @Arg(desc = "The side effect", def = "") + SideEffect sideEffect, + @Arg(desc = "The new side effect state", def = "") + SideEffect.State newState, + @Switch(name = 'h', desc = "Show the info box") + boolean showInfoBox) throws WorldEditException { if (sideEffect != null) { SideEffect.State currentState = session.getSideEffectSet().getState(sideEffect); if (newState != null && newState == currentState) { if (!showInfoBox) { actor.printError(TranslatableComponent.of( - "worldedit.fast.sideeffect.already-set", + "worldedit.perf.sideeffect.already-set", TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(newState.getDisplayName()) )); @@ -172,14 +266,14 @@ public class GeneralCommands { session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState)); if (!showInfoBox) { actor.printInfo(TranslatableComponent.of( - "worldedit.fast.sideeffect.set", + "worldedit.perf.sideeffect.set", TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(newState.getDisplayName()) )); } } else { actor.printInfo(TranslatableComponent.of( - "worldedit.fast.sideeffect.get", + "worldedit.perf.sideeffect.get", TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(currentState.getDisplayName()) )); @@ -192,7 +286,7 @@ public class GeneralCommands { session.setSideEffectSet(applier); if (!showInfoBox) { actor.printInfo(TranslatableComponent.of( - "worldedit.fast.sideeffect.set-all", + "worldedit.perf.sideeffect.set-all", TranslatableComponent.of(newState.getDisplayName()) )); } @@ -331,7 +425,7 @@ public class GeneralCommands { @ArgFlag(name = 'p', desc = "Page of results to return", def = "1") int page, @Arg(desc = "Search query", variable = true) - List query) throws Exception { + List query) { String search = String.join(" ", query); if (search.length() <= 2) { actor.printError(TranslatableComponent.of("worldedit.searchitem.too-short")); @@ -342,7 +436,8 @@ public class GeneralCommands { return; } - actor.print(new ItemSearcher(search, blocksOnly, itemsOnly, page).call()); + WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page), + TranslatableComponent.of("worldedit.searchitem.searching")); } private static class ItemSearcher implements Callable { @@ -361,7 +456,7 @@ public class GeneralCommands { @Override public Component call() throws Exception { String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search; - Map results = new TreeMap<>(); + Map results = new TreeMap<>(); String idMatch = search.replace(' ', '_'); String nameMatch = search.toLowerCase(Locale.ROOT); for (ItemType searchType : ItemType.REGISTRY) { @@ -373,15 +468,17 @@ public class GeneralCommands { continue; } final String id = searchType.getId(); - String name = searchType.getName(); - final boolean hasName = !name.equals(id); - name = name.toLowerCase(Locale.ROOT); - if (id.contains(idMatch) || (hasName && name.contains(nameMatch))) { - results.put(id, name + (hasName ? " (" + id + ")" : "")); + if (id.contains(idMatch)) { + Component name = searchType.getRichName(); + results.put(id, TextComponent.builder() + .append(name) + .append(" (" + id + ")") + .build()); } } - List list = new ArrayList<>(results.values()); - return PaginationBox.fromStrings("Search results for '" + search + "'", command, list).create(page); + List list = new ArrayList<>(results.values()); + return PaginationBox.fromComponents("Search results for '" + search + "'", command, list) + .create(page); } } 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 a77369af1..9f1b4638f 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 @@ -561,7 +561,7 @@ public class SchematicCommands { return msg.create(); }); - PaginationBox paginationBox = PaginationBox.fromStrings("Available schematics", pageCommand, components); + PaginationBox paginationBox = PaginationBox.fromComponents("Available schematics", pageCommand, components); actor.print(paginationBox.create(page)); } 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 47ce2b41b..2a4a0c0e0 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 @@ -715,7 +715,7 @@ public class SelectionCommands { final BlockState state = c.getID(); final BlockType blockType = state.getBlockType(); - TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE); + Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE); TextComponent toolTip; if (separateStates && state != blockType.getDefaultState()) { toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); 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 b2f2872a0..cf148a7f7 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 @@ -25,8 +25,10 @@ import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.command.tool.BlockDataCyler; import com.sk89q.worldedit.command.tool.BlockReplacer; +import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.DistanceWand; import com.sk89q.worldedit.command.tool.FloatingTreeRemover; import com.sk89q.worldedit.command.tool.FloodFillTool; @@ -35,19 +37,23 @@ import com.sk89q.worldedit.command.tool.LongRangeBuildTool; import com.sk89q.worldedit.command.tool.NavigationWand; import com.sk89q.worldedit.command.tool.QueryTool; import com.sk89q.worldedit.command.tool.SelectionWand; +import com.sk89q.worldedit.command.tool.StackTool; +import com.sk89q.worldedit.command.tool.Tool; import com.sk89q.worldedit.command.tool.TreePlanter; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; +import com.sk89q.worldedit.command.util.SubCommandPermissionCondition; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; 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.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; import org.enginehub.piston.CommandMetadata; @@ -82,14 +88,19 @@ public class ToolCommands { .collect(Collectors.toSet()); for (org.enginehub.piston.Command command : commands) { if (command.getAliases().contains("unbind")) { - // Don't register new /tool unbind alias + // Don't register new /tool alias command = command.toBuilder().aliases( Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias)) ).build(); } + if (command.getName().equals("stacker")) { + // Don't register /stacker + continue; + } commandManager.register(CommandUtil.deprecate( command, "Global tool names cause conflicts " - + "and will be removed in WorldEdit 8", ToolCommands::asNonGlobal + + "and will be removed in WorldEdit 8", + CommandUtil.ReplacementMessageGenerator.forNewCommand(ToolCommands::asNonGlobal) )); } @@ -110,6 +121,8 @@ public class ToolCommands { .required() .build()); command.description(TextComponent.of("Binds a tool to the item in your hand")); + + command.condition(new SubCommandPermissionCondition.Generator(nonGlobalCommands).build()); }); } @@ -124,15 +137,33 @@ public class ToolCommands { static void setToolNone(Player player, LocalSession session, boolean isBrush) throws InvalidToolBindException { - session.setTool(player, null); + isBrush = session.getTool(player) instanceof BrushTool; + session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null); player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip")); } + + 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())); + } + private final WorldEdit we; public ToolCommands(WorldEdit we) { this.we = we; } + @Command( + name = "none", + aliases = "unbind", + desc = "Unbind a bound tool from your current item" + ) + public void none(Player player, LocalSession session) throws WorldEditException { + setToolNone(player, session, false); + } + @Command( name = "selwand", aliases = "/selwand", @@ -140,9 +171,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.setwand") public void selwand(Player player, LocalSession session) throws WorldEditException { - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, SelectionWand.INSTANCE); - player.printInfo(TranslatableComponent.of("worldedit.tool.selwand.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, SelectionWand.INSTANCE, "worldedit.tool.selwand.equip"); } @Command( @@ -152,10 +181,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.setwand") public void navwand(Player player, LocalSession session) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, NavigationWand.INSTANCE); - player.printInfo(TranslatableComponent.of("worldedit.tool.navwand.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, NavigationWand.INSTANCE, "worldedit.tool.navwand.equip"); } @Command( @@ -165,10 +191,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.tool.info") public void info(Player player, LocalSession session) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new QueryTool()); - player.printInfo(TranslatableComponent.of("worldedit.tool.info.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new QueryTool(), "worldedit.tool.info.equip"); } @Command( @@ -178,9 +201,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.tool.inspect") public void inspectBrush(Player player, LocalSession session) throws WorldEditException { - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new InspectBrush()); - player.printInfo(TranslatableComponent.of("worldedit.tool.inspect.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new InspectBrush(), "worldedit.tool.info.equip"); } @Command( @@ -192,10 +213,20 @@ public class ToolCommands { public void tree(Player player, LocalSession session, @Arg(desc = "Type of tree to generate", def = "tree") TreeGenerator.TreeType type) throws WorldEditException { + setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip"); + } - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new TreePlanter(type)); - player.printInfo(TranslatableComponent.of("worldedit.tool.tree.equip", TextComponent.of(itemType.getName()))); + @Command( + name = "stacker", + desc = "Block stacker tool" + ) + @CommandPermissions("worldedit.tool.stack") + public void stacker(Player player, LocalSession session, + @Arg(desc = "The max range of the stack", def = "10") + int range, + @Arg(desc = "The mask to stack until", def = "!#existing") + Mask mask) throws WorldEditException { + setTool(player, session, new StackTool(range, mask), "worldedit.tool.stack.equip"); } @Command( @@ -207,10 +238,7 @@ public class ToolCommands { public void repl(Player player, LocalSession session, @Arg(desc = "The pattern of blocks to place") Pattern pattern) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new BlockReplacer(pattern)); - player.printInfo(TranslatableComponent.of("worldedit.tool.repl.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new BlockReplacer(pattern), "worldedit.tool.repl.equip"); } @Command( @@ -220,10 +248,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.tool.data-cycler") public void cycler(Player player, LocalSession session) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new BlockDataCyler()); - player.printInfo(TranslatableComponent.of("worldedit.tool.data-cycler.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new BlockDataCyler(), "worldedit.tool.data-cycler.equip"); } @Command( @@ -241,13 +266,10 @@ public class ToolCommands { LocalConfiguration config = we.getConfiguration(); if (range > config.maxSuperPickaxeSize) { - player.printError(TranslatableComponent.of("worldedit.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); + player.printError(TranslatableComponent.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); return; } - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new FloodFillTool(range, pattern)); - player.printInfo(TranslatableComponent.of("worldedit.tool.floodfill.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip"); } @Command( @@ -257,10 +279,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.tool.deltree") public void deltree(Player player, LocalSession session) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new FloatingTreeRemover()); - player.printInfo(TranslatableComponent.of("worldedit.tool.deltree.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new FloatingTreeRemover(), "worldedit.tool.deltree.equip"); } @Command( @@ -270,9 +289,7 @@ public class ToolCommands { ) @CommandPermissions("worldedit.tool.farwand") public void farwand(Player player, LocalSession session) throws WorldEditException { - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new DistanceWand()); - player.printInfo(TranslatableComponent.of("worldedit.tool.farwand.equip", TextComponent.of(itemType.getName()))); + setTool(player, session, new DistanceWand(), "worldedit.tool.farwand.equip"); } @Command( @@ -286,18 +303,19 @@ public class ToolCommands { Pattern primary, @Arg(desc = "Pattern to set on right-click") Pattern secondary) throws WorldEditException { - - final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); - session.setTool(player, new LongRangeBuildTool(primary, secondary)); - player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.equip", TextComponent.of(itemType.getName()))); - String primaryName = "pattern"; - String secondaryName = "pattern"; + setTool(player, session, new LongRangeBuildTool(primary, secondary), "worldedit.tool.lrbuild.equip"); + Component primaryName; + Component secondaryName; if (primary instanceof BlockStateHolder) { - primaryName = ((BlockStateHolder) primary).getBlockType().getName(); + primaryName = ((BlockStateHolder) primary).getBlockType().getRichName(); + } else { + primaryName = TextComponent.of("pattern"); } if (secondary instanceof BlockStateHolder) { - secondaryName = ((BlockStateHolder) secondary).getBlockType().getName(); + secondaryName = ((BlockStateHolder) secondary).getBlockType().getRichName(); + } else { + secondaryName = TextComponent.of("pattern"); } - player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", TextComponent.of(primaryName), TextComponent.of(secondaryName))); + player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", primaryName, secondaryName)); } } 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 14479c2a8..5c3aabb9e 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 @@ -78,7 +78,7 @@ public class BlockReplacer implements DoubleActionBlockTool { if (targetBlock != null) { pattern = targetBlock; - player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", TextComponent.of(targetBlock.getBlockType().getName()))); + player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", targetBlock.getBlockType().getRichName())); } 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 1f192aea1..ebce5559e 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 @@ -59,7 +59,7 @@ public class QueryTool implements BlockTool { TextComponent.Builder builder = TextComponent.builder(); builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); - builder.append(TextComponent.of(block.getBlockType().getName(), TextColor.YELLOW)); + 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")))); final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SubCommandPermissionCondition.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SubCommandPermissionCondition.java index 5ce55eb41..c3ac2f59d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SubCommandPermissionCondition.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SubCommandPermissionCondition.java @@ -19,10 +19,12 @@ package com.sk89q.worldedit.command.util; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.enginehub.piston.Command; import org.enginehub.piston.inject.InjectedValueAccess; +import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Set; @@ -45,8 +47,8 @@ public final class SubCommandPermissionCondition extends PermissionCondition { public static class Generator { private final List subCommands; - public Generator(List subCommands) { - this.subCommands = subCommands; + public Generator(Collection subCommands) { + this.subCommands = ImmutableList.copyOf(subCommands); } public Command.Condition build() { 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 c221acb6b..84bb1eb9e 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 @@ -83,6 +83,7 @@ import com.sk89q.worldedit.command.WorldEditCommands; import com.sk89q.worldedit.command.WorldEditCommandsRegistration; import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.BooleanConverter; +import com.sk89q.worldedit.command.argument.Chunk3dVectorConverter; import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter; import com.sk89q.worldedit.command.argument.DirectionConverter; import com.sk89q.worldedit.command.argument.DirectionVectorConverter; @@ -90,7 +91,9 @@ import com.sk89q.worldedit.command.argument.EntityRemoverConverter; import com.sk89q.worldedit.command.argument.EnumConverter; import com.sk89q.worldedit.command.argument.ExpressionConverter; import com.sk89q.worldedit.command.argument.FactoryConverter; +import com.sk89q.worldedit.command.argument.HeightConverter; import com.sk89q.worldedit.command.argument.LocationConverter; +import com.sk89q.worldedit.command.argument.OffsetConverter; import com.sk89q.worldedit.command.argument.RegionFactoryConverter; import com.sk89q.worldedit.command.argument.RegistryConverter; import com.sk89q.worldedit.command.argument.SideEffectConverter; @@ -250,6 +253,7 @@ public final class PlatformCommandManager { ); } VectorConverter.register(commandManager); + Chunk3dVectorConverter.register(commandManager); EnumConverter.register(commandManager); RegistryConverter.register(commandManager); ZonedDateTimeConverter.register(commandManager); @@ -260,6 +264,8 @@ public final class PlatformCommandManager { LocationConverter.register(commandManager); ExpressionConverter.register(commandManager); SideEffectConverter.register(commandManager); + HeightConverter.register(commandManager); + OffsetConverter.register(worldEdit, commandManager); registerBindings(new ConsumeBindings(worldEdit, this)); registerBindings(new PrimitiveBindings(worldEdit)); @@ -359,9 +365,8 @@ public final class PlatformCommandManager { } private void registerSubCommands(String name, List aliases, String desc, - CommandManager commandManager, - Consumer> handlerInstance, - @NotNull Consumer additionalConfig) { + Consumer> handlerInstance, + @NotNull Consumer additionalConfig) { commandManager.register(name, cmd -> { cmd.aliases(aliases); cmd.description(TextComponent.of(desc)); @@ -438,7 +443,6 @@ public final class PlatformCommandManager { "brush", Lists.newArrayList("br", "/brush", "/br", "/tool", "tool"), "Brushing commands", - commandManager, c -> { c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit)); c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit)); @@ -486,15 +490,11 @@ public final class PlatformCommandManager { ClipboardCommandsRegistration.builder(), new ClipboardCommands() ); - this.registration.register( - commandManager, - GeneralCommandsRegistration.builder(), - new GeneralCommands(worldEdit) - ); - this.registration.register( + GeneralCommands.register( + registration, commandManager, - GenerationCommandsRegistration.builder(), - new GenerationCommands(worldEdit) + commandManagerService, + worldEdit ); HistoryCommands history = new HistoryCommands(worldEdit); this.registration.register( 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 b55ba39d2..c880f365b 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 @@ -52,14 +52,12 @@ public class CommandUtil { private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated."); - private static Component makeDeprecatedFooter(String reason, Component newCommand) { + private static Component makeDeprecatedFooter(String reason, Component replacement) { return TextComponent.builder() .append(DEPRECATION_MARKER) .append(" " + reason + ".") .append(TextComponent.newline()) - .append(TextComponent.of("Use ", TextColor.GOLD, TextDecoration.ITALIC)) - .append(newCommand) - .append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC)) + .append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true)) .build(); } @@ -69,20 +67,48 @@ public class CommandUtil { } + public interface ReplacementMessageGenerator { + + /** + * Generate text that says "Please use [cmd] instead." and allows clicking to dump + * the command to the text box. + */ + static ReplacementMessageGenerator forNewCommand(NewCommandGenerator generator) { + return (oldCommand, oldParameters) -> { + String suggestedCommand = generator.newCommand(oldCommand, oldParameters); + return createNewCommandReplacementText(suggestedCommand); + }; + } + + Component getReplacement(Command oldCommand, CommandParameters oldParameters); + + } + + public static Component createNewCommandReplacementText(String suggestedCommand) { + return TextComponent.builder("Please use ", TextColor.GOLD) + .append(TextComponent.of(suggestedCommand) + .decoration(TextDecoration.UNDERLINED, true) + .clickEvent(ClickEvent.suggestCommand(suggestedCommand))) + .append(" instead.") + .build(); + } + public static Command deprecate(Command command, String reason, - NewCommandGenerator newCommandGenerator) { + ReplacementMessageGenerator replacementMessageGenerator) { Component deprecatedWarning = makeDeprecatedFooter( reason, - newCommandSuggestion(newCommandGenerator, - NoInputCommandParameters.builder().build(), - command) + replacementMessageGenerator.getReplacement( + command, + NoInputCommandParameters.builder().build() + ) ); return command.toBuilder() .action(parameters -> - deprecatedCommandWarning(parameters, command, reason, newCommandGenerator)) + deprecatedCommandWarning(parameters, command, reason, replacementMessageGenerator)) .footer(command.getFooter() .map(existingFooter -> existingFooter - .append(TextComponent.newline()).append(deprecatedWarning)) + .append(TextComponent.newline()) + .append(deprecatedWarning)) .orElse(deprecatedWarning)) .build(); } @@ -139,26 +165,28 @@ public class CommandUtil { CommandParameters parameters, Command command, String reason, - NewCommandGenerator generator + ReplacementMessageGenerator generator ) throws Exception { parameters.injectedValue(Key.of(Actor.class)) - .ifPresent(actor -> { - Component suggestion = newCommandSuggestion(generator, parameters, command); - actor.print(TextComponent.of(reason + ". Please use ", TextColor.GOLD) - .append(suggestion) - .append(TextComponent.of(" instead.")) - ); - }); + .ifPresent(actor -> + sendDeprecationMessage(parameters, command, reason, generator, actor) + ); return command.getAction().run(parameters); } - private static Component newCommandSuggestion(NewCommandGenerator generator, - CommandParameters parameters, - Command command) { - String suggestedCommand = generator.newCommand(command, parameters); - return TextComponent.of(suggestedCommand) - .decoration(TextDecoration.UNDERLINED, true) - .clickEvent(ClickEvent.suggestCommand(suggestedCommand)); + private static void sendDeprecationMessage( + CommandParameters parameters, + Command command, + String reason, + ReplacementMessageGenerator generator, + Actor actor + ) { + Component replacement = generator.getReplacement(command, parameters); + actor.print( + TextComponent.builder(reason + ". ", TextColor.GOLD) + .append(replacement) + .build() + ); } public static Map getSubCommands(Command currentCommand) { 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 549ea1d59..194a67be0 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,6 +36,7 @@ import com.sk89q.worldedit.command.InsufficientArgumentsException; import com.sk89q.worldedit.command.tool.InvalidToolBindException; 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.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; @@ -62,7 +63,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper { } private CommandException newCommandException(String message, Throwable cause) { - return new CommandException(TextComponent.of(String.valueOf(message)), cause, ImmutableList.of()); + return newCommandException(TextComponent.of(String.valueOf(message)), cause); + } + + private CommandException newCommandException(Component message, Throwable cause) { + return new CommandException(message, cause, ImmutableList.of()); } @ExceptionMatch @@ -158,7 +163,13 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper { @ExceptionMatch public void convert(InvalidToolBindException e) throws CommandException { - throw newCommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage(), e); + throw newCommandException( + TextComponent.builder("Can't bind tool to ") + .append(e.getItemType().getRichName()) + .append(": " + e.getMessage()) + .build(), + e + ); } @ExceptionMatch 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 9301a0493..c4086b08f 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 @@ -21,17 +21,19 @@ package com.sk89q.worldedit.util.formatting.component; import com.google.common.base.Function; import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableList; +import com.sk89q.worldedit.history.changeset.ChangeSet; 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.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import javax.annotation.Nullable; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.function.Supplier; -import javax.annotation.Nullable; +import java.util.stream.Collectors; public abstract class PaginationBox extends MessageBox { @@ -138,53 +140,30 @@ public abstract class PaginationBox extends MessageBox { } public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection lines, Function adapt) { - return fromStrings(header, pageCommand, Collections2.transform(lines, adapt)); + return fromComponents(header, pageCommand, Collections2.transform(lines, adapt)); } - public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection lines) { + public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection lines) { + return fromComponents(header, pageCommand, lines.stream() + .map(TextComponent::of) + .collect(Collectors.toList())); + } + + public static PaginationBox fromComponents(String header, @Nullable String pageCommand, Collection lines) { return new ListPaginationBox(header, pageCommand, lines); } - public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List lines) { - return fromStrings(header, pageCommand, (Collection) lines); - } + private static class ListPaginationBox extends PaginationBox { + private final List lines; - public static class ListPaginationBox extends PaginationBox { - private final Collection lines; - private int iterIndex; - private Iterator iterator; - - public ListPaginationBox(String header, String pageCommand, List lines) { - this(header, pageCommand, (Collection) lines); - } - - public ListPaginationBox(String header, String pageCommand, Collection lines) { + ListPaginationBox(String header, String pageCommand, Collection lines) { super(header, pageCommand); - this.lines = lines; + this.lines = ImmutableList.copyOf(lines); } @Override public Component getComponent(int number) { - Object obj; - if (lines instanceof List) { - obj = ((List) lines).get(number); - } else { - if (iterator == null || iterIndex > number) { - iterator = lines.iterator(); - iterIndex = 0; - } - do { - obj = iterator.next(); - iterIndex++; - } while (iterIndex < number); - } - if (obj instanceof Supplier) { - obj = ((Supplier) obj).get(); - } - if (obj instanceof Component) { - return (Component) obj; - } - return TextComponent.of(obj + ""); + return lines.get(number); } @Override 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 3e3e77f81..dc0272e1e 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 @@ -70,7 +70,7 @@ public class SideEffectBox extends PaginationBox { for (SideEffect.State uiState : SHOWN_VALUES) { builder = builder.append(TextComponent.space()); builder = builder.append(TranslatableComponent.of(uiState.getDisplayName(), uiState == state ? TextColor.WHITE : TextColor.GRAY) - .clickEvent(ClickEvent.runCommand("//fast -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US))) + .clickEvent(ClickEvent.runCommand("//perf -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US))) .hoverEvent(HoverEvent.showText(uiState == state ? TranslatableComponent.of("worldedit.sideeffect.box.current") : TranslatableComponent.of("worldedit.sideeffect.box.change-to", TranslatableComponent.of(uiState.getDisplayName())) 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 4d1a09b91..72307720f 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 @@ -19,6 +19,8 @@ package com.sk89q.worldedit.world.biome; +import com.sk89q.worldedit.world.registry.BiomeRegistry; + /** * Provides information about a biome. * @@ -32,6 +34,8 @@ public interface BiomeData { * particular convention. * * @return the biome's name + * @deprecated This method does not work on the server. + * Use {@link BiomeRegistry#getRichName(BiomeType)}. */ @Deprecated String getName(); 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 8ccb2b136..3686d8ed9 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 @@ -33,6 +33,7 @@ import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.PropertyKey; 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; @@ -96,6 +97,11 @@ public class BlockType implements Keyed, Pattern { return this.id; } + public Component getRichName() { + return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) + .getRegistries().getBlockRegistry().getRichName(this); + } + public String getNamespace() { String id = getId(); int i = id.indexOf(':'); @@ -111,15 +117,11 @@ public class BlockType implements Keyed, Pattern { * 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 public String getName() { - String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this); - if (name == null) { - return getId(); - } else { - return name; - } + return getRichName().toString(); } /* @@ -274,9 +276,7 @@ public class BlockType implements Keyed, Pattern { /** * Gets the legacy ID. Needed for legacy reasons. * - *

* DO NOT USE THIS. - *

* * @return legacy id or 0, if unknown */ @@ -286,11 +286,39 @@ public class BlockType implements Keyed, Pattern { return combinedId == null ? 0 : combinedId; } + /** + * Gets the legacy data. Needed for legacy reasons. + * + * DO NOT USE THIS. + * + * @return legacy data or 0, if unknown + */ @Deprecated public int getLegacyId() { return computeLegacy(0); } + /** + * Gets the legacy data. Needed for legacy reasons. + * + *

+ * DO NOT USE THIS. + *

+ * + * @return legacy data or 0, if unknown + */ + @Deprecated + public int getLegacyData() { + return computeLegacy(1); + } + + private int computeLegacy(int index) { + if (this.legacyCombinedId == null) { + this.legacyCombinedId = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState()); + } + return index == 0 ? legacyCombinedId >> 4 : legacyCombinedId & 15; + } + /** * The internal index of this type. * @@ -336,25 +364,4 @@ public class BlockType implements Keyed, Pattern { public SingleBlockTypeMask toMask(Extent extent) { return new SingleBlockTypeMask(extent, this); } - - /** - * Gets the legacy data. Needed for legacy reasons. - * - *

- * DO NOT USE THIS. - *

- * - * @return legacy data or 0, if unknown - */ - @Deprecated - public int getLegacyData() { - return computeLegacy(1); - } - - private int computeLegacy(int index) { - if (this.legacyCombinedId == null) { - this.legacyCombinedId = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState()); - } - return index == 0 ? legacyCombinedId >> 4 : legacyCombinedId & 15; - } } 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 05e6b075a..3e18c4777 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,6 +19,7 @@ package com.sk89q.worldedit.world.registry; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; @@ -29,11 +30,21 @@ import javax.annotation.Nullable; */ public interface BiomeRegistry { + /** + * Get the name of the biome, usually as a translatable component. + * + * @param biomeType the biome type + * @return the name of the biome + */ + Component getRichName(BiomeType biomeType); + /** * Get data about a biome. * * @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. */ @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 de439dcf9..e7bad3d86 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,29 +20,41 @@ 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.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; +import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.OptionalInt; -import javax.annotation.Nullable; /** * Provides information on blocks and provides methods to create them. */ public interface BlockRegistry { + /** + * Gets the name for the given block. + * + * @param blockType the block + * @return The name + */ + Component getRichName(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 @Nullable - String getName(BlockType blockType); + default String getName(BlockType blockType) { + return getRichName(blockType).toString(); + } /** * Get the material for the given block. 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 435fb21c7..25e0b999b 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,6 +20,10 @@ 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.translation.TranslationManager; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -34,11 +38,19 @@ import javax.annotation.Nullable; */ public class BundledBlockRegistry implements BlockRegistry { - @Nullable @Override - public String getName(BlockType blockType) { + public Component getRichName(BlockType blockType) { BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId()); - return blockEntry != null ? blockEntry.localizedName : null; + 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 TranslatableComponent.of( + TranslationManager.makeTranslationKey("block", blockType.getId()) + ); } @Nullable 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 274dbf171..7458da4d9 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 @@ -23,9 +23,9 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.item.ItemType; +import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; -import javax.annotation.Nullable; public interface ItemRegistry { 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 b26e10fda..7951b25a0 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,6 +19,9 @@ 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.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; @@ -35,6 +38,14 @@ public class NullBiomeRegistry implements BiomeRegistry { public NullBiomeRegistry() { } + @Override + public Component getRichName(BiomeType biomeType) { + return TranslatableComponent.of( + TranslationManager.makeTranslationKey("biome", biomeType.getId()) + ); + } + + @Deprecated @Nullable @Override public BiomeData getData(BiomeType biome) { diff --git a/worldedit-core/src/main/resources/lang/strings.json b/worldedit-core/src/main/resources/lang/strings.json index 5e9d7f986..9a8bf4a62 100644 --- a/worldedit-core/src/main/resources/lang/strings.json +++ b/worldedit-core/src/main/resources/lang/strings.json @@ -212,13 +212,13 @@ "worldedit.timeout.set": "Timeout time set to {0}ms.", "worldedit.timeout.return-to-default": " (Use //timeout to go back to the default.)", "worldedit.fast.disabled": "Fast mode disabled.", - "worldedit.fast.enabled": "Fast mode enabled. Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.", + "worldedit.fast.enabled": "Fast mode enabled. Changes won't be written to history (//undo is disabled). Lighting in the affected chunks may be wrong and/or you may need to rejoin to see changes.", "worldedit.fast.disabled.already": "Fast mode already disabled.", "worldedit.fast.enabled.already": "Fast mode already enabled.", - "worldedit.fast.sideeffect.set": "Side effect \"{0}\" set to {1}", - "worldedit.fast.sideeffect.get": "Side effect \"{0}\" is set to {1}", - "worldedit.fast.sideeffect.already-set": "Side effect \"{0}\" is already {1}", - "worldedit.fast.sideeffect.set-all": "All side effects set to {0}", + "worldedit.perf.sideeffect.set": "Side effect \"{0}\" set to {1}", + "worldedit.perf.sideeffect.get": "Side effect \"{0}\" is set to {1}", + "worldedit.perf.sideeffect.already-set": "Side effect \"{0}\" is already {1}", + "worldedit.perf.sideeffect.set-all": "All side effects set to {0}", "worldedit.reorder.current": "The reorder mode is {0}", "worldedit.reorder.set": "The reorder mode is now {0}", "worldedit.gmask.disabled": "Global mask disabled.", 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 ea2c48849..a005feaf8 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,6 +19,8 @@ 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.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome; */ class FabricBiomeRegistry implements BiomeRegistry { + @Override + public Component getRichName(BiomeType biomeType) { + return TranslatableComponent.of(FabricAdapter.adapt(biomeType).getTranslationKey()); + } + + @Deprecated @Override public BiomeData getData(BiomeType biome) { return new FabricBiomeData(FabricAdapter.adapt(biome)); @@ -37,6 +45,7 @@ class FabricBiomeRegistry implements BiomeRegistry { /** * Cached biome data information. */ + @Deprecated private static class FabricBiomeData implements BiomeData { private final Biome biome; @@ -49,6 +58,7 @@ class FabricBiomeRegistry implements BiomeRegistry { this.biome = biome; } + @SuppressWarnings("deprecation") @Override public String getName() { return biome.getName().asFormattedString(); 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 c54a27769..1d9e62eae 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 @@ -20,17 +20,15 @@ package com.sk89q.worldedit.fabric; 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.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BundledBlockRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Material; -import javax.annotation.Nullable; - import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -41,15 +39,9 @@ public class FabricBlockRegistry extends BundledBlockRegistry { private Map materialMap = new HashMap<>(); - @Nullable @Override - public String getName(BlockType blockType) { - Block block = FabricAdapter.adapt(blockType); - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - return block.getName().asFormattedString(); - } else { - return super.getName(blockType); - } + public Component getRichName(BlockType blockType) { + return TranslatableComponent.of(FabricAdapter.adapt(blockType).getTranslationKey()); } @Override 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 6f19555c6..8218b932f 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 @@ -19,24 +19,26 @@ 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.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.resource.language.I18n; -import net.minecraft.item.Item; - -import javax.annotation.Nullable; public class FabricItemRegistry extends BundledItemRegistry { - @Nullable @Override - public String getName(ItemType itemType) { - if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - final Item item = FabricAdapter.adapt(itemType); - return I18n.translate(item.getTranslationKey()); - } - return super.getName(itemType); + public Component getRichName(ItemType itemType) { + return TranslatableComponent.of( + FabricAdapter.adapt(itemType).getTranslationKey() + ); } + + @Override + public Component getRichName(BaseItemStack itemStack) { + return TranslatableComponent.of( + FabricAdapter.adapt(itemStack).getTranslationKey() + ); + } + } 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 c8fa3f8da..38b24d78b 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,6 +19,8 @@ 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.world.biome.BiomeData; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome; */ class ForgeBiomeRegistry implements BiomeRegistry { + @Override + public Component getRichName(BiomeType biomeType) { + return TranslatableComponent.of(ForgeAdapter.adapt(biomeType).getTranslationKey()); + } + + @Deprecated @Override public BiomeData getData(BiomeType biome) { return new ForgeBiomeData(ForgeAdapter.adapt(biome)); @@ -37,6 +45,7 @@ class ForgeBiomeRegistry implements BiomeRegistry { /** * Cached biome data information. */ + @Deprecated private static class ForgeBiomeData implements BiomeData { private final Biome biome; @@ -49,6 +58,7 @@ class ForgeBiomeRegistry implements BiomeRegistry { this.biome = biome; } + @SuppressWarnings("deprecation") @Override public String getName() { return biome.getDisplayName().getString(); 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 a6c3f45b9..cdb67bb57 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 @@ -20,6 +20,8 @@ package com.sk89q.worldedit.forge; 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.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BlockMaterial; @@ -27,9 +29,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.state.IProperty; -import net.minecraftforge.fml.loading.FMLLoader; -import javax.annotation.Nullable; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -40,15 +40,9 @@ public class ForgeBlockRegistry extends BundledBlockRegistry { private Map materialMap = new HashMap<>(); - @Nullable @Override - public String getName(BlockType blockType) { - Block block = ForgeAdapter.adapt(blockType); - if (block != null && FMLLoader.getDist().isClient()) { - return block.getNameTextComponent().getFormattedText(); - } else { - return super.getName(blockType); - } + public Component getRichName(BlockType blockType) { + return TranslatableComponent.of(ForgeAdapter.adapt(blockType).getTranslationKey()); } @Override 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 8bf23c6cb..873eab3cf 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 @@ -19,33 +19,26 @@ package com.sk89q.worldedit.forge; -import com.sk89q.worldedit.blocks.BaseItem; -import com.sk89q.worldedit.world.item.ItemTypes; -import com.sk89q.worldedit.world.registry.ItemRegistry; -import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; +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.world.item.ItemType; import com.sk89q.worldedit.world.registry.BundledItemRegistry; -import javax.annotation.Nullable; -import net.minecraft.client.resources.I18n; -import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.loading.FMLLoader; -import net.minecraftforge.registries.RegistryManager; - public class ForgeItemRegistry extends BundledItemRegistry { - @Nullable @Override - public String getName(ItemType itemType) { - if (FMLLoader.getDist().isClient()) { - final Item item = RegistryManager.ACTIVE.getRegistry(Item.class) - .getValue(ResourceLocation.tryCreate(itemType.getId())); - if (item != null) { - return I18n.format(item.getTranslationKey()); - } - } - return super.getName(itemType); + public Component getRichName(ItemType itemType) { + return TranslatableComponent.of( + ForgeAdapter.adapt(itemType).getTranslationKey() + ); } + + @Override + public Component getRichName(BaseItemStack itemStack) { + return TranslatableComponent.of( + ForgeAdapter.adapt(itemStack).getTranslationKey() + ); + } + } 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 dba2a904c..fd012d294 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,6 +19,9 @@ 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.translation.TranslationManager; import com.sk89q.worldedit.world.biome.BiomeData; import com.sk89q.worldedit.world.registry.BiomeRegistry; import org.spongepowered.api.world.biome.BiomeType; @@ -30,12 +33,21 @@ import javax.annotation.Nullable; */ class SpongeBiomeRegistry implements BiomeRegistry { + @Override + public Component getRichName(com.sk89q.worldedit.world.biome.BiomeType biomeType) { + return TranslatableComponent.of( + TranslationManager.makeTranslationKey("biome", biomeType.getId()) + ); + } + + @Deprecated @Nullable @Override public BiomeData getData(com.sk89q.worldedit.world.biome.BiomeType biome) { return new SpongeBiomeData(SpongeAdapter.adapt(biome)); } + @Deprecated private static class SpongeBiomeData implements BiomeData { private final BiomeType biome; @@ -48,6 +60,7 @@ class SpongeBiomeRegistry implements BiomeRegistry { this.biome = biome; } + @SuppressWarnings("deprecation") @Override public String getName() { return biome.getName();