Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 11:00:06 +01:00
52a05907c7
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 97c59261 PR-1073: Make Biome an interface a38581aa Fix further javadoc errors 8271c490 Fix javadoc error 8a9ecf29 PR-1072: Fix bad naming for Vault State methods 6dd58108 PR-1071: Make Fluid an interface and add missing entry ed2cdfc3 PR-1070: Make Attribute an interface and align names with the new minecraft ones 63472efb PR-1069: Add missing winter drop experimental annotation to pale boats CraftBukkit Changes: 7235ad7b0 PR-1501: Make Biome an interface 602904003 PR-1500: Rename implementation for Vault State methods 75f26f79f PR-1499: Make Fluid an interface and add missing entry 4cfd87adc PR-1498: Make Attribute an interface and align names with the new minecraft ones 6bb0db5cb SPIGOT-7928: ExactChoice acts as MaterialChoice 3eaf3a13c SPIGOT-7929: Error when setting EquippableComponent abbf57bac SPIGOT-7930: Fix spawning entities with SummonEntityEffect 92d6ab6cf PR-1497: Move boat field rename entries to below key renaming, so that keys are also renamed abfe292aa PR-1496: Use correct Fluid class on Tags type check c7aab7fa7 SPIGOT-7923: Fix Dispenser logic to avoid firing empty projectiles
219 Zeilen
11 KiB
Diff
219 Zeilen
11 KiB
Diff
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
|
|
|
|
== AT ==
|
|
public org.bukkit.craftbukkit.inventory.CraftMetaFirework
|
|
public org.bukkit.craftbukkit.inventory.CraftMetaFirework power
|
|
public org.bukkit.craftbukkit.inventory.CraftMetaFirework getNBT(Lorg/bukkit/FireworkEffect$Type;)Lnet/minecraft/world/item/component/FireworkExplosion$Shape;
|
|
|
|
Co-authored-by: MeFisto94 <MeFisto94@users.noreply.github.com>
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
index 8797a47be16b85dc69a28a56bb355bee7d6b1a78..9ab615347e241ac264fb70f43306075907420885 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java
|
|
@@ -98,6 +98,11 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
|
|
return this.attributeBase.getDescriptionId();
|
|
}
|
|
|
|
+ @Override
|
|
+ public @NotNull String translationKey() {
|
|
+ return this.attributeBase.getDescriptionId();
|
|
+ }
|
|
+
|
|
@Override
|
|
public int compareTo(@NotNull Attribute attribute) {
|
|
return this.ordinal - attribute.ordinal();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
index aae00320ab8003420bae5de7df47f553b62c5aab..3fa3de9a89550ec2fcb8ca663742826c0c3136b6 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -669,5 +669,10 @@ public class CraftBlock implements Block {
|
|
public org.bukkit.SoundGroup getBlockSoundGroup() {
|
|
return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType());
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public String translationKey() {
|
|
+ return this.getNMS().getBlock().getDescriptionId();
|
|
+ }
|
|
// Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java
|
|
index 338a8f4acf413ef24fedab60c19c7a51a0ea19a6..2d8a509446c0ed0d7358f10f67ef29c4df683696 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockType.java
|
|
@@ -234,4 +234,11 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
|
|
public Material asMaterial() {
|
|
return Registry.MATERIAL.get(this.key);
|
|
}
|
|
+
|
|
+ // Paper start - add Translatable
|
|
+ @Override
|
|
+ public String translationKey() {
|
|
+ return this.block.getDescriptionId();
|
|
+ }
|
|
+ // Paper end - add Translatable
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
index f73017bff613bd62b86c974b29576e241c24c927..59c9c970b83f62245d860994c4ac0c21dcc15398 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
@@ -152,6 +152,17 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
|
}
|
|
// Paper end
|
|
|
|
+ // Paper start - add translationKey methods
|
|
+ @Override
|
|
+ public String translationKey() {
|
|
+ if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
|
|
+ throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
|
+ }
|
|
+ return translatableContents.getKey();
|
|
+
|
|
+ }
|
|
+ // Paper end - add translationKey methods
|
|
+
|
|
@Override
|
|
public String getTranslationKey() {
|
|
return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
index 0e9d3d823608a694ef1de5c4fec593951d678c1a..68756419ac6ee292db9569eab380a5c14d748002 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
@@ -237,4 +237,11 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
|
public Material asMaterial() {
|
|
return Registry.MATERIAL.get(this.key);
|
|
}
|
|
+
|
|
+ // Paper start - add Translatable
|
|
+ @Override
|
|
+ public String translationKey() {
|
|
+ return this.item.getDescriptionId();
|
|
+ }
|
|
+ // Paper end - add Translatable
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
index 4921fc085c9d60c74028ef390325e26c598e8df1..4941e0afff8df5f10f06c715b54bf58eb86051c5 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
@@ -123,7 +123,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
|
return new FireworkExplosion(CraftMetaFirework.getNBT(effect.getType()), colors, fadeColors, effect.hasTrail(), effect.hasFlicker());
|
|
}
|
|
|
|
- static FireworkExplosion.Shape getNBT(Type type) {
|
|
+ public static FireworkExplosion.Shape getNBT(Type type) { // Paper - package-private -> public
|
|
switch (type) {
|
|
case BALL:
|
|
return FireworkExplosion.Shape.SMALL_BALL;
|
|
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
index 7f8b6462d2a1bbd39a870d2543bebc135f7eb45b..e8d5c3eb8ad98b2082bdd33d96bfb1d7124ea186 100644
|
|
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
@@ -1,11 +1,32 @@
|
|
package io.papermc.paper.world;
|
|
|
|
import com.destroystokyo.paper.ClientOption;
|
|
+import java.util.Locale;
|
|
+import java.util.Map;
|
|
+import net.minecraft.core.registries.Registries;
|
|
+import net.minecraft.network.chat.contents.TranslatableContents;
|
|
+import net.minecraft.resources.ResourceKey;
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.world.entity.player.ChatVisiblity;
|
|
+import net.minecraft.world.flag.FeatureFlags;
|
|
+import net.minecraft.world.level.GameRules;
|
|
+import net.minecraft.world.level.GameType;
|
|
+import net.minecraft.world.level.biome.Biome;
|
|
import org.bukkit.Difficulty;
|
|
+import org.bukkit.FireworkEffect;
|
|
+import org.bukkit.GameMode;
|
|
+import org.bukkit.GameRule;
|
|
+import org.bukkit.MusicInstrument;
|
|
+import org.bukkit.attribute.Attribute;
|
|
+import org.bukkit.craftbukkit.CraftWorld;
|
|
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
|
+import org.bukkit.support.RegistryHelper;
|
|
+import org.bukkit.support.environment.AllFeatures;
|
|
import org.junit.jupiter.api.Assertions;
|
|
+import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
+@AllFeatures
|
|
public class TranslationKeyTest {
|
|
|
|
@Test
|
|
@@ -15,4 +36,70 @@ public class TranslationKeyTest {
|
|
Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
|
|
}
|
|
}
|
|
+
|
|
+ @Test
|
|
+ public void testDifficultyKeys() {
|
|
+ for (Difficulty bukkitDifficulty : Difficulty.values()) {
|
|
+ Assertions.assertEquals(((TranslatableContents) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName().getContents()).getKey(), bukkitDifficulty.translationKey(), bukkitDifficulty + "'s translation key doesn't match");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testGameruleKeys() {
|
|
+ final Map<String, GameRules.Key<?>> gameRules = CraftWorld.getGameRulesNMS(new GameRules(FeatureFlags.REGISTRY.allFlags()));
|
|
+ for (GameRule<?> rule : GameRule.values()) {
|
|
+ Assertions.assertEquals(gameRules.get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testAttributeKeys() {
|
|
+ for (Attribute attribute : Attribute.values()) {
|
|
+ Assertions.assertEquals(org.bukkit.craftbukkit.attribute.CraftAttribute.bukkitToMinecraft(attribute).getDescriptionId(), attribute.translationKey(), "translation key mismatch for " + attribute);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testFireworkEffectType() {
|
|
+ for (final FireworkEffect.Type type : FireworkEffect.Type.values()) {
|
|
+ final net.minecraft.world.item.component.FireworkExplosion.Shape nmsType = org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type);
|
|
+ Assertions.assertTrue(nmsType.getName().getContents() instanceof TranslatableContents, "contents aren't translatable");
|
|
+ Assertions.assertEquals(((TranslatableContents) nmsType.getName().getContents()).getKey(), type.translationKey(), "translation key mismatch for " + type);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ @Disabled // TODO fix
|
|
+ public void testCreativeCategory() {
|
|
+ // for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
|
|
+ // CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab));
|
|
+ // Assertions.assertEquals("translation key mismatch for " + category, ((TranslatableContents) tab.getDisplayName().getContents()).getKey(), category.translationKey());
|
|
+ // }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testGameMode() {
|
|
+ for (GameType nms : GameType.values()) {
|
|
+ GameMode bukkit = GameMode.getByValue(nms.getId());
|
|
+ Assertions.assertNotNull(bukkit);
|
|
+ Assertions.assertEquals(((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testBiome() {
|
|
+ for (Map.Entry<ResourceKey<Biome>, Biome> nms : RegistryHelper.getBiomes().entrySet()) {
|
|
+ org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase(Locale.ROOT));
|
|
+ Assertions.assertEquals(nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Test
|
|
+ public void testMusicInstrument() {
|
|
+ for (final ResourceLocation nms : RegistryHelper.getRegistry().lookupOrThrow(Registries.INSTRUMENT).keySet()) {
|
|
+ final MusicInstrument bukkit = MusicInstrument.getByKey(CraftNamespacedKey.fromMinecraft(nms));
|
|
+ Assertions.assertNotNull(bukkit, "Missing bukkit instrument for " + nms);
|
|
+ Assertions.assertEquals(nms.toLanguageKey("instrument"), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
|
+ }
|
|
+ }
|
|
}
|