From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 11 Aug 2020 19:16:09 +0200 Subject: [PATCH] Add methods to get translation keys == AT == public org.bukkit.craftbukkit.inventory.CraftMetaFirework public org.bukkit.craftbukkit.inventory.CraftMetaFirework getNBT(Lorg/bukkit/FireworkEffect$Type;)I Co-authored-by: MeFisto94 diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -0,0 +0,0 @@ public class CraftBlock implements Block { public org.bukkit.SoundGroup getBlockSoundGroup() { return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType()); } + + @Override + public String getTranslationKey() { + return this.translationKey(); + } + + @Override + public String translationKey() { + return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); + } // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -0,0 +0,0 @@ public class CraftEnchantment extends Enchantment { public net.kyori.adventure.text.Component displayName(int level) { return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level)); } + + @Override + public String translationKey() { + return this.target.getDescriptionId(); + } // Paper end public net.minecraft.world.item.enchantment.Enchantment getHandle() { diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!"); return compound; } + + @Override + public String getTranslationKey(Material mat) { + if (mat.isBlock()) { + return getBlock(mat).getDescriptionId(); + } + return getItem(mat).getDescriptionId(); + } + + @Override + public String getTranslationKey(org.bukkit.block.Block block) { + return ((org.bukkit.craftbukkit.block.CraftBlock)block).getNMS().getBlock().getDescriptionId(); + } + + @Override + public String getTranslationKey(org.bukkit.entity.EntityType type) { + return net.minecraft.world.entity.EntityType.byString(type.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElse(null); + } + + @Override + public String getTranslationKey(org.bukkit.inventory.ItemStack itemStack) { + net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); + return nmsItemStack.getItem().getDescriptionId(nmsItemStack); + } // Paper end /** diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java +++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java @@ -0,0 +0,0 @@ package io.papermc.paper.world; import com.destroystokyo.paper.ClientOption; +import java.util.Map; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.player.ChatVisiblity; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.biome.Biome; import org.bukkit.Difficulty; +import org.bukkit.FireworkEffect; +import org.bukkit.GameMode; +import org.bukkit.GameRule; +import org.bukkit.attribute.Attribute; +import org.bukkit.support.AbstractTestingBase; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; -public class TranslationKeyTest { +public class TranslationKeyTest extends AbstractTestingBase { @Test public void testChatVisibilityKeys() { @@ -0,0 +0,0 @@ public class TranslationKeyTest { Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey()); } } + + @Test + public void testDifficultyKeys() { + for (Difficulty bukkitDifficulty : Difficulty.values()) { + Assert.assertEquals(bukkitDifficulty + "'s translation key doesn't match", ((TranslatableContents) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName().getContents()).getKey(), bukkitDifficulty.translationKey()); + } + } + + @Test + public void testGameruleKeys() { + for (GameRule rule : GameRule.values()) { + Assert.assertEquals(rule.getName() + "'s translation doesn't match", org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey()); + } + } + + @Test + public void testAttributeKeys() { + for (Attribute attribute : Attribute.values()) { + Assert.assertEquals("translation key mismatch for " + attribute, org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute).getDescriptionId(), attribute.translationKey()); + } + } + + @Test + public void testFireworkEffectType() { + for (FireworkEffect.Type type : FireworkEffect.Type.values()) { + Assert.assertEquals("translation key mismatch for " + type, net.minecraft.world.item.FireworkRocketItem.Shape.byId(org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type)).getName(), org.bukkit.FireworkEffect.Type.NAMES.key(type)); + } + } + + @Test + @Ignore // TODO fix + public void testCreativeCategory() { + // for (CreativeModeTab tab : CreativeModeTabs.tabs()) { + // CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab)); + // Assert.assertEquals("translation key mismatch for " + category, ((TranslatableContents) tab.getDisplayName().getContents()).getKey(), category.translationKey()); + // } + } + + @Test + public void testGameMode() { + for (GameType nms : GameType.values()) { + GameMode bukkit = GameMode.getByValue(nms.getId()); + Assert.assertNotNull(bukkit); + Assert.assertEquals("translation key mismatch for " + bukkit, ((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey()); + } + } + + @Test + public void testBiome() { + for (Map.Entry, Biome> nms : AbstractTestingBase.BIOMES.entrySet()) { + org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase()); + Assert.assertEquals("translation key mismatch for " + bukkit, nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey()); + } + } }