Implement Translatable on CreativeCategory (#7587)

This commit is contained in:
Jake Potrebic 2022-06-01 17:07:10 -07:00
parent a063840a0e
commit 63ffb7fd84
2 changed files with 108 additions and 5 deletions

View file

@ -80,12 +80,25 @@ diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/
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 @@ import org.bukkit.Difficulty;
@@ -0,0 +0,0 @@ package io.papermc.paper.world;
import com.destroystokyo.paper.ClientOption;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.ChatVisiblity;
+import net.minecraft.world.item.CreativeModeTab;
import org.bukkit.Difficulty;
+import org.bukkit.FireworkEffect;
+import org.bukkit.GameRule;
+import org.bukkit.attribute.Attribute;
+import org.bukkit.craftbukkit.inventory.CraftCreativeCategory;
+import org.bukkit.inventory.CreativeCategory;
+import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert;
import org.junit.Test;
-public class TranslationKeyTest {
+public class TranslationKeyTest extends org.bukkit.support.AbstractTestingBase {
+import java.util.Objects;
+
+public class TranslationKeyTest extends AbstractTestingBase {
@Test
public void testChatVisibilityKeys() {
@ -103,22 +116,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ @Test
+ public void testGameruleKeys() {
+ for (org.bukkit.GameRule<?> rule : org.bukkit.GameRule.values()) {
+ 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 (org.bukkit.attribute.Attribute attribute : org.bukkit.attribute.Attribute.values()) {
+ 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 (org.bukkit.FireworkEffect.Type type : org.bukkit.FireworkEffect.Type.values()) {
+ 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
+ public void testCreativeCategory() {
+ for (CreativeModeTab tab : CreativeModeTab.TABS) {
+ if (tab == CreativeModeTab.TAB_SEARCH || tab == CreativeModeTab.TAB_HOTBAR || tab == CreativeModeTab.TAB_INVENTORY) { // not implemented in the api
+ continue;
+ }
+ CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab));
+ Assert.assertEquals("translation key mismatch for " + category, ((TranslatableComponent) tab.getDisplayName()).getKey(), category.translationKey());
+ }
+ }
}