From 412e157d390a32eff4855a931f8a72f25d6d8445 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 20 Feb 2023 19:35:39 +1100 Subject: [PATCH] SPIGOT-7267: Fix EntityType#getTranslationKey() and add unit test By: Doc --- .../org/bukkit/craftbukkit/util/CraftMagicNumbers.java | 3 ++- .../test/java/org/bukkit/entity/EntityTypesTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index a7879836c8..68546700fd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -377,7 +377,8 @@ public final class CraftMagicNumbers implements UnsafeValues { @Override public String getTranslationKey(EntityType entityType) { - return EntityTypes.byString(entityType.name()).map(EntityTypes::getDescriptionId).orElseThrow(); + Preconditions.checkArgument(entityType.getName() != null, "Invalid name of EntityType %s for translation key", entityType); + return EntityTypes.byString(entityType.getName()).map(EntityTypes::getDescriptionId).orElseThrow(); } @Override diff --git a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java index 724e03c963..366509f17b 100644 --- a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java @@ -27,4 +27,14 @@ public class EntityTypesTest extends AbstractTestingBase { Assert.assertTrue("Unmapped bukkit entities " + allBukkit, allBukkit.isEmpty()); } + + @Test + public void testTranslationKey() { + for (EntityType entityType : EntityType.values()) { + // Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names. + if (entityType.getName() != null) { + Assert.assertNotNull("Nulllable translation key for " + entityType, entityType.getTranslationKey()); + } + } + } }