mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 20:50:41 +01:00
77a5779e24
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: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
192 lines
9.5 KiB
Diff
192 lines
9.5 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/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
index f041b5d80bff9c022b007e04ef1558e9116acc6b..a586442422a2b2c06b785af0d261d3e19eb1d59b 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..fc6606e1bf2e2c35cb6c84af78859c3441775907 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
@@ -150,6 +150,11 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
|
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.handle.getDescriptionId();
|
|
+ }
|
|
// Paper end
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
index d20fdd4f06faa09c7d9f9e04f379cf0fa68db9bb..66d773cadb74f9176e6cf68a565568034f52ec63 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java
|
|
@@ -240,4 +240,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 305eac6845119c36d041bf75930eb0909405911c..8c1d2d0521da52f9a1262f5433da21700b9b0454 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
|
|
@@ -110,7 +110,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..b61b8b8e4fe1b5d905f218bf3b406b1e1af3f6b3 100644
|
|
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
@@ -1,12 +1,28 @@
|
|
package io.papermc.paper.world;
|
|
|
|
import com.destroystokyo.paper.ClientOption;
|
|
+import java.util.Locale;
|
|
+import java.util.Map;
|
|
+import net.minecraft.core.registries.BuiltInRegistries;
|
|
+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.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.util.CraftNamespacedKey;
|
|
+import org.bukkit.support.AbstractTestingBase;
|
|
import org.junit.jupiter.api.Assertions;
|
|
+import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
-public class TranslationKeyTest {
|
|
+public class TranslationKeyTest extends AbstractTestingBase {
|
|
|
|
@Test
|
|
public void testChatVisibilityKeys() {
|
|
@@ -15,4 +31,69 @@ 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() {
|
|
+ for (GameRule<?> rule : GameRule.values()) {
|
|
+ Assertions.assertEquals(org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().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 : AbstractTestingBase.BIOMES.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 : BuiltInRegistries.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);
|
|
+ }
|
|
+ }
|
|
}
|