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
This commit is contained in:
1 parent
2f4c44f80c
commit
cfd26253b6
37 files changed
+515
-268
No files matched your search
@@ -25,6 +25,11 @@ fun Project.applyLibrariesConfiguration() {
|
||||
|
||||
group = "${rootProject.group}.worldedit-libs"
|
||||
|
||||
val relocations = mapOf(
|
||||
"net.kyori.text" to "com.sk89q.worldedit.util.formatting.text",
|
||||
"net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori"
|
||||
)
|
||||
|
||||
tasks.register<ShadowJar>("jar") {
|
||||
configurations = listOf(project.configurations["shade"])
|
||||
archiveClassifier.set("")
|
||||
@@ -36,7 +41,9 @@ fun Project.applyLibrariesConfiguration() {
|
||||
exclude(dependency("org.slf4j:slf4j-api"))
|
||||
}
|
||||
|
||||
relocate("net.kyori.text", "com.sk89q.worldedit.util.formatting.text")
|
||||
relocations.forEach { (from, to) ->
|
||||
relocate(from, to)
|
||||
}
|
||||
}
|
||||
val altConfigFiles = { artifactType: String ->
|
||||
val deps = configurations["shade"].incoming.dependencies
|
||||
@@ -61,13 +68,15 @@ fun Project.applyLibrariesConfiguration() {
|
||||
from({
|
||||
altConfigFiles("sources")
|
||||
})
|
||||
val filePattern = Regex("(.*)net/kyori/text((?:/|$).*)")
|
||||
val textPattern = Regex("net\\.kyori\\.text")
|
||||
eachFile {
|
||||
filter {
|
||||
it.replaceFirst(textPattern, "com.sk89q.worldedit.util.formatting.text")
|
||||
relocations.forEach { (from, to) ->
|
||||
val filePattern = Regex("(.*)${from.replace('.', '/')}((?:/|$).*)")
|
||||
val textPattern = Regex.fromLiteral(from)
|
||||
eachFile {
|
||||
filter {
|
||||
it.replaceFirst(textPattern, to)
|
||||
}
|
||||
path = path.replaceFirst(filePattern, "$1${to.replace('.', '/')}$2")
|
||||
}
|
||||
path = path.replaceFirst(filePattern, "$1com/sk89q/worldedit/util/formatting/text$2")
|
||||
}
|
||||
archiveClassifier.set("sources")
|
||||
}
|
||||
@@ -96,4 +105,4 @@ fun Project.applyLibrariesConfiguration() {
|
||||
}
|
||||
|
||||
applyCommonArtifactoryConfig()
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import org.gradle.api.Project
|
||||
|
||||
object Versions {
|
||||
const val TEXT = "3.0.1"
|
||||
const val TEXT_EXTRAS = "3.0.2"
|
||||
const val TEXT = "3.0.3"
|
||||
const val TEXT_EXTRAS = "3.0.3"
|
||||
const val PISTON = "0.5.2"
|
||||
const val AUTO_VALUE = "1.6.5"
|
||||
const val AUTO_VALUE = "1.7"
|
||||
const val JUNIT = "5.5.0"
|
||||
const val MOCKITO = "3.0.0"
|
||||
const val MOCKITO = "3.3.3"
|
||||
const val LOGBACK = "1.2.3"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
@@ -34,6 +37,14 @@ class BukkitBiomeRegistry implements BiomeRegistry {
|
||||
BukkitBiomeRegistry() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRichName(BiomeType biomeType) {
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("biome", biomeType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Override
|
||||
public BiomeData getData(BiomeType biome) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@@ -36,6 +37,14 @@ import javax.annotation.Nullable;
|
||||
public class BukkitBlockRegistry extends BundledBlockRegistry {
|
||||
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
|
||||
|
||||
@Override
|
||||
public Component getRichName(BlockType blockType) {
|
||||
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
|
||||
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getRichBlockName(blockType);
|
||||
}
|
||||
return super.getRichName(blockType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockMaterial getMaterial(BlockType blockType) {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.world.registry.BlockCategoryRegistry;
|
||||
import com.sk89q.worldedit.world.registry.BlockRegistry;
|
||||
import com.sk89q.worldedit.world.registry.BundledRegistries;
|
||||
import com.sk89q.worldedit.world.registry.ItemCategoryRegistry;
|
||||
import com.sk89q.worldedit.world.registry.ItemRegistry;
|
||||
|
||||
/**
|
||||
* World data for the Bukkit platform.
|
||||
@@ -33,6 +34,7 @@ class BukkitRegistries extends BundledRegistries {
|
||||
private static final BukkitRegistries INSTANCE = new BukkitRegistries();
|
||||
private final BlockRegistry blockRegistry = new BukkitBlockRegistry();
|
||||
private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry();
|
||||
private final ItemRegistry itemRegistry = new BukkitItemRegistry();
|
||||
private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry();
|
||||
private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry();
|
||||
|
||||
@@ -52,6 +54,11 @@ class BukkitRegistries extends BundledRegistries {
|
||||
return biomeRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemRegistry getItemRegistry() {
|
||||
return itemRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCategoryRegistry getBlockCategoryRegistry() {
|
||||
return blockCategoryRegistry;
|
||||
|
||||
+26
@@ -30,10 +30,12 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.SideEffect;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.DataFixer;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -114,6 +116,30 @@ public interface BukkitImplAdapter {
|
||||
@Nullable
|
||||
Entity createEntity(Location location, BaseEntity state);
|
||||
|
||||
/**
|
||||
* Gets the name for the given block.
|
||||
*
|
||||
* @param blockType the block
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichBlockName(BlockType blockType);
|
||||
|
||||
/**
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichItemName(ItemType itemType);
|
||||
|
||||
/**
|
||||
* Gets the name for the given item stack.
|
||||
*
|
||||
* @param itemStack the item stack
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichItemName(BaseItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get a map of {@code string -> property}.
|
||||
*
|
||||
|
||||
Binary file not shown.
@@ -559,15 +559,17 @@ public final class WorldEdit {
|
||||
Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks();
|
||||
|
||||
if (!missingBlocks.isEmpty()) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
TextComponent.Builder str = TextComponent.builder();
|
||||
str.append("Missing these blocks: ");
|
||||
int size = missingBlocks.size();
|
||||
int i = 0;
|
||||
|
||||
for (Map.Entry<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;
|
||||
|
||||
@@ -576,7 +578,7 @@ public final class WorldEdit {
|
||||
}
|
||||
}
|
||||
|
||||
actor.printError(str.toString());
|
||||
actor.printError(str.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,83 +1,91 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
/**
|
||||
* Represents a stack of BaseItems.
|
||||
*
|
||||
* <p>This class may be removed in the future.</p>
|
||||
*/
|
||||
public class BaseItemStack extends BaseItem {
|
||||
|
||||
private int amount = 1;
|
||||
|
||||
/**
|
||||
* Construct the object with default stack size of one, with damage value of 0.
|
||||
*
|
||||
* @param itemType The item type
|
||||
*/
|
||||
public BaseItemStack(ItemType itemType) {
|
||||
super(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param itemType The item type
|
||||
* @param amount amount in the stack
|
||||
*/
|
||||
public BaseItemStack(ItemType itemType, int amount) {
|
||||
super(itemType);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id The item type
|
||||
* @param tag Tag value
|
||||
* @param amount amount in the stack
|
||||
*/
|
||||
public BaseItemStack(ItemType id, CompoundTag tag, int amount) {
|
||||
super(id, tag);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of items in the stack.
|
||||
*
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of items in the stack.
|
||||
*
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
/**
|
||||
* Represents a stack of BaseItems.
|
||||
*
|
||||
* <p>This class may be removed in the future.</p>
|
||||
*/
|
||||
public class BaseItemStack extends BaseItem {
|
||||
|
||||
private int amount = 1;
|
||||
|
||||
/**
|
||||
* Construct the object with default stack size of one, with damage value of 0.
|
||||
*
|
||||
* @param itemType The item type
|
||||
*/
|
||||
public BaseItemStack(ItemType itemType) {
|
||||
super(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param itemType The item type
|
||||
* @param amount amount in the stack
|
||||
*/
|
||||
public BaseItemStack(ItemType itemType, int amount) {
|
||||
super(itemType);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id The item type
|
||||
* @param tag Tag value
|
||||
* @param amount amount in the stack
|
||||
*/
|
||||
public BaseItemStack(ItemType id, CompoundTag tag, int amount) {
|
||||
super(id, tag);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of items in the stack.
|
||||
*
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of items in the stack.
|
||||
*
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Component getRichName() {
|
||||
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
|
||||
.getRegistries().getItemRegistry().getRichName(this);
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,6 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
@@ -92,18 +91,14 @@ public class BiomeCommands {
|
||||
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
|
||||
PaginationBox paginationBox = PaginationBox.fromStrings("Available Biomes", "/biomelist -p %page%",
|
||||
PaginationBox paginationBox = PaginationBox.fromComponents("Available Biomes", "/biomelist -p %page%",
|
||||
BiomeType.REGISTRY.values().stream()
|
||||
.map(biomeType -> {
|
||||
String id = biomeType.getId();
|
||||
final BiomeData data = biomeRegistry.getData(biomeType);
|
||||
if (data != null) {
|
||||
String name = data.getName();
|
||||
return id + " (" + name + ")";
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
})
|
||||
.map(biomeType -> TextComponent.builder()
|
||||
.append(biomeType.getId())
|
||||
.append(" (")
|
||||
.append(biomeRegistry.getRichName(biomeType))
|
||||
.append(")")
|
||||
.build())
|
||||
.collect(Collectors.toList()));
|
||||
return paginationBox.create(page);
|
||||
}, (Component) null);
|
||||
@@ -158,14 +153,11 @@ public class BiomeCommands {
|
||||
messageKey = "worldedit.biomeinfo.selection";
|
||||
}
|
||||
|
||||
List<Component> components = biomes.stream().map(biome -> {
|
||||
BiomeData data = biomeRegistry.getData(biome);
|
||||
if (data != null) {
|
||||
return TextComponent.of(data.getName()).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())));
|
||||
} else {
|
||||
return TextComponent.of(biome.getId());
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
List<Component> components = biomes.stream().map(biome ->
|
||||
biomeRegistry.getRichName(biome).hoverEvent(
|
||||
HoverEvent.showText(TextComponent.of(biome.getId()))
|
||||
)
|
||||
).collect(Collectors.toList());
|
||||
player.printInfo(TranslatableComponent.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@@ -58,6 +56,8 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* General WorldEdit commands.
|
||||
*/
|
||||
@@ -350,7 +350,7 @@ public class GeneralCommands {
|
||||
@Override
|
||||
public Component call() throws Exception {
|
||||
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 nameMatch = search.toLowerCase(Locale.ROOT);
|
||||
for (ItemType searchType : ItemType.REGISTRY) {
|
||||
@@ -362,15 +362,17 @@ public class GeneralCommands {
|
||||
continue;
|
||||
}
|
||||
final String id = searchType.getId();
|
||||
String name = searchType.getName();
|
||||
final boolean hasName = !name.equals(id);
|
||||
name = name.toLowerCase(Locale.ROOT);
|
||||
if (id.contains(idMatch) || (hasName && name.contains(nameMatch))) {
|
||||
results.put(id, name + (hasName ? " (" + id + ")" : ""));
|
||||
if (id.contains(idMatch)) {
|
||||
Component name = searchType.getRichName();
|
||||
results.put(id, TextComponent.builder()
|
||||
.append(name)
|
||||
.append(" (" + id + ")")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
List<String> list = new ArrayList<>(results.values());
|
||||
return PaginationBox.fromStrings("Search results for '" + search + "'", command, list).create(page);
|
||||
List<Component> list = new ArrayList<>(results.values());
|
||||
return PaginationBox.fromComponents("Search results for '" + search + "'", command, list)
|
||||
.create(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -675,7 +675,7 @@ public class SelectionCommands {
|
||||
|
||||
final BlockState state = c.getID();
|
||||
final BlockType blockType = state.getBlockType();
|
||||
TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE);
|
||||
Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE);
|
||||
TextComponent toolTip;
|
||||
if (separateStates && state != blockType.getDefaultState()) {
|
||||
toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.command.tool.BlockDataCyler;
|
||||
import com.sk89q.worldedit.command.tool.BlockReplacer;
|
||||
import com.sk89q.worldedit.command.tool.DistanceWand;
|
||||
@@ -34,6 +35,7 @@ import com.sk89q.worldedit.command.tool.LongRangeBuildTool;
|
||||
import com.sk89q.worldedit.command.tool.NavigationWand;
|
||||
import com.sk89q.worldedit.command.tool.QueryTool;
|
||||
import com.sk89q.worldedit.command.tool.SelectionWand;
|
||||
import com.sk89q.worldedit.command.tool.Tool;
|
||||
import com.sk89q.worldedit.command.tool.TreePlanter;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
@@ -43,10 +45,10 @@ import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
||||
import com.sk89q.worldedit.internal.command.CommandUtil;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.CommandManagerService;
|
||||
import org.enginehub.piston.CommandMetadata;
|
||||
@@ -127,6 +129,13 @@ public class ToolCommands {
|
||||
player.printInfo(TranslatableComponent.of(isBrush ? "worldedit.brush.none.equip" : "worldedit.tool.none.equip"));
|
||||
}
|
||||
|
||||
private static void setTool(Player player, LocalSession session, Tool tool,
|
||||
String translationKey) throws InvalidToolBindException {
|
||||
BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
session.setTool(itemStack.getType(), tool);
|
||||
player.printInfo(TranslatableComponent.of(translationKey, itemStack.getRichName()));
|
||||
}
|
||||
|
||||
private final WorldEdit we;
|
||||
|
||||
public ToolCommands(WorldEdit we) {
|
||||
@@ -149,10 +158,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.setwand")
|
||||
public void selwand(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new SelectionWand());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.selwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new SelectionWand(), "worldedit.tool.selwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -162,10 +168,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.setwand")
|
||||
public void navwand(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new NavigationWand());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.navwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new NavigationWand(), "worldedit.tool.navwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -174,10 +177,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.info")
|
||||
public void info(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new QueryTool());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.info.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new QueryTool(), "worldedit.tool.info.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -188,10 +188,7 @@ public class ToolCommands {
|
||||
public void tree(Player player, LocalSession session,
|
||||
@Arg(desc = "Type of tree to generate", def = "tree")
|
||||
TreeGenerator.TreeType type) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new TreePlanter(type));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.tree.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new TreePlanter(type), "worldedit.tool.tree.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -202,10 +199,7 @@ public class ToolCommands {
|
||||
public void repl(Player player, LocalSession session,
|
||||
@Arg(desc = "The pattern of blocks to place")
|
||||
Pattern pattern) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new BlockReplacer(pattern));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new BlockReplacer(pattern), "worldedit.tool.repl.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -214,10 +208,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.data-cycler")
|
||||
public void cycler(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new BlockDataCyler());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.data-cycler.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new BlockDataCyler(), "worldedit.tool.data-cycler.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -238,10 +229,7 @@ public class ToolCommands {
|
||||
player.printError(TranslatableComponent.of("worldedit.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize)));
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new FloodFillTool(range, pattern));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.floodfill.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -250,10 +238,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.deltree")
|
||||
public void deltree(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new FloatingTreeRemover());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.deltree.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new FloatingTreeRemover(), "worldedit.tool.deltree.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -262,10 +247,7 @@ public class ToolCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.tool.farwand")
|
||||
public void farwand(Player player, LocalSession session) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new DistanceWand());
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.farwand.equip", TextComponent.of(itemType.getName())));
|
||||
setTool(player, session, new DistanceWand(), "worldedit.tool.farwand.equip");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -279,18 +261,19 @@ public class ToolCommands {
|
||||
Pattern primary,
|
||||
@Arg(desc = "Pattern to set on right-click")
|
||||
Pattern secondary) throws WorldEditException {
|
||||
|
||||
final ItemType itemType = player.getItemInHand(HandSide.MAIN_HAND).getType();
|
||||
session.setTool(itemType, new LongRangeBuildTool(primary, secondary));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.equip", TextComponent.of(itemType.getName())));
|
||||
String primaryName = "pattern";
|
||||
String secondaryName = "pattern";
|
||||
setTool(player, session, new LongRangeBuildTool(primary, secondary), "worldedit.tool.lrbuild.equip");
|
||||
Component primaryName;
|
||||
Component secondaryName;
|
||||
if (primary instanceof BlockStateHolder) {
|
||||
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getName();
|
||||
primaryName = ((BlockStateHolder<?>) primary).getBlockType().getRichName();
|
||||
} else {
|
||||
primaryName = TextComponent.of("pattern");
|
||||
}
|
||||
if (secondary instanceof BlockStateHolder) {
|
||||
secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getName();
|
||||
secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getRichName();
|
||||
} else {
|
||||
secondaryName = TextComponent.of("pattern");
|
||||
}
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", TextComponent.of(primaryName), TextComponent.of(secondaryName)));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.lrbuild.set", primaryName, secondaryName));
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
|
||||
if (targetBlock != null) {
|
||||
pattern = targetBlock;
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", TextComponent.of(targetBlock.getBlockType().getName())));
|
||||
player.printInfo(TranslatableComponent.of("worldedit.tool.repl.switched", targetBlock.getBlockType().getRichName()));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class QueryTool implements BlockTool {
|
||||
|
||||
TextComponent.Builder builder = TextComponent.builder();
|
||||
builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE));
|
||||
builder.append(TextComponent.of(block.getBlockType().getName(), TextColor.YELLOW));
|
||||
builder.append(block.getBlockType().getRichName().color(TextColor.YELLOW));
|
||||
builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY)
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover"))));
|
||||
final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState());
|
||||
|
||||
+13
-2
@@ -36,6 +36,7 @@ import com.sk89q.worldedit.command.InsufficientArgumentsException;
|
||||
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
|
||||
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
|
||||
@@ -62,7 +63,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
|
||||
}
|
||||
|
||||
private CommandException newCommandException(String message, Throwable cause) {
|
||||
return new CommandException(TextComponent.of(String.valueOf(message)), cause, ImmutableList.of());
|
||||
return newCommandException(TextComponent.of(String.valueOf(message)), cause);
|
||||
}
|
||||
|
||||
private CommandException newCommandException(Component message, Throwable cause) {
|
||||
return new CommandException(message, cause, ImmutableList.of());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
@@ -158,7 +163,13 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InvalidToolBindException e) throws CommandException {
|
||||
throw newCommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage(), e);
|
||||
throw newCommandException(
|
||||
TextComponent.builder("Can't bind tool to ")
|
||||
.append(e.getItemType().getRichName())
|
||||
.append(": " + e.getMessage())
|
||||
.build(),
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
|
||||
+10
-3
@@ -27,6 +27,7 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class PaginationBox extends MessageBox {
|
||||
|
||||
@@ -129,20 +130,26 @@ public abstract class PaginationBox extends MessageBox {
|
||||
}
|
||||
|
||||
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, List<String> lines) {
|
||||
return fromComponents(header, pageCommand, lines.stream()
|
||||
.map(TextComponent::of)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public static PaginationBox fromComponents(String header, @Nullable String pageCommand, List<Component> lines) {
|
||||
return new ListPaginationBox(header, pageCommand, lines);
|
||||
}
|
||||
|
||||
private static class ListPaginationBox extends PaginationBox {
|
||||
private final List<String> lines;
|
||||
private final List<Component> lines;
|
||||
|
||||
ListPaginationBox(String header, String pageCommand, List<String> lines) {
|
||||
ListPaginationBox(String header, String pageCommand, List<Component> lines) {
|
||||
super(header, pageCommand);
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getComponent(int number) {
|
||||
return TextComponent.of(lines.get(number));
|
||||
return lines.get(number);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
-3
@@ -25,7 +25,7 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.renderer.FriendlyComponentRenderer;
|
||||
import com.sk89q.worldedit.util.formatting.text.renderer.TranslatableComponentRenderer;
|
||||
import com.sk89q.worldedit.util.io.ResourceLoader;
|
||||
|
||||
import java.io.File;
|
||||
@@ -63,9 +63,22 @@ public class TranslationManager {
|
||||
private static final Gson gson = new GsonBuilder().create();
|
||||
private static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>() {}.getType();
|
||||
|
||||
public static String makeTranslationKey(String type, String id) {
|
||||
String[] parts = id.split(":", 2);
|
||||
return type + '.' + parts[0] + '.' + parts[1].replace('/', '.');
|
||||
}
|
||||
|
||||
private final Map<Locale, Map<String, String>> translationMap = new ConcurrentHashMap<>();
|
||||
private final FriendlyComponentRenderer<Locale> friendlyComponentRenderer = FriendlyComponentRenderer.from(
|
||||
(locale, key) -> new MessageFormat(getTranslationMap(locale).getOrDefault(key, key), locale));
|
||||
private final TranslatableComponentRenderer<Locale> friendlyComponentRenderer = TranslatableComponentRenderer.from(
|
||||
(locale, key) -> {
|
||||
String translation = getTranslationMap(locale).get(key);
|
||||
if (translation == null) {
|
||||
// let it pass through (for e.g. MC messages)
|
||||
return null;
|
||||
}
|
||||
return new MessageFormat(translation, locale);
|
||||
}
|
||||
);
|
||||
private Locale defaultLocale = Locale.ENGLISH;
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
@@ -19,9 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.world.biome;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
|
||||
/**
|
||||
* Provides information about a biome.
|
||||
*
|
||||
* @deprecated This no longer returns useful information.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface BiomeData {
|
||||
|
||||
/**
|
||||
@@ -29,7 +34,10 @@ public interface BiomeData {
|
||||
* particular convention.
|
||||
*
|
||||
* @return the biome's name
|
||||
* @deprecated This method does not work on the server.
|
||||
* Use {@link BiomeRegistry#getRichName(BiomeType)}.
|
||||
*/
|
||||
@Deprecated
|
||||
String getName();
|
||||
|
||||
}
|
||||
@@ -28,7 +28,10 @@ import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Returns the name of a biome using a given {@code BiomeRegistry}.
|
||||
*
|
||||
* @deprecated for removal, appears to be unused
|
||||
*/
|
||||
@Deprecated
|
||||
class BiomeName implements Function<BiomeType, String> {
|
||||
|
||||
private final BiomeRegistry registry;
|
||||
|
||||
@@ -35,7 +35,10 @@ import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Utility methods related to biomes.
|
||||
*
|
||||
* @deprecated Only method is being deprecated for removal.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Biomes {
|
||||
|
||||
private Biomes() {
|
||||
@@ -48,7 +51,9 @@ public final class Biomes {
|
||||
* @param name the name to test
|
||||
* @param registry a biome registry
|
||||
* @return a biome or null
|
||||
* @deprecated This uses the outdated name system. Find names by comparing with their ID instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static BiomeType findBiomeByName(Collection<BiomeType> biomes, String name, BiomeRegistry registry) {
|
||||
checkNotNull(biomes);
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
@@ -97,18 +98,20 @@ public class BlockType implements Keyed {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Component getRichName() {
|
||||
return WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
|
||||
.getRegistries().getBlockRegistry().getRichName(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this block, or the ID if the name cannot be found.
|
||||
*
|
||||
* @return The name, or ID
|
||||
* @deprecated The name is now translatable, use {@link #getRichName()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getName() {
|
||||
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this);
|
||||
if (name == null) {
|
||||
return getId();
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
return getRichName().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,9 +24,9 @@ import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.registry.Keyed;
|
||||
import com.sk89q.worldedit.registry.NamespacedRegistry;
|
||||
import com.sk89q.worldedit.util.concurrency.LazyReference;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.ItemMaterial;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -37,6 +37,11 @@ public class ItemType implements Keyed {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private final LazyReference<Component> richName =
|
||||
LazyReference.from(() ->
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
|
||||
.getRegistries().getItemRegistry().getRichName(this)
|
||||
);
|
||||
private final LazyReference<ItemMaterial> itemMaterial
|
||||
= LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getMaterial(this));
|
||||
@@ -54,11 +59,17 @@ public class ItemType implements Keyed {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Component getRichName() {
|
||||
return richName.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this item, or the ID if the name cannot be found.
|
||||
*
|
||||
* @return The name, or ID
|
||||
* @deprecated Names are translatable now, use {@link #getRichName()}.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
|
||||
@@ -29,12 +30,23 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public interface BiomeRegistry {
|
||||
|
||||
/**
|
||||
* Get the name of the biome, usually as a translatable component.
|
||||
*
|
||||
* @param biomeType the biome type
|
||||
* @return the name of the biome
|
||||
*/
|
||||
Component getRichName(BiomeType biomeType);
|
||||
|
||||
/**
|
||||
* Get data about a biome.
|
||||
*
|
||||
* @param biome the biome
|
||||
* @return a data object or null if information is not known
|
||||
* @deprecated This method no longer returns any useful information.
|
||||
* Use {@link #getRichName(BiomeType)} for the name of the biome.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
BiomeData getData(BiomeType biome);
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Provides information on blocks and provides methods to create them.
|
||||
*/
|
||||
@@ -37,10 +37,22 @@ public interface BlockRegistry {
|
||||
* Gets the name for the given block.
|
||||
*
|
||||
* @param blockType the block
|
||||
* @return The name, or null if it's unknown
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichName(BlockType blockType);
|
||||
|
||||
/**
|
||||
* Gets the name for the given block.
|
||||
*
|
||||
* @param blockType the block
|
||||
* @return The name, or null if it's unknown
|
||||
* @deprecated Names are now translatable, use {@link #getRichName(BlockType)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String getName(BlockType blockType);
|
||||
default String getName(BlockType blockType) {
|
||||
return getRichName(blockType).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the material for the given block.
|
||||
|
||||
+15
-3
@@ -20,6 +20,10 @@
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
@@ -35,11 +39,19 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class BundledBlockRegistry implements BlockRegistry {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(BlockType blockType) {
|
||||
public Component getRichName(BlockType blockType) {
|
||||
BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId());
|
||||
return blockEntry != null ? blockEntry.localizedName : null;
|
||||
if (blockEntry != null) {
|
||||
// This is more likely to be "right", but not translated
|
||||
// Some vanilla MC blocks have overrides so we need this name here
|
||||
// Most platforms should be overriding this anyways, so it likely doesn't matter
|
||||
// too much!
|
||||
return TextComponent.of(blockEntry.localizedName);
|
||||
}
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("block", blockType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+14
-11
@@ -19,6 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -33,20 +37,19 @@ public class BundledItemRegistry implements ItemRegistry {
|
||||
return BundledItemData.getInstance().findById(itemType.getId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(ItemType itemType) {
|
||||
public Component getRichName(ItemType itemType) {
|
||||
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
|
||||
if (itemEntry != null) {
|
||||
String localized = itemEntry.localizedName;
|
||||
if (localized.equals("Air")) {
|
||||
String id = itemType.getId();
|
||||
int c = id.indexOf(':');
|
||||
return c < 0 ? id : id.substring(c + 1);
|
||||
}
|
||||
return localized;
|
||||
if (itemEntry != null && !itemEntry.localizedName.equals("Air")) {
|
||||
// This is more likely to be "right", but not translated
|
||||
// Some vanilla MC items have overrides so we need this name here
|
||||
// Most platforms should be overriding this anyways, so it likely doesn't matter
|
||||
// too much!
|
||||
return TextComponent.of(itemEntry.localizedName);
|
||||
}
|
||||
return null;
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("item", itemType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -29,10 +32,32 @@ public interface ItemRegistry {
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name, or null if it's unknown
|
||||
* @return The name
|
||||
*/
|
||||
Component getRichName(ItemType itemType);
|
||||
|
||||
/**
|
||||
* Gets the name for the given item stack.
|
||||
*
|
||||
* @param itemStack the item stack
|
||||
* @return The name
|
||||
*/
|
||||
default Component getRichName(BaseItemStack itemStack) {
|
||||
return getRichName(itemStack.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name for the given item.
|
||||
*
|
||||
* @param itemType the item
|
||||
* @return The name, or null if it's unknown
|
||||
* @deprecated Names are now translatable, use {@link #getRichName(ItemType)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String getName(ItemType itemType);
|
||||
default String getName(ItemType itemType) {
|
||||
return getRichName(itemType).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the material for the given item.
|
||||
|
||||
+11
@@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.world.registry;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
|
||||
@@ -35,6 +38,14 @@ public class NullBiomeRegistry implements BiomeRegistry {
|
||||
public NullBiomeRegistry() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRichName(BiomeType biomeType) {
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("biome", biomeType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Override
|
||||
public BiomeData getData(BiomeType biome) {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.fabric;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
@@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
|
||||
*/
|
||||
class FabricBiomeRegistry implements BiomeRegistry {
|
||||
|
||||
@Override
|
||||
public Component getRichName(BiomeType biomeType) {
|
||||
return TranslatableComponent.of(FabricAdapter.adapt(biomeType).getTranslationKey());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public BiomeData getData(BiomeType biome) {
|
||||
return new FabricBiomeData(FabricAdapter.adapt(biome));
|
||||
@@ -37,6 +45,7 @@ class FabricBiomeRegistry implements BiomeRegistry {
|
||||
/**
|
||||
* Cached biome data information.
|
||||
*/
|
||||
@Deprecated
|
||||
private static class FabricBiomeData implements BiomeData {
|
||||
private final Biome biome;
|
||||
|
||||
@@ -49,10 +58,11 @@ class FabricBiomeRegistry implements BiomeRegistry {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getName() {
|
||||
return biome.getName().asFormattedString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,17 +20,15 @@
|
||||
package com.sk89q.worldedit.fabric;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Material;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,15 +39,9 @@ public class FabricBlockRegistry extends BundledBlockRegistry {
|
||||
|
||||
private Map<Material, FabricBlockMaterial> materialMap = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(BlockType blockType) {
|
||||
Block block = FabricAdapter.adapt(blockType);
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
return block.getName().asFormattedString();
|
||||
} else {
|
||||
return super.getName(blockType);
|
||||
}
|
||||
public Component getRichName(BlockType blockType) {
|
||||
return TranslatableComponent.of(FabricAdapter.adapt(blockType).getTranslationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,24 +19,26 @@
|
||||
|
||||
package com.sk89q.worldedit.fabric;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FabricItemRegistry extends BundledItemRegistry {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(ItemType itemType) {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
final Item item = FabricAdapter.adapt(itemType);
|
||||
return I18n.translate(item.getTranslationKey());
|
||||
}
|
||||
return super.getName(itemType);
|
||||
public Component getRichName(ItemType itemType) {
|
||||
return TranslatableComponent.of(
|
||||
FabricAdapter.adapt(itemType).getTranslationKey()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRichName(BaseItemStack itemStack) {
|
||||
return TranslatableComponent.of(
|
||||
FabricAdapter.adapt(itemStack).getTranslationKey()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
@@ -29,6 +31,12 @@ import net.minecraft.world.biome.Biome;
|
||||
*/
|
||||
class ForgeBiomeRegistry implements BiomeRegistry {
|
||||
|
||||
@Override
|
||||
public Component getRichName(BiomeType biomeType) {
|
||||
return TranslatableComponent.of(ForgeAdapter.adapt(biomeType).getTranslationKey());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public BiomeData getData(BiomeType biome) {
|
||||
return new ForgeBiomeData(ForgeAdapter.adapt(biome));
|
||||
@@ -37,6 +45,7 @@ class ForgeBiomeRegistry implements BiomeRegistry {
|
||||
/**
|
||||
* Cached biome data information.
|
||||
*/
|
||||
@Deprecated
|
||||
private static class ForgeBiomeData implements BiomeData {
|
||||
private final Biome biome;
|
||||
|
||||
@@ -49,10 +58,11 @@ class ForgeBiomeRegistry implements BiomeRegistry {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getName() {
|
||||
return biome.getDisplayName().getString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
@@ -27,9 +29,7 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -40,15 +40,9 @@ public class ForgeBlockRegistry extends BundledBlockRegistry {
|
||||
|
||||
private Map<Material, ForgeBlockMaterial> materialMap = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(BlockType blockType) {
|
||||
Block block = ForgeAdapter.adapt(blockType);
|
||||
if (block != null && FMLLoader.getDist().isClient()) {
|
||||
return block.getNameTextComponent().getFormattedText();
|
||||
} else {
|
||||
return super.getName(blockType);
|
||||
}
|
||||
public Component getRichName(BlockType blockType) {
|
||||
return TranslatableComponent.of(ForgeAdapter.adapt(blockType).getTranslationKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,28 +19,26 @@
|
||||
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
|
||||
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;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ForgeItemRegistry extends BundledItemRegistry {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getName(ItemType itemType) {
|
||||
if (FMLLoader.getDist().isClient()) {
|
||||
final Item item = RegistryManager.ACTIVE.getRegistry(Item.class)
|
||||
.getValue(ResourceLocation.tryCreate(itemType.getId()));
|
||||
if (item != null) {
|
||||
return I18n.format(item.getTranslationKey());
|
||||
}
|
||||
}
|
||||
return super.getName(itemType);
|
||||
public Component getRichName(ItemType itemType) {
|
||||
return TranslatableComponent.of(
|
||||
ForgeAdapter.adapt(itemType).getTranslationKey()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getRichName(BaseItemStack itemStack) {
|
||||
return TranslatableComponent.of(
|
||||
ForgeAdapter.adapt(itemStack).getTranslationKey()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.sponge;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.sk89q.worldedit.util.translation.TranslationManager;
|
||||
import com.sk89q.worldedit.world.biome.BiomeData;
|
||||
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
||||
import org.spongepowered.api.world.biome.BiomeType;
|
||||
@@ -30,12 +33,21 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
class SpongeBiomeRegistry implements BiomeRegistry {
|
||||
|
||||
@Override
|
||||
public Component getRichName(com.sk89q.worldedit.world.biome.BiomeType biomeType) {
|
||||
return TranslatableComponent.of(
|
||||
TranslationManager.makeTranslationKey("biome", biomeType.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Override
|
||||
public BiomeData getData(com.sk89q.worldedit.world.biome.BiomeType biome) {
|
||||
return new SpongeBiomeData(SpongeAdapter.adapt(biome));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static class SpongeBiomeData implements BiomeData {
|
||||
private final BiomeType biome;
|
||||
|
||||
@@ -48,10 +60,11 @@ class SpongeBiomeRegistry implements BiomeRegistry {
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getName() {
|
||||
return biome.getName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user