Upstream changes (#717)

* 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 <octavia.togami@gmail.com>
Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com>
Co-authored-by: Aurora <aurora@relanet.eu>
This commit is contained in:
Hannes Greule 2020-11-09 10:38:10 +01:00 committed by GitHub
parent 49052d73ce
commit 428f8e201d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 660 additions and 303 deletions

View File

@ -25,6 +25,11 @@ fun Project.applyLibrariesConfiguration() {
group = "${rootProject.group}.worldedit-libs" 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<ShadowJar>("jar") { tasks.register<ShadowJar>("jar") {
configurations = listOf(project.configurations["shade"]) configurations = listOf(project.configurations["shade"])
archiveClassifier.set("") archiveClassifier.set("")
@ -36,13 +41,15 @@ fun Project.applyLibrariesConfiguration() {
exclude(dependency("org.slf4j:slf4j-api")) 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 altConfigFiles = { artifactType: String ->
val deps = configurations["shade"].incoming.dependencies val deps = configurations["shade"].incoming.dependencies
.filterIsInstance<ModuleDependency>() .filterIsInstance<ModuleDependency>()
.map { it.copy() } .map { it.copy() }
.map { dependency: ModuleDependency -> .map { dependency ->
dependency.artifact { dependency.artifact {
name = dependency.name name = dependency.name
type = artifactType type = artifactType
@ -61,13 +68,15 @@ fun Project.applyLibrariesConfiguration() {
from({ from({
altConfigFiles("sources") altConfigFiles("sources")
}) })
val filePattern = Regex("(.*)net/kyori/text((?:/|$).*)") relocations.forEach { (from, to) ->
val textPattern = Regex("net\\.kyori\\.text") val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
val textPattern = Regex.fromLiteral(from)
eachFile { eachFile {
filter { filter {
it.replaceFirst(textPattern, "com.sk89q.worldedit.util.formatting.text") 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") archiveClassifier.set("sources")
} }

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.bukkit; 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.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -34,6 +37,14 @@ class BukkitBiomeRegistry implements BiomeRegistry {
BukkitBiomeRegistry() { BukkitBiomeRegistry() {
} }
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("biome", biomeType.getId())
);
}
@Deprecated
@Nullable @Nullable
@Override @Override
public BiomeData getData(BiomeType biome) { public BiomeData getData(BiomeType biome) {

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; 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.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
@ -39,6 +40,14 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
private BukkitBlockMaterial[] materialMap; 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 @Nullable
@Override @Override
public BlockMaterial getMaterial(BlockType blockType) { public BlockMaterial getMaterial(BlockType blockType) {

View File

@ -19,13 +19,32 @@
package com.sk89q.worldedit.bukkit; 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 com.sk89q.worldedit.world.registry.BundledItemRegistry;
import org.bukkit.Material; import org.bukkit.Material;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; 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 @Override
public Collection<String> values() { public Collection<String> values() {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import com.sk89q.worldedit.world.registry.BlockCategoryRegistry; import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;
import com.sk89q.worldedit.world.registry.BlockRegistry; 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.BundledRegistries;
import com.sk89q.worldedit.world.registry.EntityRegistry; import com.sk89q.worldedit.world.registry.EntityRegistry;
import com.sk89q.worldedit.world.registry.ItemCategoryRegistry; import com.sk89q.worldedit.world.registry.ItemCategoryRegistry;
@ -35,8 +34,8 @@ class BukkitRegistries extends BundledRegistries {
private static final BukkitRegistries INSTANCE = new BukkitRegistries(); private static final BukkitRegistries INSTANCE = new BukkitRegistries();
private final BlockRegistry blockRegistry = new BukkitBlockRegistry(); private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry(); private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
private final EntityRegistry entityRegistry = new BukkitEntityRegistry(); private final EntityRegistry entityRegistry = new BukkitEntityRegistry();
private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry(); private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry();
private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry(); private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry();
@ -57,6 +56,11 @@ class BukkitRegistries extends BundledRegistries {
return biomeRegistry; return biomeRegistry;
} }
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
@Override @Override
public BlockCategoryRegistry getBlockCategoryRegistry() { public BlockCategoryRegistry getBlockCategoryRegistry() {
return blockCategoryRegistry; return blockCategoryRegistry;
@ -81,8 +85,4 @@ class BukkitRegistries extends BundledRegistries {
return INSTANCE; return INSTANCE;
} }
@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}
} }

View File

@ -36,12 +36,14 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.SideEffect; 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.DataFixer;
import com.sk89q.worldedit.world.RegenOptions; import com.sk89q.worldedit.world.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -52,10 +54,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable;
/** /**
* An interface for adapters of various Bukkit implementations. * An interface for adapters of various Bukkit implementations.
@ -127,6 +129,30 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
@Nullable @Nullable
Entity createEntity(Location location, BaseEntity state); 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}. * Get a map of {@code string -> property}.
* *

View File

@ -48,6 +48,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; 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.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; 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.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_15_R1.BiomeBase; import net.minecraft.server.v1_15_R1.BiomeBase;
import net.minecraft.server.v1_15_R1.Block; 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 @Override
public OptionalInt getInternalBlockStateId(BlockState state) { public OptionalInt getInternalBlockStateId(BlockState state) {
BlockMaterial_1_15_2 material = (BlockMaterial_1_15_2) state.getMaterial(); BlockMaterial_1_15_2 material = (BlockMaterial_1_15_2) state.getMaterial();

View File

@ -47,6 +47,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; 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.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; 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.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R1.BiomeBase; import net.minecraft.server.v1_16_R1.BiomeBase;
import net.minecraft.server.v1_16_R1.Block; 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 @Override
public OptionalInt getInternalBlockStateId(BlockState state) { public OptionalInt getInternalBlockStateId(BlockState state) {
BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial(); BlockMaterial_1_16_1 material = (BlockMaterial_1_16_1) state.getMaterial();

View File

@ -47,6 +47,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; 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.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; 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.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R2.BiomeBase; import net.minecraft.server.v1_16_R2.BiomeBase;
import net.minecraft.server.v1_16_R2.Block; 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 @Override
public OptionalInt getInternalBlockStateId(BlockState state) { public OptionalInt getInternalBlockStateId(BlockState state) {
BlockMaterial_1_16_2 material = (BlockMaterial_1_16_2) state.getMaterial(); BlockMaterial_1_16_2 material = (BlockMaterial_1_16_2) state.getMaterial();

View File

@ -48,6 +48,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.SideEffect; import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; 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.RegenOptions;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; 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.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.server.v1_16_R3.BiomeBase; import net.minecraft.server.v1_16_R3.BiomeBase;
import net.minecraft.server.v1_16_R3.Block; 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 @Override
public OptionalInt getInternalBlockStateId(BlockState state) { public OptionalInt getInternalBlockStateId(BlockState state) {
BlockMaterial_1_16_4 material = (BlockMaterial_1_16_4) state.getMaterial(); BlockMaterial_1_16_4 material = (BlockMaterial_1_16_4) state.getMaterial();

View File

@ -591,15 +591,17 @@ public final class WorldEdit {
Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks(); Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks();
if (!missingBlocks.isEmpty()) { if (!missingBlocks.isEmpty()) {
StringBuilder str = new StringBuilder(); TextComponent.Builder str = TextComponent.builder();
str.append("Missing these blocks: "); str.append("Missing these blocks: ");
int size = missingBlocks.size(); int size = missingBlocks.size();
int i = 0; int i = 0;
for (Map.Entry<BlockType, Integer> blockTypeIntegerEntry : missingBlocks.entrySet()) { for (Map.Entry<BlockType, Integer> 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; ++i;
@ -608,7 +610,7 @@ public final class WorldEdit {
} }
} }
actor.printError(str.toString()); actor.printError(str.build());
} }
} }

View File

@ -20,6 +20,9 @@
package com.sk89q.worldedit.blocks; package com.sk89q.worldedit.blocks;
import com.sk89q.jnbt.CompoundTag; 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; import com.sk89q.worldedit.world.item.ItemType;
/** /**
@ -80,4 +83,9 @@ public class BaseItemStack extends BaseItem {
public void setAmount(int amount) { public void setAmount(int amount) {
this.amount = amount; this.amount = amount;
} }
public Component getRichName() {
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getItemRegistry().getRichName(this);
}
} }

View File

@ -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.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.world.World; 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.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
@ -87,22 +86,18 @@ public class BiomeCommands {
@ArgFlag(name = 'p', desc = "Page number.", def = "1") @ArgFlag(name = 'p', desc = "Page number.", def = "1")
int page) { int page) {
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
BiomeRegistry biomeRegistry = BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS) .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
.getRegistries().getBiomeRegistry();
PaginationBox paginationBox = PaginationBox PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%",
.fromStrings("Available Biomes", "/biomelist -p %page%", BiomeType.REGISTRY.values().stream()
BiomeType.REGISTRY.values().stream().map(biomeType -> { .map(biomeType -> TextComponent.builder()
String id = biomeType.getId(); .append(biomeType.getId())
final BiomeData data = biomeRegistry.getData(biomeType); .append(" (")
if (data != null) { .append(biomeRegistry.getRichName(biomeType))
String name = data.getName(); .append(")")
return id + " (" + name + ")"; .build())
} else { .collect(Collectors.toList()));
return id;
}
}).collect(Collectors.toList()));
return paginationBox.create(page); return paginationBox.create(page);
}, (Component) null); }, (Component) null);
} }
@ -150,14 +145,11 @@ public class BiomeCommands {
messageKey = "worldedit.biomeinfo.selection"; messageKey = "worldedit.biomeinfo.selection";
} }
List<Component> components = biomes.stream().map(biome -> { List<Component> components = biomes.stream().map(biome ->
BiomeData data = biomeRegistry.getData(biome); biomeRegistry.getRichName(biome).hoverEvent(
if (data != null) { HoverEvent.showText(TextComponent.of(biome.getId()))
return TextComponent.of(data.getName()).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId()))); )
} else { ).collect(Collectors.toList());
return TextComponent.of(biome.getId());
}
}).collect(Collectors.toList());
player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", ")))); player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
} }

View File

@ -153,6 +153,7 @@ public class BrushCommands {
this.worldEdit = worldEdit; this.worldEdit = worldEdit;
} }
/* Covered by ToolCommands
@Command( @Command(
name = "none", name = "none",
aliases = "unbind", aliases = "unbind",
@ -161,6 +162,7 @@ public class BrushCommands {
void none(Player player, LocalSession session) throws WorldEditException { void none(Player player, LocalSession session) throws WorldEditException {
ToolCommands.setToolNone(player, session, true); ToolCommands.setToolNone(player, session, true);
} }
*/
@Command(name = "blendball", @Command(name = "blendball",
aliases = { aliases = {

View File

@ -174,17 +174,22 @@ public class ChunkCommands {
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop")))); .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 Region region;
private final List<BlockVector2> chunks = null; private final List<BlockVector2> chunks = null;
ChunkListPaginationBox(Region region) { ChunkListPaginationBox(Region region) {
super("Selected Chunks", "/listchunks -p %page%", region.getChunks()); super("Selected Chunks", "/listchunks -p %page%");
} }
@Override @Override
public Component getComponent(int number) { public Component getComponent(int number) {
return create(number); return TextComponent.of(chunks.get(number).toString());
}
@Override
public int getComponentsSize() {
return chunks.size();
} }
} }
} }

View File

@ -28,6 +28,7 @@ import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.RandomTextureUtil; import com.boydti.fawe.util.RandomTextureUtil;
import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.TextureUtil;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; 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.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.HookMode; import com.sk89q.worldedit.command.util.HookMode;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.extension.input.DisallowedUsageException;
import com.sk89q.worldedit.extension.input.InputParseException; 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.extension.platform.Capability;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.Mask; 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.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet; import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.formatting.component.PaginationBox; 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.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.item.ItemType; 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.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
@ -65,8 +72,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull; 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) @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class GeneralCommands { 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<org.enginehub.piston.Command> 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<String> 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; private final WorldEdit worldEdit;
/** /**
@ -145,10 +213,36 @@ public class GeneralCommands {
@Command( @Command(
name = "/fast", name = "/fast",
desc = "Toggle fast mode side effects" desc = "Toggle fast mode"
) )
@CommandPermissions("worldedit.fast") @CommandPermissions("worldedit.fast")
public void fast(Actor actor, LocalSession session, @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 = "") @Arg(desc = "The side effect", def = "")
SideEffect sideEffect, SideEffect sideEffect,
@Arg(desc = "The new side effect state", def = "") @Arg(desc = "The new side effect state", def = "")
@ -160,7 +254,7 @@ public class GeneralCommands {
if (newState != null && newState == currentState) { if (newState != null && newState == currentState) {
if (!showInfoBox) { if (!showInfoBox) {
actor.printError(TranslatableComponent.of( actor.printError(TranslatableComponent.of(
"worldedit.fast.sideeffect.already-set", "worldedit.perf.sideeffect.already-set",
TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(sideEffect.getDisplayName()),
TranslatableComponent.of(newState.getDisplayName()) TranslatableComponent.of(newState.getDisplayName())
)); ));
@ -172,14 +266,14 @@ public class GeneralCommands {
session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState)); session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState));
if (!showInfoBox) { if (!showInfoBox) {
actor.printInfo(TranslatableComponent.of( actor.printInfo(TranslatableComponent.of(
"worldedit.fast.sideeffect.set", "worldedit.perf.sideeffect.set",
TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(sideEffect.getDisplayName()),
TranslatableComponent.of(newState.getDisplayName()) TranslatableComponent.of(newState.getDisplayName())
)); ));
} }
} else { } else {
actor.printInfo(TranslatableComponent.of( actor.printInfo(TranslatableComponent.of(
"worldedit.fast.sideeffect.get", "worldedit.perf.sideeffect.get",
TranslatableComponent.of(sideEffect.getDisplayName()), TranslatableComponent.of(sideEffect.getDisplayName()),
TranslatableComponent.of(currentState.getDisplayName()) TranslatableComponent.of(currentState.getDisplayName())
)); ));
@ -192,7 +286,7 @@ public class GeneralCommands {
session.setSideEffectSet(applier); session.setSideEffectSet(applier);
if (!showInfoBox) { if (!showInfoBox) {
actor.printInfo(TranslatableComponent.of( actor.printInfo(TranslatableComponent.of(
"worldedit.fast.sideeffect.set-all", "worldedit.perf.sideeffect.set-all",
TranslatableComponent.of(newState.getDisplayName()) TranslatableComponent.of(newState.getDisplayName())
)); ));
} }
@ -331,7 +425,7 @@ public class GeneralCommands {
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1") @ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
int page, int page,
@Arg(desc = "Search query", variable = true) @Arg(desc = "Search query", variable = true)
List<String> query) throws Exception { List<String> query) {
String search = String.join(" ", query); String search = String.join(" ", query);
if (search.length() <= 2) { if (search.length() <= 2) {
actor.printError(TranslatableComponent.of("worldedit.searchitem.too-short")); actor.printError(TranslatableComponent.of("worldedit.searchitem.too-short"));
@ -342,7 +436,8 @@ public class GeneralCommands {
return; 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<Component> { private static class ItemSearcher implements Callable<Component> {
@ -361,7 +456,7 @@ public class GeneralCommands {
@Override @Override
public Component call() throws Exception { public Component call() throws Exception {
String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search; String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search;
Map<String, String> results = new TreeMap<>(); Map<String, Component> results = new TreeMap<>();
String idMatch = search.replace(' ', '_'); String idMatch = search.replace(' ', '_');
String nameMatch = search.toLowerCase(Locale.ROOT); String nameMatch = search.toLowerCase(Locale.ROOT);
for (ItemType searchType : ItemType.REGISTRY) { for (ItemType searchType : ItemType.REGISTRY) {
@ -373,15 +468,17 @@ public class GeneralCommands {
continue; continue;
} }
final String id = searchType.getId(); final String id = searchType.getId();
String name = searchType.getName(); if (id.contains(idMatch)) {
final boolean hasName = !name.equals(id); Component name = searchType.getRichName();
name = name.toLowerCase(Locale.ROOT); results.put(id, TextComponent.builder()
if (id.contains(idMatch) || (hasName && name.contains(nameMatch))) { .append(name)
results.put(id, name + (hasName ? " (" + id + ")" : "")); .append(" (" + id + ")")
.build());
} }
} }
List<String> list = new ArrayList<>(results.values()); List<Component> list = new ArrayList<>(results.values());
return PaginationBox.fromStrings("Search results for '" + search + "'", command, list).create(page); return PaginationBox.fromComponents("Search results for '" + search + "'", command, list)
.create(page);
} }
} }

View File

@ -561,7 +561,7 @@ public class SchematicCommands {
return msg.create(); return msg.create();
}); });
PaginationBox paginationBox = PaginationBox.fromStrings("Available schematics", pageCommand, components); PaginationBox paginationBox = PaginationBox.fromComponents("Available schematics", pageCommand, components);
actor.print(paginationBox.create(page)); actor.print(paginationBox.create(page));
} }

View File

@ -715,7 +715,7 @@ public class SelectionCommands {
final BlockState state = c.getID(); final BlockState state = c.getID();
final BlockType blockType = state.getBlockType(); final BlockType blockType = state.getBlockType();
TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE); Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE);
TextComponent toolTip; TextComponent toolTip;
if (separateStates && state != blockType.getDefaultState()) { if (separateStates && state != blockType.getDefaultState()) {
toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY);

View File

@ -25,8 +25,10 @@ import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.command.tool.BlockDataCyler; import com.sk89q.worldedit.command.tool.BlockDataCyler;
import com.sk89q.worldedit.command.tool.BlockReplacer; 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.DistanceWand;
import com.sk89q.worldedit.command.tool.FloatingTreeRemover; import com.sk89q.worldedit.command.tool.FloatingTreeRemover;
import com.sk89q.worldedit.command.tool.FloodFillTool; 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.NavigationWand;
import com.sk89q.worldedit.command.tool.QueryTool; import com.sk89q.worldedit.command.tool.QueryTool;
import com.sk89q.worldedit.command.tool.SelectionWand; 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.tool.TreePlanter;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.SubCommandPermissionCondition;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.CommandUtil; import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator; 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.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService; import org.enginehub.piston.CommandManagerService;
import org.enginehub.piston.CommandMetadata; import org.enginehub.piston.CommandMetadata;
@ -82,14 +88,19 @@ public class ToolCommands {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
for (org.enginehub.piston.Command command : commands) { for (org.enginehub.piston.Command command : commands) {
if (command.getAliases().contains("unbind")) { if (command.getAliases().contains("unbind")) {
// Don't register new /tool unbind alias // Don't register new /tool <whatever> alias
command = command.toBuilder().aliases( command = command.toBuilder().aliases(
Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias)) Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias))
).build(); ).build();
} }
if (command.getName().equals("stacker")) {
// Don't register /stacker
continue;
}
commandManager.register(CommandUtil.deprecate( commandManager.register(CommandUtil.deprecate(
command, "Global tool names cause conflicts " 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() .required()
.build()); .build());
command.description(TextComponent.of("Binds a tool to the item in your hand")); 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) static void setToolNone(Player player, LocalSession session, boolean isBrush)
throws InvalidToolBindException { 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")); 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; private final WorldEdit we;
public ToolCommands(WorldEdit we) { public ToolCommands(WorldEdit we) {
this.we = 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( @Command(
name = "selwand", name = "selwand",
aliases = "/selwand", aliases = "/selwand",
@ -140,9 +171,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.setwand") @CommandPermissions("worldedit.setwand")
public void selwand(Player player, LocalSession session) throws WorldEditException { public void selwand(Player player, LocalSession session) throws WorldEditException {
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); setTool(player, session, SelectionWand.INSTANCE, "worldedit.tool.selwand.equip");
session.setTool(player, SelectionWand.INSTANCE);
player.printInfo(TranslatableComponent.of("worldedit.tool.selwand.equip", TextComponent.of(itemType.getName())));
} }
@Command( @Command(
@ -152,10 +181,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.setwand") @CommandPermissions("worldedit.setwand")
public void navwand(Player player, LocalSession session) throws WorldEditException { public void navwand(Player player, LocalSession session) throws WorldEditException {
setTool(player, session, NavigationWand.INSTANCE, "worldedit.tool.navwand.equip");
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())));
} }
@Command( @Command(
@ -165,10 +191,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.info") @CommandPermissions("worldedit.tool.info")
public void info(Player player, LocalSession session) throws WorldEditException { public void info(Player player, LocalSession session) throws WorldEditException {
setTool(player, session, new QueryTool(), "worldedit.tool.info.equip");
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())));
} }
@Command( @Command(
@ -178,9 +201,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.inspect") @CommandPermissions("worldedit.tool.inspect")
public void inspectBrush(Player player, LocalSession session) throws WorldEditException { public void inspectBrush(Player player, LocalSession session) throws WorldEditException {
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); setTool(player, session, new InspectBrush(), "worldedit.tool.info.equip");
session.setTool(player, new InspectBrush());
player.printInfo(TranslatableComponent.of("worldedit.tool.inspect.equip", TextComponent.of(itemType.getName())));
} }
@Command( @Command(
@ -192,10 +213,20 @@ public class ToolCommands {
public void tree(Player player, LocalSession session, public void tree(Player player, LocalSession session,
@Arg(desc = "Type of tree to generate", def = "tree") @Arg(desc = "Type of tree to generate", def = "tree")
TreeGenerator.TreeType type) throws WorldEditException { TreeGenerator.TreeType type) throws WorldEditException {
setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip");
}
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); @Command(
session.setTool(player, new TreePlanter(type)); name = "stacker",
player.printInfo(TranslatableComponent.of("worldedit.tool.tree.equip", TextComponent.of(itemType.getName()))); 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( @Command(
@ -207,10 +238,7 @@ public class ToolCommands {
public void repl(Player player, LocalSession session, public void repl(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to place") @Arg(desc = "The pattern of blocks to place")
Pattern pattern) throws WorldEditException { Pattern pattern) throws WorldEditException {
setTool(player, session, new BlockReplacer(pattern), "worldedit.tool.repl.equip");
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())));
} }
@Command( @Command(
@ -220,10 +248,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.data-cycler") @CommandPermissions("worldedit.tool.data-cycler")
public void cycler(Player player, LocalSession session) throws WorldEditException { public void cycler(Player player, LocalSession session) throws WorldEditException {
setTool(player, session, new BlockDataCyler(), "worldedit.tool.data-cycler.equip");
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())));
} }
@Command( @Command(
@ -241,13 +266,10 @@ public class ToolCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
if (range > config.maxSuperPickaxeSize) { 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; return;
} }
setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip");
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())));
} }
@Command( @Command(
@ -257,10 +279,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.deltree") @CommandPermissions("worldedit.tool.deltree")
public void deltree(Player player, LocalSession session) throws WorldEditException { public void deltree(Player player, LocalSession session) throws WorldEditException {
setTool(player, session, new FloatingTreeRemover(), "worldedit.tool.deltree.equip");
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())));
} }
@Command( @Command(
@ -270,9 +289,7 @@ public class ToolCommands {
) )
@CommandPermissions("worldedit.tool.farwand") @CommandPermissions("worldedit.tool.farwand")
public void farwand(Player player, LocalSession session) throws WorldEditException { public void farwand(Player player, LocalSession session) throws WorldEditException {
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); setTool(player, session, new DistanceWand(), "worldedit.tool.farwand.equip");
session.setTool(player, new DistanceWand());
player.printInfo(TranslatableComponent.of("worldedit.tool.farwand.equip", TextComponent.of(itemType.getName())));
} }
@Command( @Command(
@ -286,18 +303,19 @@ public class ToolCommands {
Pattern primary, Pattern primary,
@Arg(desc = "Pattern to set on right-click") @Arg(desc = "Pattern to set on right-click")
Pattern secondary) throws WorldEditException { Pattern secondary) throws WorldEditException {
setTool(player, session, new LongRangeBuildTool(primary, secondary), "worldedit.tool.lrbuild.equip");
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType(); Component primaryName;
session.setTool(player, new LongRangeBuildTool(primary, secondary)); Component secondaryName;
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.equip", TextComponent.of(itemType.getName())));
String primaryName = "pattern";
String secondaryName = "pattern";
if (primary instanceof BlockStateHolder) { if (primary instanceof BlockStateHolder) {
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getName(); primaryName = ((BlockStateHolder<?>) primary).getBlockType().getRichName();
} else {
primaryName = TextComponent.of("pattern");
} }
if (secondary instanceof BlockStateHolder) { 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));
} }
} }

View File

@ -78,7 +78,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
if (targetBlock != null) { if (targetBlock != null) {
pattern = targetBlock; 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; return true;

View File

@ -59,7 +59,7 @@ public class QueryTool implements BlockTool {
TextComponent.Builder builder = TextComponent.builder(); TextComponent.Builder builder = TextComponent.builder();
builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); 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) builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover")))); .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover"))));
final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState());

View File

@ -19,10 +19,12 @@
package com.sk89q.worldedit.command.util; package com.sk89q.worldedit.command.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.inject.InjectedValueAccess;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -45,8 +47,8 @@ public final class SubCommandPermissionCondition extends PermissionCondition {
public static class Generator { public static class Generator {
private final List<Command> subCommands; private final List<Command> subCommands;
public Generator(List<Command> subCommands) { public Generator(Collection<? extends Command> subCommands) {
this.subCommands = subCommands; this.subCommands = ImmutableList.copyOf(subCommands);
} }
public Command.Condition build() { public Command.Condition build() {

View File

@ -83,6 +83,7 @@ import com.sk89q.worldedit.command.WorldEditCommands;
import com.sk89q.worldedit.command.WorldEditCommandsRegistration; import com.sk89q.worldedit.command.WorldEditCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.argument.BooleanConverter; 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.CommaSeparatedValuesConverter;
import com.sk89q.worldedit.command.argument.DirectionConverter; import com.sk89q.worldedit.command.argument.DirectionConverter;
import com.sk89q.worldedit.command.argument.DirectionVectorConverter; 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.EnumConverter;
import com.sk89q.worldedit.command.argument.ExpressionConverter; import com.sk89q.worldedit.command.argument.ExpressionConverter;
import com.sk89q.worldedit.command.argument.FactoryConverter; 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.LocationConverter;
import com.sk89q.worldedit.command.argument.OffsetConverter;
import com.sk89q.worldedit.command.argument.RegionFactoryConverter; import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
import com.sk89q.worldedit.command.argument.RegistryConverter; import com.sk89q.worldedit.command.argument.RegistryConverter;
import com.sk89q.worldedit.command.argument.SideEffectConverter; import com.sk89q.worldedit.command.argument.SideEffectConverter;
@ -250,6 +253,7 @@ public final class PlatformCommandManager {
); );
} }
VectorConverter.register(commandManager); VectorConverter.register(commandManager);
Chunk3dVectorConverter.register(commandManager);
EnumConverter.register(commandManager); EnumConverter.register(commandManager);
RegistryConverter.register(commandManager); RegistryConverter.register(commandManager);
ZonedDateTimeConverter.register(commandManager); ZonedDateTimeConverter.register(commandManager);
@ -260,6 +264,8 @@ public final class PlatformCommandManager {
LocationConverter.register(commandManager); LocationConverter.register(commandManager);
ExpressionConverter.register(commandManager); ExpressionConverter.register(commandManager);
SideEffectConverter.register(commandManager); SideEffectConverter.register(commandManager);
HeightConverter.register(commandManager);
OffsetConverter.register(worldEdit, commandManager);
registerBindings(new ConsumeBindings(worldEdit, this)); registerBindings(new ConsumeBindings(worldEdit, this));
registerBindings(new PrimitiveBindings(worldEdit)); registerBindings(new PrimitiveBindings(worldEdit));
@ -359,7 +365,6 @@ public final class PlatformCommandManager {
} }
private <CI> void registerSubCommands(String name, List<String> aliases, String desc, private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance, Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
@NotNull Consumer<CommandManager> additionalConfig) { @NotNull Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> { commandManager.register(name, cmd -> {
@ -438,7 +443,6 @@ public final class PlatformCommandManager {
"brush", "brush",
Lists.newArrayList("br", "/brush", "/br", "/tool", "tool"), Lists.newArrayList("br", "/brush", "/br", "/tool", "tool"),
"Brushing commands", "Brushing commands",
commandManager,
c -> { c -> {
c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit)); c.accept(BrushCommandsRegistration.builder(), new BrushCommands(worldEdit));
c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit)); c.accept(ToolCommandsRegistration.builder(), new ToolCommands(worldEdit));
@ -486,15 +490,11 @@ public final class PlatformCommandManager {
ClipboardCommandsRegistration.builder(), ClipboardCommandsRegistration.builder(),
new ClipboardCommands() new ClipboardCommands()
); );
this.registration.register( GeneralCommands.register(
registration,
commandManager, commandManager,
GeneralCommandsRegistration.builder(), commandManagerService,
new GeneralCommands(worldEdit) worldEdit
);
this.registration.register(
commandManager,
GenerationCommandsRegistration.builder(),
new GenerationCommands(worldEdit)
); );
HistoryCommands history = new HistoryCommands(worldEdit); HistoryCommands history = new HistoryCommands(worldEdit);
this.registration.register( this.registration.register(

View File

@ -52,14 +52,12 @@ public class CommandUtil {
private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated."); 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() return TextComponent.builder()
.append(DEPRECATION_MARKER) .append(DEPRECATION_MARKER)
.append(" " + reason + ".") .append(" " + reason + ".")
.append(TextComponent.newline()) .append(TextComponent.newline())
.append(TextComponent.of("Use ", TextColor.GOLD, TextDecoration.ITALIC)) .append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true))
.append(newCommand)
.append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC))
.build(); .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, public static Command deprecate(Command command, String reason,
NewCommandGenerator newCommandGenerator) { ReplacementMessageGenerator replacementMessageGenerator) {
Component deprecatedWarning = makeDeprecatedFooter( Component deprecatedWarning = makeDeprecatedFooter(
reason, reason,
newCommandSuggestion(newCommandGenerator, replacementMessageGenerator.getReplacement(
NoInputCommandParameters.builder().build(), command,
command) NoInputCommandParameters.builder().build()
)
); );
return command.toBuilder() return command.toBuilder()
.action(parameters -> .action(parameters ->
deprecatedCommandWarning(parameters, command, reason, newCommandGenerator)) deprecatedCommandWarning(parameters, command, reason, replacementMessageGenerator))
.footer(command.getFooter() .footer(command.getFooter()
.map(existingFooter -> existingFooter .map(existingFooter -> existingFooter
.append(TextComponent.newline()).append(deprecatedWarning)) .append(TextComponent.newline())
.append(deprecatedWarning))
.orElse(deprecatedWarning)) .orElse(deprecatedWarning))
.build(); .build();
} }
@ -139,26 +165,28 @@ public class CommandUtil {
CommandParameters parameters, CommandParameters parameters,
Command command, Command command,
String reason, String reason,
NewCommandGenerator generator ReplacementMessageGenerator generator
) throws Exception { ) throws Exception {
parameters.injectedValue(Key.of(Actor.class)) parameters.injectedValue(Key.of(Actor.class))
.ifPresent(actor -> { .ifPresent(actor ->
Component suggestion = newCommandSuggestion(generator, parameters, command); sendDeprecationMessage(parameters, command, reason, generator, actor)
actor.print(TextComponent.of(reason + ". Please use ", TextColor.GOLD)
.append(suggestion)
.append(TextComponent.of(" instead."))
); );
});
return command.getAction().run(parameters); return command.getAction().run(parameters);
} }
private static Component newCommandSuggestion(NewCommandGenerator generator, private static void sendDeprecationMessage(
CommandParameters parameters, CommandParameters parameters,
Command command) { Command command,
String suggestedCommand = generator.newCommand(command, parameters); String reason,
return TextComponent.of(suggestedCommand) ReplacementMessageGenerator generator,
.decoration(TextDecoration.UNDERLINED, true) Actor actor
.clickEvent(ClickEvent.suggestCommand(suggestedCommand)); ) {
Component replacement = generator.getReplacement(command, parameters);
actor.print(
TextComponent.builder(reason + ". ", TextColor.GOLD)
.append(replacement)
.build()
);
} }
public static Map<String, Command> getSubCommands(Command currentCommand) { public static Map<String, Command> getSubCommands(Command currentCommand) {

View File

@ -36,6 +36,7 @@ import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
@ -62,7 +63,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
} }
private CommandException newCommandException(String message, Throwable cause) { 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 @ExceptionMatch
@ -158,7 +163,13 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
@ExceptionMatch @ExceptionMatch
public void convert(InvalidToolBindException e) throws CommandException { 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 @ExceptionMatch

View File

@ -21,17 +21,19 @@ package com.sk89q.worldedit.util.formatting.component;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Collections2; 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.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent; 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.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import javax.annotation.Nullable; import java.util.stream.Collectors;
public abstract class PaginationBox extends MessageBox { public abstract class PaginationBox extends MessageBox {
@ -138,53 +140,30 @@ public abstract class PaginationBox extends MessageBox {
} }
public static <T> PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection<T> lines, Function<T, Component> adapt) { public static <T> PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection<T> lines, Function<T, Component> 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<String> lines) {
return fromComponents(header, pageCommand, lines.stream()
.map(TextComponent::of)
.collect(Collectors.toList()));
}
public static PaginationBox fromComponents(String header, @Nullable String pageCommand, Collection<Component> lines) {
return new ListPaginationBox(header, pageCommand, lines); return new ListPaginationBox(header, pageCommand, lines);
} }
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List<String> lines) { private static class ListPaginationBox extends PaginationBox {
return fromStrings(header, pageCommand, (Collection) lines); private final List<Component> lines;
}
public static class ListPaginationBox extends PaginationBox { ListPaginationBox(String header, String pageCommand, Collection<Component> lines) {
private final Collection lines;
private int iterIndex;
private Iterator iterator;
public ListPaginationBox(String header, String pageCommand, List<String> lines) {
this(header, pageCommand, (Collection) lines);
}
public ListPaginationBox(String header, String pageCommand, Collection lines) {
super(header, pageCommand); super(header, pageCommand);
this.lines = lines; this.lines = ImmutableList.copyOf(lines);
} }
@Override @Override
public Component getComponent(int number) { public Component getComponent(int number) {
Object obj; return lines.get(number);
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 + "");
} }
@Override @Override

View File

@ -70,7 +70,7 @@ public class SideEffectBox extends PaginationBox {
for (SideEffect.State uiState : SHOWN_VALUES) { for (SideEffect.State uiState : SHOWN_VALUES) {
builder = builder.append(TextComponent.space()); builder = builder.append(TextComponent.space());
builder = builder.append(TranslatableComponent.of(uiState.getDisplayName(), uiState == state ? TextColor.WHITE : TextColor.GRAY) 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 .hoverEvent(HoverEvent.showText(uiState == state
? TranslatableComponent.of("worldedit.sideeffect.box.current") ? TranslatableComponent.of("worldedit.sideeffect.box.current")
: TranslatableComponent.of("worldedit.sideeffect.box.change-to", TranslatableComponent.of(uiState.getDisplayName())) : TranslatableComponent.of("worldedit.sideeffect.box.change-to", TranslatableComponent.of(uiState.getDisplayName()))

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.biome; package com.sk89q.worldedit.world.biome;
import com.sk89q.worldedit.world.registry.BiomeRegistry;
/** /**
* Provides information about a biome. * Provides information about a biome.
* *
@ -32,6 +34,8 @@ public interface BiomeData {
* particular convention. * particular convention.
* *
* @return the biome's name * @return the biome's name
* @deprecated This method does not work on the server.
* Use {@link BiomeRegistry#getRichName(BiomeType)}.
*/ */
@Deprecated @Deprecated
String getName(); String getName();

View File

@ -33,6 +33,7 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.util.concurrency.LazyReference; 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.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
@ -96,6 +97,11 @@ public class BlockType implements Keyed, Pattern {
return this.id; return this.id;
} }
public Component getRichName() {
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getBlockRegistry().getRichName(this);
}
public String getNamespace() { public String getNamespace() {
String id = getId(); String id = getId();
int i = id.indexOf(':'); 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. * Gets the name of this block, or the ID if the name cannot be found.
* *
* @return The name, or ID * @return The name, or ID
* @deprecated The name is now translatable, use {@link #getRichName()}.
*/ */
@Deprecated @Deprecated
public String getName() { public String getName() {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this); return getRichName().toString();
if (name == null) {
return getId();
} else {
return name;
}
} }
/* /*
@ -274,9 +276,7 @@ public class BlockType implements Keyed, Pattern {
/** /**
* Gets the legacy ID. Needed for legacy reasons. * Gets the legacy ID. Needed for legacy reasons.
* *
* <p>
* DO NOT USE THIS. * DO NOT USE THIS.
* </p>
* *
* @return legacy id or 0, if unknown * @return legacy id or 0, if unknown
*/ */
@ -286,11 +286,39 @@ public class BlockType implements Keyed, Pattern {
return combinedId == null ? 0 : combinedId; 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 @Deprecated
public int getLegacyId() { public int getLegacyId() {
return computeLegacy(0); return computeLegacy(0);
} }
/**
* Gets the legacy data. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
* </p>
*
* @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. * The internal index of this type.
* *
@ -336,25 +364,4 @@ public class BlockType implements Keyed, Pattern {
public SingleBlockTypeMask toMask(Extent extent) { public SingleBlockTypeMask toMask(Extent extent) {
return new SingleBlockTypeMask(extent, this); return new SingleBlockTypeMask(extent, this);
} }
/**
* Gets the legacy data. Needed for legacy reasons.
*
* <p>
* DO NOT USE THIS.
* </p>
*
* @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;
}
} }

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry; 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.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -29,11 +30,21 @@ import javax.annotation.Nullable;
*/ */
public interface BiomeRegistry { 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. * Get data about a biome.
* *
* @param biome the biome * @param biome the biome
* @return a data object or null if information is not known * @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 @Deprecated
@Nullable @Nullable

View File

@ -20,29 +20,41 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.state.Property; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.OptionalInt; import java.util.OptionalInt;
import javax.annotation.Nullable;
/** /**
* Provides information on blocks and provides methods to create them. * Provides information on blocks and provides methods to create them.
*/ */
public interface BlockRegistry { 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. * Gets the name for the given block.
* *
* @param blockType the block * @param blockType the block
* @return The name, or null if it's unknown * @return The name, or null if it's unknown
* @deprecated Names are now translatable, use {@link #getRichName(BlockType)}.
*/ */
@Deprecated @Deprecated
@Nullable @Nullable
String getName(BlockType blockType); default String getName(BlockType blockType) {
return getRichName(blockType).toString();
}
/** /**
* Get the material for the given block. * Get the material for the given block.

View File

@ -20,6 +20,10 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.state.Property; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
@ -34,11 +38,19 @@ import javax.annotation.Nullable;
*/ */
public class BundledBlockRegistry implements BlockRegistry { public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override @Override
public String getName(BlockType blockType) { public Component getRichName(BlockType blockType) {
BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId()); 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 @Nullable

View File

@ -23,9 +23,9 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import javax.annotation.Nullable;
public interface ItemRegistry { public interface ItemRegistry {

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.world.registry; 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.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -35,6 +38,14 @@ public class NullBiomeRegistry implements BiomeRegistry {
public NullBiomeRegistry() { public NullBiomeRegistry() {
} }
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(
TranslationManager.makeTranslationKey("biome", biomeType.getId())
);
}
@Deprecated
@Nullable @Nullable
@Override @Override
public BiomeData getData(BiomeType biome) { public BiomeData getData(BiomeType biome) {

View File

@ -212,13 +212,13 @@
"worldedit.timeout.set": "Timeout time set to {0}ms.", "worldedit.timeout.set": "Timeout time set to {0}ms.",
"worldedit.timeout.return-to-default": " (Use //timeout to go back to the default.)", "worldedit.timeout.return-to-default": " (Use //timeout to go back to the default.)",
"worldedit.fast.disabled": "Fast mode disabled.", "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.disabled.already": "Fast mode already disabled.",
"worldedit.fast.enabled.already": "Fast mode already enabled.", "worldedit.fast.enabled.already": "Fast mode already enabled.",
"worldedit.fast.sideeffect.set": "Side effect \"{0}\" set to {1}", "worldedit.perf.sideeffect.set": "Side effect \"{0}\" set to {1}",
"worldedit.fast.sideeffect.get": "Side effect \"{0}\" is set to {1}", "worldedit.perf.sideeffect.get": "Side effect \"{0}\" is set to {1}",
"worldedit.fast.sideeffect.already-set": "Side effect \"{0}\" is already {1}", "worldedit.perf.sideeffect.already-set": "Side effect \"{0}\" is already {1}",
"worldedit.fast.sideeffect.set-all": "All side effects set to {0}", "worldedit.perf.sideeffect.set-all": "All side effects set to {0}",
"worldedit.reorder.current": "The reorder mode is {0}", "worldedit.reorder.current": "The reorder mode is {0}",
"worldedit.reorder.set": "The reorder mode is now {0}", "worldedit.reorder.set": "The reorder mode is now {0}",
"worldedit.gmask.disabled": "Global mask disabled.", "worldedit.gmask.disabled": "Global mask disabled.",

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.fabric; 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.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
*/ */
class FabricBiomeRegistry implements BiomeRegistry { class FabricBiomeRegistry implements BiomeRegistry {
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(FabricAdapter.adapt(biomeType).getTranslationKey());
}
@Deprecated
@Override @Override
public BiomeData getData(BiomeType biome) { public BiomeData getData(BiomeType biome) {
return new FabricBiomeData(FabricAdapter.adapt(biome)); return new FabricBiomeData(FabricAdapter.adapt(biome));
@ -37,6 +45,7 @@ class FabricBiomeRegistry implements BiomeRegistry {
/** /**
* Cached biome data information. * Cached biome data information.
*/ */
@Deprecated
private static class FabricBiomeData implements BiomeData { private static class FabricBiomeData implements BiomeData {
private final Biome biome; private final Biome biome;
@ -49,6 +58,7 @@ class FabricBiomeRegistry implements BiomeRegistry {
this.biome = biome; this.biome = biome;
} }
@SuppressWarnings("deprecation")
@Override @Override
public String getName() { public String getName() {
return biome.getName().asFormattedString(); return biome.getName().asFormattedString();

View File

@ -20,17 +20,15 @@
package com.sk89q.worldedit.fabric; package com.sk89q.worldedit.fabric;
import com.sk89q.worldedit.registry.state.Property; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockRegistry; 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.Block;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,15 +39,9 @@ public class FabricBlockRegistry extends BundledBlockRegistry {
private Map<Material, FabricBlockMaterial> materialMap = new HashMap<>(); private Map<Material, FabricBlockMaterial> materialMap = new HashMap<>();
@Nullable
@Override @Override
public String getName(BlockType blockType) { public Component getRichName(BlockType blockType) {
Block block = FabricAdapter.adapt(blockType); return TranslatableComponent.of(FabricAdapter.adapt(blockType).getTranslationKey());
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return block.getName().asFormattedString();
} else {
return super.getName(blockType);
}
} }
@Override @Override

View File

@ -19,24 +19,26 @@
package com.sk89q.worldedit.fabric; 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.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry; 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 { public class FabricItemRegistry extends BundledItemRegistry {
@Nullable
@Override @Override
public String getName(ItemType itemType) { public Component getRichName(ItemType itemType) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { return TranslatableComponent.of(
final Item item = FabricAdapter.adapt(itemType); FabricAdapter.adapt(itemType).getTranslationKey()
return I18n.translate(item.getTranslationKey()); );
} }
return super.getName(itemType);
@Override
public Component getRichName(BaseItemStack itemStack) {
return TranslatableComponent.of(
FabricAdapter.adapt(itemStack).getTranslationKey()
);
} }
} }

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.forge; 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.BiomeData;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
*/ */
class ForgeBiomeRegistry implements BiomeRegistry { class ForgeBiomeRegistry implements BiomeRegistry {
@Override
public Component getRichName(BiomeType biomeType) {
return TranslatableComponent.of(ForgeAdapter.adapt(biomeType).getTranslationKey());
}
@Deprecated
@Override @Override
public BiomeData getData(BiomeType biome) { public BiomeData getData(BiomeType biome) {
return new ForgeBiomeData(ForgeAdapter.adapt(biome)); return new ForgeBiomeData(ForgeAdapter.adapt(biome));
@ -37,6 +45,7 @@ class ForgeBiomeRegistry implements BiomeRegistry {
/** /**
* Cached biome data information. * Cached biome data information.
*/ */
@Deprecated
private static class ForgeBiomeData implements BiomeData { private static class ForgeBiomeData implements BiomeData {
private final Biome biome; private final Biome biome;
@ -49,6 +58,7 @@ class ForgeBiomeRegistry implements BiomeRegistry {
this.biome = biome; this.biome = biome;
} }
@SuppressWarnings("deprecation")
@Override @Override
public String getName() { public String getName() {
return biome.getDisplayName().getString(); return biome.getDisplayName().getString();

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.registry.state.Property; 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.BlockState;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial; 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.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.state.IProperty; import net.minecraft.state.IProperty;
import net.minecraftforge.fml.loading.FMLLoader;
import javax.annotation.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -40,15 +40,9 @@ public class ForgeBlockRegistry extends BundledBlockRegistry {
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>(); private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
@Nullable
@Override @Override
public String getName(BlockType blockType) { public Component getRichName(BlockType blockType) {
Block block = ForgeAdapter.adapt(blockType); return TranslatableComponent.of(ForgeAdapter.adapt(blockType).getTranslationKey());
if (block != null && FMLLoader.getDist().isClient()) {
return block.getNameTextComponent().getFormattedText();
} else {
return super.getName(blockType);
}
} }
@Override @Override

View File

@ -19,33 +19,26 @@
package com.sk89q.worldedit.forge; package com.sk89q.worldedit.forge;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.registry.ItemRegistry; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry; 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 { public class ForgeItemRegistry extends BundledItemRegistry {
@Nullable
@Override @Override
public String getName(ItemType itemType) { public Component getRichName(ItemType itemType) {
if (FMLLoader.getDist().isClient()) { return TranslatableComponent.of(
final Item item = RegistryManager.ACTIVE.getRegistry(Item.class) ForgeAdapter.adapt(itemType).getTranslationKey()
.getValue(ResourceLocation.tryCreate(itemType.getId())); );
if (item != null) {
return I18n.format(item.getTranslationKey());
} }
@Override
public Component getRichName(BaseItemStack itemStack) {
return TranslatableComponent.of(
ForgeAdapter.adapt(itemStack).getTranslationKey()
);
} }
return super.getName(itemType);
}
} }

View File

@ -19,6 +19,9 @@
package com.sk89q.worldedit.sponge; 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.biome.BiomeData;
import com.sk89q.worldedit.world.registry.BiomeRegistry; import com.sk89q.worldedit.world.registry.BiomeRegistry;
import org.spongepowered.api.world.biome.BiomeType; import org.spongepowered.api.world.biome.BiomeType;
@ -30,12 +33,21 @@ import javax.annotation.Nullable;
*/ */
class SpongeBiomeRegistry implements BiomeRegistry { 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 @Nullable
@Override @Override
public BiomeData getData(com.sk89q.worldedit.world.biome.BiomeType biome) { public BiomeData getData(com.sk89q.worldedit.world.biome.BiomeType biome) {
return new SpongeBiomeData(SpongeAdapter.adapt(biome)); return new SpongeBiomeData(SpongeAdapter.adapt(biome));
} }
@Deprecated
private static class SpongeBiomeData implements BiomeData { private static class SpongeBiomeData implements BiomeData {
private final BiomeType biome; private final BiomeType biome;
@ -48,6 +60,7 @@ class SpongeBiomeRegistry implements BiomeRegistry {
this.biome = biome; this.biome = biome;
} }
@SuppressWarnings("deprecation")
@Override @Override
public String getName() { public String getName() {
return biome.getName(); return biome.getName();