2021-08-14 06:11:12 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Tue, 11 Aug 2020 19:16:09 +0200
|
|
|
|
Subject: [PATCH] Add methods to get translation keys
|
|
|
|
|
2022-11-20 00:53:20 +01:00
|
|
|
== AT ==
|
|
|
|
public org.bukkit.craftbukkit.inventory.CraftMetaFirework
|
|
|
|
public org.bukkit.craftbukkit.inventory.CraftMetaFirework getNBT(Lorg/bukkit/FireworkEffect$Type;)I
|
|
|
|
|
2021-08-14 06:11:12 +02:00
|
|
|
Co-authored-by: MeFisto94 <MeFisto94@users.noreply.github.com>
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2024-01-14 16:31:39 +01:00
|
|
|
index f041b5d80bff9c022b007e04ef1558e9116acc6b..a586442422a2b2c06b785af0d261d3e19eb1d59b 100644
|
2021-08-14 06:11:12 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2023-12-06 04:00:14 +01:00
|
|
|
@@ -669,5 +669,10 @@ public class CraftBlock implements Block {
|
2022-04-30 22:44:22 +02:00
|
|
|
public org.bukkit.SoundGroup getBlockSoundGroup() {
|
|
|
|
return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType());
|
2021-08-14 06:11:12 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String translationKey() {
|
2023-02-15 23:10:14 +01:00
|
|
|
+ return this.getNMS().getBlock().getDescriptionId();
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
2024-01-26 20:17:06 +01:00
|
|
|
index f0f7fb977edb7e7009716429f007e44fa36bfcda..7aa4035a4df1ddcc71065034eafd569ca59be810 100644
|
2021-08-14 06:11:12 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
2024-01-26 20:17:06 +01:00
|
|
|
@@ -152,6 +152,11 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
2021-08-14 06:11:12 +02:00
|
|
|
public net.kyori.adventure.text.Component displayName(int level) {
|
|
|
|
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String translationKey() {
|
2023-12-06 19:21:23 +01:00
|
|
|
+ return this.handle.getDescriptionId();
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
2023-12-06 04:00:14 +01:00
|
|
|
@Override
|
2021-08-14 06:11:12 +02:00
|
|
|
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
2023-09-25 01:05:05 +02:00
|
|
|
index 7f8b6462d2a1bbd39a870d2543bebc135f7eb45b..dbd1dc4453bd26fb6116b62f6ccbf69e92e09fc4 100644
|
2021-08-14 06:11:12 +02:00
|
|
|
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
2023-07-29 00:06:27 +02:00
|
|
|
@@ -1,12 +1,27 @@
|
2022-06-08 17:31:27 +02:00
|
|
|
package io.papermc.paper.world;
|
|
|
|
|
2022-06-02 02:07:10 +02:00
|
|
|
import com.destroystokyo.paper.ClientOption;
|
2022-12-08 19:23:12 +01:00
|
|
|
+import java.util.Map;
|
2023-07-29 00:06:27 +02:00
|
|
|
+import net.minecraft.core.registries.BuiltInRegistries;
|
2022-06-08 17:31:27 +02:00
|
|
|
+import net.minecraft.network.chat.contents.TranslatableContents;
|
2022-07-20 18:23:26 +02:00
|
|
|
+import net.minecraft.resources.ResourceKey;
|
2023-07-29 00:06:27 +02:00
|
|
|
+import net.minecraft.resources.ResourceLocation;
|
2022-06-02 02:07:10 +02:00
|
|
|
import net.minecraft.world.entity.player.ChatVisiblity;
|
2022-06-02 03:30:29 +02:00
|
|
|
+import net.minecraft.world.level.GameType;
|
2022-07-20 18:23:26 +02:00
|
|
|
+import net.minecraft.world.level.biome.Biome;
|
2022-06-02 02:07:10 +02:00
|
|
|
import org.bukkit.Difficulty;
|
|
|
|
+import org.bukkit.FireworkEffect;
|
2022-06-02 03:30:29 +02:00
|
|
|
+import org.bukkit.GameMode;
|
2022-06-02 02:07:10 +02:00
|
|
|
+import org.bukkit.GameRule;
|
2023-07-29 00:06:27 +02:00
|
|
|
+import org.bukkit.MusicInstrument;
|
2022-06-02 02:07:10 +02:00
|
|
|
+import org.bukkit.attribute.Attribute;
|
2023-07-29 00:06:27 +02:00
|
|
|
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
2022-06-02 02:07:10 +02:00
|
|
|
+import org.bukkit.support.AbstractTestingBase;
|
2023-09-24 09:16:58 +02:00
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
+import org.junit.jupiter.api.Disabled;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2021-08-14 06:11:12 +02:00
|
|
|
|
|
|
|
-public class TranslationKeyTest {
|
2022-06-02 02:07:10 +02:00
|
|
|
+public class TranslationKeyTest extends AbstractTestingBase {
|
2021-08-14 06:11:12 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testChatVisibilityKeys() {
|
2023-07-29 00:06:27 +02:00
|
|
|
@@ -15,4 +30,67 @@ public class TranslationKeyTest {
|
2023-09-25 01:05:05 +02:00
|
|
|
Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
|
2021-08-14 06:11:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testDifficultyKeys() {
|
|
|
|
+ for (Difficulty bukkitDifficulty : Difficulty.values()) {
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(((TranslatableContents) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName().getContents()).getKey(), bukkitDifficulty.translationKey(), bukkitDifficulty + "'s translation key doesn't match");
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGameruleKeys() {
|
2022-06-02 02:07:10 +02:00
|
|
|
+ for (GameRule<?> rule : GameRule.values()) {
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match");
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testAttributeKeys() {
|
2022-06-02 02:07:10 +02:00
|
|
|
+ for (Attribute attribute : Attribute.values()) {
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(org.bukkit.craftbukkit.attribute.CraftAttribute.bukkitToMinecraft(attribute).getDescriptionId(), attribute.translationKey(), "translation key mismatch for " + attribute);
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testFireworkEffectType() {
|
2022-06-02 02:07:10 +02:00
|
|
|
+ for (FireworkEffect.Type type : FireworkEffect.Type.values()) {
|
2023-09-25 01:05:05 +02:00
|
|
|
+ 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);
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
2022-06-02 02:07:10 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
2023-09-24 09:16:58 +02:00
|
|
|
+ @Disabled // TODO fix
|
2022-06-02 02:07:10 +02:00
|
|
|
+ public void testCreativeCategory() {
|
2022-12-08 19:23:12 +01:00
|
|
|
+ // for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
|
|
|
|
+ // CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab));
|
2023-09-24 09:16:58 +02:00
|
|
|
+ // Assertions.assertEquals("translation key mismatch for " + category, ((TranslatableContents) tab.getDisplayName().getContents()).getKey(), category.translationKey());
|
2022-12-08 19:23:12 +01:00
|
|
|
+ // }
|
2022-06-02 03:30:29 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGameMode() {
|
|
|
|
+ for (GameType nms : GameType.values()) {
|
|
|
|
+ GameMode bukkit = GameMode.getByValue(nms.getId());
|
2023-09-24 09:16:58 +02:00
|
|
|
+ Assertions.assertNotNull(bukkit);
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
2022-06-02 03:30:29 +02:00
|
|
|
+ }
|
2022-07-20 18:23:26 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testBiome() {
|
2022-12-08 19:23:12 +01:00
|
|
|
+ for (Map.Entry<ResourceKey<Biome>, Biome> nms : AbstractTestingBase.BIOMES.entrySet()) {
|
2022-07-20 18:23:26 +02:00
|
|
|
+ org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase());
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
2022-07-20 18:23:26 +02:00
|
|
|
+ }
|
2023-07-29 00:06:27 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testMusicInstrument() {
|
|
|
|
+ for (final ResourceLocation nms : BuiltInRegistries.INSTRUMENT.keySet()) {
|
|
|
|
+ final MusicInstrument bukkit = MusicInstrument.getByKey(CraftNamespacedKey.fromMinecraft(nms));
|
2023-09-24 09:16:58 +02:00
|
|
|
+ Assertions.assertNotNull(bukkit, "Missing bukkit instrument for " + nms);
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(nms.toLanguageKey("instrument"), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
2023-07-29 00:06:27 +02:00
|
|
|
+ }
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
}
|