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 f041b5d80bff9c022b007e04ef1558e9116acc6b..a586442422a2b2c06b785af0d261d3e19eb1d59b 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -669,5 +669,10 @@ public class CraftBlock implements Block { public org.bukkit.SoundGroup getBlockSoundGroup() { return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType()); } + + @Override + public String translationKey() { + return this.getNMS().getBlock().getDescriptionId(); + } // 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 f0f7fb977edb7e7009716429f007e44fa36bfcda..7aa4035a4df1ddcc71065034eafd569ca59be810 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -152,6 +152,11 @@ public class CraftEnchantment extends Enchantment implements Handleable rule : GameRule.values()) { + Assertions.assertEquals(org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match"); + } + } + + @Test + public void testAttributeKeys() { + for (Attribute attribute : Attribute.values()) { + Assertions.assertEquals(org.bukkit.craftbukkit.attribute.CraftAttribute.bukkitToMinecraft(attribute).getDescriptionId(), attribute.translationKey(), "translation key mismatch for " + attribute); + } + } + + @Test + public void testFireworkEffectType() { + for (FireworkEffect.Type type : FireworkEffect.Type.values()) { + Assertions.assertEquals(net.minecraft.world.item.FireworkRocketItem.Shape.byId(org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type)).getName(), org.bukkit.FireworkEffect.Type.NAMES.key(type), "translation key mismatch for " + type); + } + } + + @Test + @Disabled // TODO fix + public void testCreativeCategory() { + // for (CreativeModeTab tab : CreativeModeTabs.tabs()) { + // CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab)); + // Assertions.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()); + Assertions.assertNotNull(bukkit); + Assertions.assertEquals(((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey(), "translation key mismatch for " + bukkit); + } + } + + @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()); + Assertions.assertEquals(nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey(), "translation key mismatch for " + bukkit); + } + } + + @Test + public void testMusicInstrument() { + for (final ResourceLocation nms : BuiltInRegistries.INSTRUMENT.keySet()) { + final MusicInstrument bukkit = MusicInstrument.getByKey(CraftNamespacedKey.fromMinecraft(nms)); + Assertions.assertNotNull(bukkit, "Missing bukkit instrument for " + nms); + Assertions.assertEquals(nms.toLanguageKey("instrument"), bukkit.translationKey(), "translation key mismatch for " + bukkit); + } + } }