Skip to content
Permalink
Browse files
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 59a5d6c.

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
  • Loading branch information
octylFractal committed Mar 23, 2020
1 parent 2f4c44f commit cfd26253b6fb59ff6c65a0157a6780be7db4ea5a
Showing 37 changed files with 513 additions and 266 deletions.
@@ -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 @@
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.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 @@ public BiomeRegistry getBiomeRegistry() {
return biomeRegistry;
}

@Override
public ItemRegistry getItemRegistry() {
return itemRegistry;
}

@Override
public BlockCategoryRegistry getBlockCategoryRegistry() {
return blockCategoryRegistry;
@@ -30,10 +30,12 @@
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 @@ default void tickWatchdog() {
@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 void flushBlockBag(Actor actor, EditSession editSession) {
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 void flushBlockBag(Actor actor, EditSession editSession) {
}
}

actor.printError(str.toString());
actor.printError(str.build());
}
}

0 comments on commit cfd2625

Please sign in to comment.