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
|
2022-12-07 21:16:54 +01:00
|
|
|
index 7e97b09376b1e9000511f56f3406dba550ba2612..89b8abc3e7e946aae2ab3d2c870f2d2c95f9671d 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
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -670,5 +670,15 @@ 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 getTranslationKey() {
|
|
|
|
+ return this.translationKey();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String translationKey() {
|
|
|
|
+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
2022-12-07 21:16:54 +01:00
|
|
|
index e8334e2264510f5101e80b4f130e7ae1442560d7..57decf4156f176ebcc988478c17856cbc555c5e4 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
|
2022-06-08 08:06:17 +02:00
|
|
|
@@ -194,6 +194,11 @@ public class CraftEnchantment extends Enchantment {
|
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() {
|
|
|
|
+ return this.target.getDescriptionId();
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2022-12-07 21:16:54 +01:00
|
|
|
index cb7fd05f498448c87525eeeb012d055f90bac05e..30fe764640c8dad4b0f28486d00aa58a17bc7452 100644
|
2021-08-14 06:11:12 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2022-12-07 21:16:54 +01:00
|
|
|
@@ -481,6 +481,30 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2021-11-11 03:53:27 +01:00
|
|
|
Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!");
|
|
|
|
return compound;
|
2021-08-14 06:11:12 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getTranslationKey(Material mat) {
|
|
|
|
+ if (mat.isBlock()) {
|
|
|
|
+ return getBlock(mat).getDescriptionId();
|
|
|
|
+ }
|
|
|
|
+ return getItem(mat).getDescriptionId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getTranslationKey(org.bukkit.block.Block block) {
|
|
|
|
+ return ((org.bukkit.craftbukkit.block.CraftBlock)block).getNMS().getBlock().getDescriptionId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getTranslationKey(org.bukkit.entity.EntityType type) {
|
|
|
|
+ return net.minecraft.world.entity.EntityType.byString(type.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElse(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getTranslationKey(org.bukkit.inventory.ItemStack itemStack) {
|
|
|
|
+ net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
|
|
|
|
+ return nmsItemStack.getItem().getDescriptionId(nmsItemStack);
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
/**
|
|
|
|
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
2022-07-20 18:23:26 +02:00
|
|
|
index fab3063fffa959ac7f0eb5937f2fae94d11b6591..9292a0119499d14c9ed170999ac3b8dfdd1f839a 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
|
2022-07-20 18:23:26 +02:00
|
|
|
@@ -1,12 +1,29 @@
|
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-07-20 18:23:26 +02:00
|
|
|
+import net.minecraft.core.Registry;
|
|
|
|
+import net.minecraft.core.RegistryAccess;
|
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;
|
2022-06-02 02:07:10 +02:00
|
|
|
import net.minecraft.world.entity.player.ChatVisiblity;
|
|
|
|
+import net.minecraft.world.item.CreativeModeTab;
|
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;
|
|
|
|
+import org.bukkit.attribute.Attribute;
|
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftCreativeCategory;
|
|
|
|
+import org.bukkit.inventory.CreativeCategory;
|
|
|
|
+import org.bukkit.support.AbstractTestingBase;
|
2021-08-14 06:11:12 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
-public class TranslationKeyTest {
|
2022-07-20 18:23:26 +02:00
|
|
|
+import java.util.Map;
|
2022-06-02 02:07:10 +02:00
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+public class TranslationKeyTest extends AbstractTestingBase {
|
2021-08-14 06:11:12 +02:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testChatVisibilityKeys() {
|
2022-07-20 18:23:26 +02:00
|
|
|
@@ -15,4 +32,60 @@ public class TranslationKeyTest {
|
2021-08-14 06:11:12 +02:00
|
|
|
Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testDifficultyKeys() {
|
|
|
|
+ for (Difficulty bukkitDifficulty : Difficulty.values()) {
|
2022-06-08 17:31:27 +02:00
|
|
|
+ Assert.assertEquals(bukkitDifficulty + "'s translation key doesn't match", ((TranslatableContents) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName().getContents()).getKey(), bukkitDifficulty.translationKey());
|
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()) {
|
2021-08-14 06:11:12 +02:00
|
|
|
+ Assert.assertEquals(rule.getName() + "'s translation doesn't match", org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testAttributeKeys() {
|
2022-06-02 02:07:10 +02:00
|
|
|
+ for (Attribute attribute : Attribute.values()) {
|
2021-08-14 06:11:12 +02:00
|
|
|
+ Assert.assertEquals("translation key mismatch for " + attribute, org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute).getDescriptionId(), attribute.translationKey());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testFireworkEffectType() {
|
2022-06-02 02:07:10 +02:00
|
|
|
+ for (FireworkEffect.Type type : FireworkEffect.Type.values()) {
|
2021-08-14 06:11:12 +02:00
|
|
|
+ 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));
|
|
|
|
+ }
|
2022-06-02 02:07:10 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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));
|
2022-06-08 17:31:27 +02:00
|
|
|
+ Assert.assertEquals("translation key mismatch for " + category, ((TranslatableContents) tab.getDisplayName().getContents()).getKey(), category.translationKey());
|
2022-06-02 02:07:10 +02:00
|
|
|
+ }
|
2022-06-02 03:30:29 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGameMode() {
|
|
|
|
+ for (GameType nms : GameType.values()) {
|
|
|
|
+ GameMode bukkit = GameMode.getByValue(nms.getId());
|
|
|
|
+ Assert.assertNotNull(bukkit);
|
2022-06-08 17:31:27 +02:00
|
|
|
+ Assert.assertEquals("translation key mismatch for " + bukkit, ((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey());
|
2022-06-02 03:30:29 +02:00
|
|
|
+ }
|
2022-07-20 18:23:26 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testBiome() {
|
|
|
|
+ for (Map.Entry<ResourceKey<Biome>, Biome> nms : RegistryAccess.builtinCopy().registry(Registry.BIOME_REGISTRY).get().entrySet()) {
|
|
|
|
+ org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase());
|
|
|
|
+ Assert.assertEquals("translation key mismatch for " + bukkit, nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey());
|
|
|
|
+ }
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
}
|