From d6784f22c15c21bf1c74c890177d55edd79c5ebe Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Wed, 1 Jun 2022 18:30:29 -0700 Subject: [PATCH] Add translation keys to GameMode enum (#7081) --- .../Add-methods-to-get-translation-keys.patch | 32 +++++++++++++++++++ .../Add-methods-to-get-translation-keys.patch | 11 +++++++ 2 files changed, 43 insertions(+) diff --git a/patches/api/Add-methods-to-get-translation-keys.patch b/patches/api/Add-methods-to-get-translation-keys.patch index 82e51b95c0..71b2e2b629 100644 --- a/patches/api/Add-methods-to-get-translation-keys.patch +++ b/patches/api/Add-methods-to-get-translation-keys.patch @@ -85,6 +85,38 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end } + /** +diff --git a/src/main/java/org/bukkit/GameMode.java b/src/main/java/org/bukkit/GameMode.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/GameMode.java ++++ b/src/main/java/org/bukkit/GameMode.java +@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable; + * Represents the various type of game modes that {@link HumanEntity}s may + * have + */ +-public enum GameMode { ++public enum GameMode implements net.kyori.adventure.translation.Translatable { // Paper - implement Translatable + /** + * Creative mode may fly, build instantly, become invulnerable and create + * free items. +@@ -0,0 +0,0 @@ public enum GameMode { + + private final int value; + private static final Map BY_ID = Maps.newHashMap(); ++ // Paper start - translation keys ++ private final String translationKey; ++ ++ @Override ++ public @org.jetbrains.annotations.NotNull String translationKey() { ++ return this.translationKey; ++ } ++ // Paper end + + private GameMode(final int value) { + this.value = value; ++ this.translationKey = "gameMode." + this.name().toLowerCase(java.util.Locale.ENGLISH); // Paper + } + /** diff --git a/src/main/java/org/bukkit/GameRule.java b/src/main/java/org/bukkit/GameRule.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 diff --git a/patches/server/Add-methods-to-get-translation-keys.patch b/patches/server/Add-methods-to-get-translation-keys.patch index 0ca0aa228d..2603e0927a 100644 --- a/patches/server/Add-methods-to-get-translation-keys.patch +++ b/patches/server/Add-methods-to-get-translation-keys.patch @@ -85,8 +85,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.world.entity.player.ChatVisiblity; +import net.minecraft.world.item.CreativeModeTab; ++import net.minecraft.world.level.GameType; import org.bukkit.Difficulty; +import org.bukkit.FireworkEffect; ++import org.bukkit.GameMode; +import org.bukkit.GameRule; +import org.bukkit.attribute.Attribute; +import org.bukkit.craftbukkit.inventory.CraftCreativeCategory; @@ -144,5 +146,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab)); + Assert.assertEquals("translation key mismatch for " + category, ((TranslatableComponent) tab.getDisplayName()).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, ((TranslatableComponent) nms.getLongDisplayName()).getKey(), bukkit.translationKey()); ++ } + } }