diff --git a/build-data/paper.at b/build-data/paper.at index 235ae06d7..59c32f006 100644 --- a/build-data/paper.at +++ b/build-data/paper.at @@ -233,3 +233,7 @@ public net.minecraft.world.level.entity.PersistentEntitySectionManager sectionSt # Optimize light engine public-f net.minecraft.world.level.chunk.DataLayer + +# Add methods to get translation keys +public org.bukkit.craftbukkit.inventory.CraftMetaFirework +public org.bukkit.craftbukkit.inventory.CraftMetaFirework getNBT(Lorg/bukkit/FireworkEffect$Type;)I diff --git a/patches/api/0007-Adventure.patch b/patches/api/0007-Adventure.patch index aca9d3e01..49272d431 100644 --- a/patches/api/0007-Adventure.patch +++ b/patches/api/0007-Adventure.patch @@ -7,31 +7,48 @@ Co-authored-by: zml Co-authored-by: Jake Potrebic diff --git a/build.gradle.kts b/build.gradle.kts -index 17fd7162ab32785252bf2579daae8d47aec21684..479d4e3b91e902e9b30d351aa65c8b079555d7e0 100644 +index 17fd7162ab32785252bf2579daae8d47aec21684..f3018c133440e2f6d1bcdf1adb060dfc6db1a866 100644 --- a/build.gradle.kts +++ b/build.gradle.kts -@@ -10,6 +10,8 @@ java { +@@ -10,6 +10,19 @@ java { withJavadocJar() } +val adventureVersion = "4.8.1" ++val apiAndDocs by configurations.creating { ++ attributes { ++ attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) ++ attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) ++ attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES)) ++ attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) ++ } ++} ++configurations.api { ++ extendsFrom(apiAndDocs) ++} + dependencies { // api dependencies are listed transitively to API consumers api("commons-lang:commons-lang:2.6") -@@ -19,6 +21,11 @@ dependencies { +@@ -19,6 +32,11 @@ dependencies { api("org.yaml:snakeyaml:1.28") api("com.googlecode.json-simple:json-simple:1.1.1") // Paper api("it.unimi.dsi:fastutil:8.2.2") -+ api(platform("net.kyori:adventure-bom:$adventureVersion")) -+ api("net.kyori:adventure-api") -+ api("net.kyori:adventure-text-serializer-gson") -+ api("net.kyori:adventure-text-serializer-legacy") -+ api("net.kyori:adventure-text-serializer-plain") ++ apiAndDocs(platform("net.kyori:adventure-bom:$adventureVersion")) ++ apiAndDocs("net.kyori:adventure-api") ++ apiAndDocs("net.kyori:adventure-text-serializer-gson") ++ apiAndDocs("net.kyori:adventure-text-serializer-legacy") ++ apiAndDocs("net.kyori:adventure-text-serializer-plain") compileOnly("org.apache.maven:maven-resolver-provider:3.8.1") compileOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.0") -@@ -66,5 +73,11 @@ tasks.withType().configureEach { +@@ -61,10 +79,17 @@ tasks.jar { + } + + tasks.withType().configureEach { ++ (options as CoreJavadocOptions).addStringOption("sourcepath", apiAndDocs.resolvedConfiguration.files.joinToString(separator = File.pathSeparator, transform = File::getPath)) + (options as StandardJavadocDocletOptions).links( + "https://guava.dev/releases/21.0/api/docs/", "https://javadoc.io/doc/org.yaml/snakeyaml/1.28/", "https://javadoc.io/doc/org.jetbrains/annotations/21.0.1/", // Paper - we don't want Java 5 annotations "https://javadoc.io/doc/net.md-5/bungeecord-chat/1.16-R0.4/", diff --git a/patches/api/0025-Use-ASM-for-event-executors.patch b/patches/api/0025-Use-ASM-for-event-executors.patch index a8c4bbbf6..48f7e0c19 100644 --- a/patches/api/0025-Use-ASM-for-event-executors.patch +++ b/patches/api/0025-Use-ASM-for-event-executors.patch @@ -6,12 +6,12 @@ Subject: [PATCH] Use ASM for event executors. Uses method handles for private or static methods. diff --git a/build.gradle.kts b/build.gradle.kts -index 479d4e3b91e902e9b30d351aa65c8b079555d7e0..c12636f01b233c2436b7d5cdd4c04ac91389247b 100644 +index f3018c133440e2f6d1bcdf1adb060dfc6db1a866..d347f7eb79a7d0f0f8c8ec117885158cff1bacf5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts -@@ -27,6 +27,9 @@ dependencies { - api("net.kyori:adventure-text-serializer-legacy") - api("net.kyori:adventure-text-serializer-plain") +@@ -38,6 +38,9 @@ dependencies { + apiAndDocs("net.kyori:adventure-text-serializer-legacy") + apiAndDocs("net.kyori:adventure-text-serializer-plain") + implementation("org.ow2.asm:asm:9.1") + implementation("org.ow2.asm:asm-commons:9.1") diff --git a/patches/api/0068-Allow-plugins-to-use-SLF4J-for-logging.patch b/patches/api/0068-Allow-plugins-to-use-SLF4J-for-logging.patch index adaf87432..2e4760ca3 100644 --- a/patches/api/0068-Allow-plugins-to-use-SLF4J-for-logging.patch +++ b/patches/api/0068-Allow-plugins-to-use-SLF4J-for-logging.patch @@ -14,13 +14,13 @@ it without having to shade it in the plugin and going through several layers of logging abstraction. diff --git a/build.gradle.kts b/build.gradle.kts -index c12636f01b233c2436b7d5cdd4c04ac91389247b..d69d367a7527d677661ea56453b95417748b70a9 100644 +index 7cb2fd3adcbf425857ec3de03d009d4c0bd81dc3..689d470ebe2c7e25e4c87f6127978d1d283e55b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts -@@ -26,6 +26,8 @@ dependencies { - api("net.kyori:adventure-text-serializer-gson") - api("net.kyori:adventure-text-serializer-legacy") - api("net.kyori:adventure-text-serializer-plain") +@@ -37,6 +37,8 @@ dependencies { + apiAndDocs("net.kyori:adventure-text-serializer-gson") + apiAndDocs("net.kyori:adventure-text-serializer-legacy") + apiAndDocs("net.kyori:adventure-text-serializer-plain") + api("org.apache.logging.log4j:log4j-api:2.14.1") // Paper + api("org.slf4j:slf4j-api:1.7.30") // Paper diff --git a/patches/api/0198-Add-Player-Client-Options-API.patch b/patches/api/0198-Add-Player-Client-Options-API.patch index 19e56d2d7..be003da94 100644 --- a/patches/api/0198-Add-Player-Client-Options-API.patch +++ b/patches/api/0198-Add-Player-Client-Options-API.patch @@ -6,12 +6,14 @@ Subject: [PATCH] Add Player Client Options API diff --git a/src/main/java/com/destroystokyo/paper/ClientOption.java b/src/main/java/com/destroystokyo/paper/ClientOption.java new file mode 100644 -index 0000000000000000000000000000000000000000..9dad814cf51bc59ec5dfbf14474fea6557de38aa +index 0000000000000000000000000000000000000000..cedb51f9f3a9150035c2b44970a096448c441dd9 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/ClientOption.java -@@ -0,0 +1,33 @@ +@@ -0,0 +1,50 @@ +package com.destroystokyo.paper; + ++import net.kyori.adventure.translation.Translatable; ++import net.kyori.adventure.util.Index; +import org.jetbrains.annotations.NotNull; + +import org.bukkit.inventory.MainHand; @@ -36,11 +38,26 @@ index 0000000000000000000000000000000000000000..9dad814cf51bc59ec5dfbf14474fea65 + return type; + } + -+ public enum ChatVisibility { -+ FULL, -+ SYSTEM, -+ HIDDEN, -+ UNKNOWN ++ public enum ChatVisibility implements Translatable { ++ FULL("full"), ++ SYSTEM("system"), ++ HIDDEN("hidden"), ++ UNKNOWN("unknown"); ++ ++ public static Index NAMES = Index.create(ChatVisibility.class, chatVisibility -> chatVisibility.name); ++ private final String name; ++ ++ ChatVisibility(String name) { ++ this.name = name; ++ } ++ ++ @Override ++ public @NotNull String translationKey() { ++ if (this == UNKNOWN) { ++ throw new UnsupportedOperationException(this.name + " doesn't have a translation key"); ++ } ++ return "options.chat.visibility." + this.name; ++ } + } +} diff --git a/src/main/java/com/destroystokyo/paper/SkinParts.java b/src/main/java/com/destroystokyo/paper/SkinParts.java diff --git a/patches/api/0225-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch b/patches/api/0225-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch deleted file mode 100644 index 69eb848b6..000000000 --- a/patches/api/0225-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch +++ /dev/null @@ -1,127 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: MeFisto94 -Date: Tue, 11 Aug 2020 19:17:46 +0200 -Subject: [PATCH] Add a way to get translation keys for blocks, entities and - materials - - -diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java -index e7af2b346253cf05923998527bdc27b1180fa3b6..90047af133a2e2e0268f84f038e5c19dac48e3d2 100644 ---- a/src/main/java/org/bukkit/Material.java -+++ b/src/main/java/org/bukkit/Material.java -@@ -3989,6 +3989,16 @@ public enum Material implements Keyed { - } - return false; - } -+ -+ /** -+ * Return the translation key for the Material, so the client can translate it into the active -+ * locale when using a TranslatableComponent. -+ * @return the translation key -+ */ -+ @NotNull -+ public String getTranslationKey() { -+ return Bukkit.getUnsafe().getTranslationKey(this); -+ } - // Paper end - - /** -diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java -index e348034288c74ab80360086d71f0b7f61551df24..2d9264ffe0fee863f1b814952ef063daa7962d76 100644 ---- a/src/main/java/org/bukkit/UnsafeValues.java -+++ b/src/main/java/org/bukkit/UnsafeValues.java -@@ -101,5 +101,34 @@ public interface UnsafeValues { - byte[] serializeItem(ItemStack item); - - ItemStack deserializeItem(byte[] data); -+ -+ /** -+ * Return the translation key for the Material, so the client can translate it into the active -+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}. -+ * @return the translation key -+ */ -+ String getTranslationKey(Material mat); -+ -+ /** -+ * Return the translation key for the Block, so the client can translate it into the active -+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}. -+ * @return the translation key -+ */ -+ String getTranslationKey(org.bukkit.block.Block block); -+ -+ /** -+ * Return the translation key for the EntityType, so the client can translate it into the active -+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
-+ * This is null, when the EntityType isn't known to NMS (custom entities) -+ * @return the translation key -+ */ -+ String getTranslationKey(org.bukkit.entity.EntityType type); -+ -+ /** -+ * Return the translation key for the ItemStack, so the client can translate it into the active -+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
-+ * @return the translation key -+ */ -+ String getTranslationKey(ItemStack itemStack); - // Paper end - } -diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java -index 786b8011e98b2fe93cc2418d624f6350ede62d90..024deba760c41787190d20e4ac5c541920bb4991 100644 ---- a/src/main/java/org/bukkit/block/Block.java -+++ b/src/main/java/org/bukkit/block/Block.java -@@ -610,5 +610,13 @@ public interface Block extends Metadatable { - */ - @NotNull - com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup(); -+ -+ /** -+ * Return the translation key for the Block, so the client can translate it into the active -+ * locale when using a TranslatableComponent. -+ * @return the translation key -+ */ -+ @NotNull -+ String getTranslationKey(); - // Paper end - } -diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java -index 9be5371c7f398d0ec8241403661415ff40661067..99b0ed0a30846a2d744265ea8f279da90b31fa37 100644 ---- a/src/main/java/org/bukkit/entity/EntityType.java -+++ b/src/main/java/org/bukkit/entity/EntityType.java -@@ -419,4 +419,15 @@ public enum EntityType implements Keyed { - public boolean isAlive() { - return living; - } -+ -+ /** -+ * Return the translation key for the EntityType, so the client can translate it into the active -+ * locale when using a TranslatableComponent.
-+ * This is null, when the EntityType isn't known to NMS (custom entities) -+ * @return the translation key -+ */ -+ @Nullable -+ public String getTranslationKey() { -+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); -+ } - } -diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index b80ef2e5c23764ee68f809268185492bf5577913..f2c8ffaf8b62707e7806012d41f9cd7be1638ed9 100644 ---- a/src/main/java/org/bukkit/inventory/ItemStack.java -+++ b/src/main/java/org/bukkit/inventory/ItemStack.java -@@ -852,5 +852,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor - ItemMeta itemMeta = getItemMeta(); - return itemMeta != null && itemMeta.hasItemFlag(flag); - } -+ -+ /** -+ * Gets the translation key for this itemstack. -+ * This is not the same as getting the translation key -+ * for the material of this itemstack. -+ * -+ * @return the translation key -+ */ -+ @NotNull -+ public String getTranslationKey() { -+ return Bukkit.getUnsafe().getTranslationKey(this); -+ } - // Paper end - } diff --git a/patches/api/0225-Add-methods-to-get-translation-keys.patch b/patches/api/0225-Add-methods-to-get-translation-keys.patch new file mode 100644 index 000000000..39ae6ef99 --- /dev/null +++ b/patches/api/0225-Add-methods-to-get-translation-keys.patch @@ -0,0 +1,355 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Tue, 11 Aug 2020 19:17:46 +0200 +Subject: [PATCH] Add methods to get translation keys + +Co-authored-by: MeFisto94 + +diff --git a/src/main/java/org/bukkit/Difficulty.java b/src/main/java/org/bukkit/Difficulty.java +index 3f6cbefc2b1414ba2dad709e79288013b3ef73be..122884098f08c9aa5e144876746b5ce4e8f1a4b6 100644 +--- a/src/main/java/org/bukkit/Difficulty.java ++++ b/src/main/java/org/bukkit/Difficulty.java +@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable; + /** + * Represents the various difficulty levels that are available. + */ +-public enum Difficulty { ++public enum Difficulty implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations + /** + * Players regain health over time, hostile mobs don't spawn, the hunger + * bar does not deplete. +@@ -51,6 +51,12 @@ public enum Difficulty { + return value; + } + ++ // Paper start ++ @Override ++ public @org.jetbrains.annotations.NotNull String translationKey() { ++ return "options.difficulty." + this.name().toLowerCase(java.util.Locale.ENGLISH); ++ } ++ // Paper end + /** + * Gets the Difficulty represented by the specified value + * +diff --git a/src/main/java/org/bukkit/FireworkEffect.java b/src/main/java/org/bukkit/FireworkEffect.java +index 4a97e73ce59c0eee77661967f1d3ac23508aae3e..d543b2b6aa131efec9b978d0b71a228f79a31f9a 100644 +--- a/src/main/java/org/bukkit/FireworkEffect.java ++++ b/src/main/java/org/bukkit/FireworkEffect.java +@@ -18,28 +18,44 @@ public final class FireworkEffect implements ConfigurationSerializable { + /** + * The type or shape of the effect. + */ +- public enum Type { ++ public enum Type implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations + /** + * A small ball effect. + */ +- BALL, ++ BALL("small_ball"), // Paper - add name + /** + * A large ball effect. + */ +- BALL_LARGE, ++ BALL_LARGE("large_ball"), // Paper - add name + /** + * A star-shaped effect. + */ +- STAR, ++ STAR("star"), // Paper - add name + /** + * A burst effect. + */ +- BURST, ++ BURST("burst"), // Paper - add name + /** + * A creeper-face effect. + */ +- CREEPER, ++ CREEPER("creeper"), // Paper - add name + ; ++ // Paper start ++ /** ++ * The name map. ++ */ ++ public static final net.kyori.adventure.util.Index NAMES = net.kyori.adventure.util.Index.create(Type.class, type -> type.name); ++ private final String name; ++ ++ Type(final String name) { ++ this.name = name; ++ } ++ ++ @Override ++ public @NotNull String translationKey() { ++ return "item.minecraft.firework_star.shape." + this.name; ++ } ++ // Paper end + } + + /** +diff --git a/src/main/java/org/bukkit/GameRule.java b/src/main/java/org/bukkit/GameRule.java +index 442db40bc6ea2cfd2f724807544a080bb62bd8c5..d3365e44e64c2e72416d3a50be20ada79320ba2a 100644 +--- a/src/main/java/org/bukkit/GameRule.java ++++ b/src/main/java/org/bukkit/GameRule.java +@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable; + * + * @param type of rule (Boolean or Integer) + */ +-public final class GameRule { ++public final class GameRule implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations + + private static Map> gameRules = new HashMap<>(); + // Boolean rules +@@ -283,4 +283,11 @@ public final class GameRule { + public static GameRule[] values() { + return gameRules.values().toArray(new GameRule[gameRules.size()]); + } ++ ++ // Paper start ++ @Override ++ public @NotNull String translationKey() { ++ return "gamerule." + this.name; ++ } ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java +index e7af2b346253cf05923998527bdc27b1180fa3b6..2e98000d74bcba927d4b126cb3de668b63d67ceb 100644 +--- a/src/main/java/org/bukkit/Material.java ++++ b/src/main/java/org/bukkit/Material.java +@@ -100,7 +100,7 @@ import org.jetbrains.annotations.Nullable; + * An enum of all material IDs accepted by the official server and client + */ + @SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"}) // Paper +-public enum Material implements Keyed { ++public enum Material implements Keyed, net.kyori.adventure.translation.Translatable { // Paper + // + AIR(9648, 0), + STONE(22948), +@@ -3989,6 +3989,23 @@ public enum Material implements Keyed { + } + return false; + } ++ ++ /** ++ * Return the translation key for the Material, so the client can translate it into the active ++ * locale when using a TranslatableComponent. ++ * @return the translation key ++ * @deprecated use {@link #translationKey()} ++ */ ++ @NotNull ++ @Deprecated ++ public String getTranslationKey() { ++ return this.translationKey(); ++ } ++ ++ @Override ++ public @NotNull String translationKey() { ++ return Bukkit.getUnsafe().getTranslationKey(this); ++ } + // Paper end + + /** +diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java +index e348034288c74ab80360086d71f0b7f61551df24..2d9264ffe0fee863f1b814952ef063daa7962d76 100644 +--- a/src/main/java/org/bukkit/UnsafeValues.java ++++ b/src/main/java/org/bukkit/UnsafeValues.java +@@ -101,5 +101,34 @@ public interface UnsafeValues { + byte[] serializeItem(ItemStack item); + + ItemStack deserializeItem(byte[] data); ++ ++ /** ++ * Return the translation key for the Material, so the client can translate it into the active ++ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}. ++ * @return the translation key ++ */ ++ String getTranslationKey(Material mat); ++ ++ /** ++ * Return the translation key for the Block, so the client can translate it into the active ++ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}. ++ * @return the translation key ++ */ ++ String getTranslationKey(org.bukkit.block.Block block); ++ ++ /** ++ * Return the translation key for the EntityType, so the client can translate it into the active ++ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
++ * This is null, when the EntityType isn't known to NMS (custom entities) ++ * @return the translation key ++ */ ++ String getTranslationKey(org.bukkit.entity.EntityType type); ++ ++ /** ++ * Return the translation key for the ItemStack, so the client can translate it into the active ++ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
++ * @return the translation key ++ */ ++ String getTranslationKey(ItemStack itemStack); + // Paper end + } +diff --git a/src/main/java/org/bukkit/attribute/Attribute.java b/src/main/java/org/bukkit/attribute/Attribute.java +index 13eac9ad2c1672051635d1c35cc49239252e7a61..107e36ef02a9481954bd770ce9a55a0b1e84be7a 100644 +--- a/src/main/java/org/bukkit/attribute/Attribute.java ++++ b/src/main/java/org/bukkit/attribute/Attribute.java +@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; + /** + * Types of attributes which may be present on an {@link Attributable}. + */ +-public enum Attribute implements Keyed { ++public enum Attribute implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations + + /** + * Maximum health of an Entity. +@@ -73,4 +73,10 @@ public enum Attribute implements Keyed { + public NamespacedKey getKey() { + return key; + } ++ // Paper start ++ @Override ++ public @NotNull String translationKey() { ++ return "attribute.name." + this.key.getKey(); ++ } ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java +index 786b8011e98b2fe93cc2418d624f6350ede62d90..e7957ec1727f7483d6d75b9e94333f06dc6d1da2 100644 +--- a/src/main/java/org/bukkit/block/Block.java ++++ b/src/main/java/org/bukkit/block/Block.java +@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable; + * (i.e. lighting and power) may not be able to be safely accessed during world + * generation when used in cases like BlockPhysicsEvent!!!! + */ +-public interface Block extends Metadatable { ++public interface Block extends Metadatable, net.kyori.adventure.translation.Translatable { // Paper - translatable + + /** + * Gets the metadata for this block +@@ -610,5 +610,15 @@ public interface Block extends Metadatable { + */ + @NotNull + com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup(); ++ ++ /** ++ * Return the translation key for the Block, so the client can translate it into the active ++ * locale when using a TranslatableComponent. ++ * @return the translation key ++ * @deprecated use {@link #translationKey()} ++ */ ++ @NotNull ++ @Deprecated ++ String getTranslationKey(); + // Paper end + } +diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java +index 8eb0497c81744874809ebc4bc2e28b128e66a926..b277034fee2d4f38c40713842d14a8f6dde757aa 100644 +--- a/src/main/java/org/bukkit/enchantments/Enchantment.java ++++ b/src/main/java/org/bukkit/enchantments/Enchantment.java +@@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable; + /** + * The various type of enchantments that may be added to armour or weapons + */ +-public abstract class Enchantment implements Keyed { ++public abstract class Enchantment implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations + /** + * Provides protection against environmental damage + */ +diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java +index 4d5f0837bd0e02a30c943d8969fb6b13452322e0..a39f9c078f42451bd122f3e3729d10ca299bee5f 100644 +--- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java ++++ b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java +@@ -69,5 +69,10 @@ public class EnchantmentWrapper extends Enchantment { + public net.kyori.adventure.text.Component displayName(int level) { + return getEnchantment().displayName(level); + } ++ ++ @Override ++ public @NotNull String translationKey() { ++ return getEnchantment().translationKey(); ++ } + // Paper end + } +diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java +index 9be5371c7f398d0ec8241403661415ff40661067..d36d314383713bac3b11f18d95b0809dce3cd6e0 100644 +--- a/src/main/java/org/bukkit/entity/EntityType.java ++++ b/src/main/java/org/bukkit/entity/EntityType.java +@@ -20,7 +20,7 @@ import org.jetbrains.annotations.Contract; + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; + +-public enum EntityType implements Keyed { ++public enum EntityType implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - translatable + + // These strings MUST match the strings in nms.EntityTypes and are case sensitive. + /** +@@ -419,4 +419,27 @@ public enum EntityType implements Keyed { + public boolean isAlive() { + return living; + } ++ // Paper start ++ /** ++ * Return the translation key for the EntityType, so the client can translate it into the active ++ * locale when using a TranslatableComponent.
++ * This is null, when the EntityType isn't known to NMS (custom entities) ++ * @return the translation key ++ * @deprecated use {@link #translationKey()} ++ */ ++ @Deprecated ++ @Nullable ++ public String getTranslationKey() { ++ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); ++ } ++ ++ /** ++ * @throws IllegalArgumentException if the entity does not have a translation key (is probably a custom entity) ++ */ ++ @Override ++ public @NotNull String translationKey() { ++ Preconditions.checkArgument(this != UNKNOWN, "UNKNOWN entities do not have translation keys"); ++ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); ++ } ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java +index b80ef2e5c23764ee68f809268185492bf5577913..e6eab5d8ca3fea8d2e0ccc1cd1c1a7a110b589db 100644 +--- a/src/main/java/org/bukkit/inventory/ItemStack.java ++++ b/src/main/java/org/bukkit/inventory/ItemStack.java +@@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable; + * use this class to encapsulate Materials for which {@link Material#isItem()} + * returns false. + */ +-public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyori.adventure.text.event.HoverEventSource { // Paper ++public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyori.adventure.text.event.HoverEventSource, net.kyori.adventure.translation.Translatable { // Paper + private Material type = Material.AIR; + private int amount = 0; + private MaterialData data = null; +@@ -852,5 +852,30 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor + ItemMeta itemMeta = getItemMeta(); + return itemMeta != null && itemMeta.hasItemFlag(flag); + } ++ ++ /** ++ * Gets the translation key for this itemstack. ++ * This is not the same as getting the translation key ++ * for the material of this itemstack. ++ * ++ * @return the translation key ++ * @deprecated use {@link #translationKey()} ++ */ ++ @NotNull ++ @Deprecated ++ public String getTranslationKey() { ++ return this.translationKey(); ++ } ++ ++ /** ++ * {@inheritDoc} ++ *

++ * This is not the same as getting the translation key ++ * for the material of this itemstack. ++ */ ++ @Override ++ public @NotNull String translationKey() { ++ return Bukkit.getUnsafe().getTranslationKey(this); ++ } + // Paper end + } diff --git a/patches/api/0238-Add-Destroy-Speed-API.patch b/patches/api/0238-Add-Destroy-Speed-API.patch index 1b87616b5..1dda5738d 100644 --- a/patches/api/0238-Add-Destroy-Speed-API.patch +++ b/patches/api/0238-Add-Destroy-Speed-API.patch @@ -6,12 +6,12 @@ Subject: [PATCH] Add Destroy Speed API Co-authored-by: Jake Potrebic diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java -index 024deba760c41787190d20e4ac5c541920bb4991..e759a03ccf7b341db36f455879e0004a6d6d4d07 100644 +index e7957ec1727f7483d6d75b9e94333f06dc6d1da2..cc570b31e817433d6e90990277cce283ee5d449e 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java -@@ -618,5 +618,29 @@ public interface Block extends Metadatable { - */ +@@ -620,5 +620,29 @@ public interface Block extends Metadatable, net.kyori.adventure.translation.Tran @NotNull + @Deprecated String getTranslationKey(); + + /** diff --git a/patches/api/0249-Additional-Block-Material-API-s.patch b/patches/api/0249-Additional-Block-Material-API-s.patch index c16d0c6a6..9187241cd 100644 --- a/patches/api/0249-Additional-Block-Material-API-s.patch +++ b/patches/api/0249-Additional-Block-Material-API-s.patch @@ -9,10 +9,10 @@ process to do this in the Bukkit API Adds API for buildable, replaceable, burnable too. diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java -index e759a03ccf7b341db36f455879e0004a6d6d4d07..b3c127a3d4c554c08e500497a54755e626342dd3 100644 +index 9583c2b91f7f50c9c377d3aac30001f86ad95461..9f5a68cb91ec10721031607c83621cc31db5d7b0 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java -@@ -428,6 +428,42 @@ public interface Block extends Metadatable { +@@ -428,6 +428,42 @@ public interface Block extends Metadatable, net.kyori.adventure.translation.Tran */ boolean isLiquid(); diff --git a/patches/api/0277-Cache-the-result-of-Material-isBlock.patch b/patches/api/0277-Cache-the-result-of-Material-isBlock.patch index c036dea12..f84188a28 100644 --- a/patches/api/0277-Cache-the-result-of-Material-isBlock.patch +++ b/patches/api/0277-Cache-the-result-of-Material-isBlock.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Cache the result of Material#isBlock diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java -index 90047af133a2e2e0268f84f038e5c19dac48e3d2..1edfa68a52f988b34652e98faffeabde4f0cc99a 100644 +index 2e98000d74bcba927d4b126cb3de668b63d67ceb..bfcc4c605e92d3c703ca620bcfa206d99c7bb512 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java -@@ -3933,6 +3933,7 @@ public enum Material implements Keyed { +@@ -3933,6 +3933,7 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata public final Class data; private final boolean legacy; private final NamespacedKey key; @@ -16,7 +16,7 @@ index 90047af133a2e2e0268f84f038e5c19dac48e3d2..1edfa68a52f988b34652e98faffeabde private Material(final int id) { this(id, 64); -@@ -4130,6 +4131,11 @@ public enum Material implements Keyed { +@@ -4137,6 +4138,11 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata * @return true if this material is a block */ public boolean isBlock() { @@ -28,7 +28,7 @@ index 90047af133a2e2e0268f84f038e5c19dac48e3d2..1edfa68a52f988b34652e98faffeabde switch (this) { // case ACACIA_BUTTON: -@@ -5211,6 +5217,7 @@ public enum Material implements Keyed { +@@ -5218,6 +5224,7 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata static { for (Material material : values()) { BY_NAME.put(material.name(), material); diff --git a/patches/api/0281-Add-Block-isValidTool.patch b/patches/api/0281-Add-Block-isValidTool.patch index 257cf003a..1bc49df4a 100644 --- a/patches/api/0281-Add-Block-isValidTool.patch +++ b/patches/api/0281-Add-Block-isValidTool.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add Block#isValidTool diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java -index b3c127a3d4c554c08e500497a54755e626342dd3..ca488173a20bcf3427906f0a6548f06a97c9dc36 100644 +index 9f5a68cb91ec10721031607c83621cc31db5d7b0..c521f2bb830242b57c408ba3aa9e63f893df2f07 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java -@@ -219,6 +219,15 @@ public interface Block extends Metadatable { +@@ -219,6 +219,15 @@ public interface Block extends Metadatable, net.kyori.adventure.translation.Tran public static int getBlockKeyZ(long packed) { return (int) ((packed << 10) >> 37); } diff --git a/patches/api/0284-Item-Rarity-API.patch b/patches/api/0284-Item-Rarity-API.patch index d177f112f..901152eb7 100644 --- a/patches/api/0284-Item-Rarity-API.patch +++ b/patches/api/0284-Item-Rarity-API.patch @@ -39,11 +39,11 @@ index 0000000000000000000000000000000000000000..74ef8395cc040ce488c2acaa416db202 + } +} diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java -index 1edfa68a52f988b34652e98faffeabde4f0cc99a..b83c504be7a8d0905d401b421c4274a58f70866c 100644 +index bfcc4c605e92d3c703ca620bcfa206d99c7bb512..f1e5cb5e490d10b76f8f9bab8cfa00d2c24c0287 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java -@@ -4000,6 +4000,17 @@ public enum Material implements Keyed { - public String getTranslationKey() { +@@ -4007,6 +4007,17 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata + public @NotNull String translationKey() { return Bukkit.getUnsafe().getTranslationKey(this); } + @@ -88,11 +88,11 @@ index 84eda68281c6c6968d95b1313a33696c3a9980d4..bcd10b2c9255d778b678310febf19373 // Paper end } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index f2c8ffaf8b62707e7806012d41f9cd7be1638ed9..0cb944652dc6d77a2cbeaf0d420fb694924b5b60 100644 +index e6eab5d8ca3fea8d2e0ccc1cd1c1a7a110b589db..f46aeb59a5a1bde4011cd1d933afcc19c7d1b3bd 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java -@@ -864,5 +864,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor - public String getTranslationKey() { +@@ -877,5 +877,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor + public @NotNull String translationKey() { return Bukkit.getUnsafe().getTranslationKey(this); } + diff --git a/patches/api/0304-ItemStack-repair-check-API.patch b/patches/api/0304-ItemStack-repair-check-API.patch index ac9f88171..a42235e46 100644 --- a/patches/api/0304-ItemStack-repair-check-API.patch +++ b/patches/api/0304-ItemStack-repair-check-API.patch @@ -26,10 +26,10 @@ index 6dbd520182b1e7713a68baad09b7f613424ef619..e504567cf755557be8511f2c93c17157 * Returns the server's protocol version. * diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index e8f4543131d293beaa1fe9b44e2e98f27bc5dc79..b4d55e0d5e605cb6980b555acd42d16e1e65c196 100644 +index f46aeb59a5a1bde4011cd1d933afcc19c7d1b3bd..86bd9f14de5c1ff3d797955be1af56e5efcac884 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java -@@ -874,5 +874,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor +@@ -887,5 +887,27 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor public io.papermc.paper.inventory.ItemRarity getRarity() { return Bukkit.getUnsafe().getItemStackRarity(this); } diff --git a/patches/api/0305-More-Enchantment-API.patch b/patches/api/0305-More-Enchantment-API.patch index dda68575c..02284154d 100644 --- a/patches/api/0305-More-Enchantment-API.patch +++ b/patches/api/0305-More-Enchantment-API.patch @@ -35,10 +35,10 @@ index 0000000000000000000000000000000000000000..e6a40c1fcea761bd66743b50e3da3d14 + } +} diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java -index 8eb0497c81744874809ebc4bc2e28b128e66a926..799813410f40589ba1d7d530a47d87f609764705 100644 +index b277034fee2d4f38c40713842d14a8f6dde757aa..05f516eb488124a86dcd31a52ffa1f4b847545ac 100644 --- a/src/main/java/org/bukkit/enchantments/Enchantment.java +++ b/src/main/java/org/bukkit/enchantments/Enchantment.java -@@ -306,6 +306,46 @@ public abstract class Enchantment implements Keyed { +@@ -306,6 +306,46 @@ public abstract class Enchantment implements Keyed, net.kyori.adventure.translat * @return the name of the enchantment with {@code level} applied */ public abstract @NotNull net.kyori.adventure.text.Component displayName(int level); @@ -86,12 +86,12 @@ index 8eb0497c81744874809ebc4bc2e28b128e66a926..799813410f40589ba1d7d530a47d87f6 @Override diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java -index 4d5f0837bd0e02a30c943d8969fb6b13452322e0..ca097db904db96e81c0ea4b06b445a13e9333cfe 100644 +index a39f9c078f42451bd122f3e3729d10ca299bee5f..5f42a9c0c43ced10b754170d7c83793a99fce81b 100644 --- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java +++ b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java -@@ -69,5 +69,32 @@ public class EnchantmentWrapper extends Enchantment { - public net.kyori.adventure.text.Component displayName(int level) { - return getEnchantment().displayName(level); +@@ -74,5 +74,32 @@ public class EnchantmentWrapper extends Enchantment { + public @NotNull String translationKey() { + return getEnchantment().translationKey(); } + + @Override diff --git a/patches/api/0311-Attributes-API-for-item-defaults.patch b/patches/api/0311-Attributes-API-for-item-defaults.patch index 8dbfaf230..51f936770 100644 --- a/patches/api/0311-Attributes-API-for-item-defaults.patch +++ b/patches/api/0311-Attributes-API-for-item-defaults.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Attributes API for item defaults diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java -index b83c504be7a8d0905d401b421c4274a58f70866c..08eb0cc65308c5d4078814a0bccf84142737e87a 100644 +index f1e5cb5e490d10b76f8f9bab8cfa00d2c24c0287..ed6dfb28f8f434680fc8eacbe49a9d0b6cf9be83 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java -@@ -4011,6 +4011,19 @@ public enum Material implements Keyed { +@@ -4018,6 +4018,19 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata public io.papermc.paper.inventory.ItemRarity getItemRarity() { return Bukkit.getUnsafe().getItemRarity(this); } diff --git a/patches/server/0413-Implement-Player-Client-Options-API.patch b/patches/server/0413-Implement-Player-Client-Options-API.patch index bc18e14f6..6877866b5 100644 --- a/patches/server/0413-Implement-Player-Client-Options-API.patch +++ b/patches/server/0413-Implement-Player-Client-Options-API.patch @@ -125,3 +125,28 @@ index bef6868a33144e0e4f44bba1ba13d6310e291523..a3951039eeb1f5d3529213ca02d11c97 // Paper end @Override +diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java +new file mode 100644 +index 0000000000000000000000000000000000000000..6cd015dc5a2e012ac827c2b2d9aa5542b0591afb +--- /dev/null ++++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java +@@ -0,0 +1,19 @@ ++package io.papermc.paper.world; ++ ++import com.destroystokyo.paper.ClientOption; ++import net.minecraft.network.chat.TranslatableComponent; ++import net.minecraft.world.entity.player.ChatVisiblity; ++import org.bukkit.Difficulty; ++import org.junit.Assert; ++import org.junit.Test; ++ ++public class TranslationKeyTest { ++ ++ @Test ++ public void testChatVisibilityKeys() { ++ for (ClientOption.ChatVisibility chatVisibility : ClientOption.ChatVisibility.values()) { ++ if (chatVisibility == ClientOption.ChatVisibility.UNKNOWN) continue; ++ Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey()); ++ } ++ } ++} diff --git a/patches/server/0521-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch b/patches/server/0521-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch deleted file mode 100644 index f6f6acbb2..000000000 --- a/patches/server/0521-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch +++ /dev/null @@ -1,65 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: MeFisto94 -Date: Tue, 11 Aug 2020 19:16:09 +0200 -Subject: [PATCH] Add a way to get translation keys for blocks, entities and - materials - - -diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index d33c56ac47884ebcce98494377af26cc77f8d5f6..5e5465b8d9b4187a11e7952515ef040ab997d902 100644 ---- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -772,5 +772,10 @@ public class CraftBlock implements Block { - public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() { - return new com.destroystokyo.paper.block.CraftBlockSoundGroup(getNMS().getBlock().defaultBlockState().getSoundType()); - } -+ -+ @Override -+ public String getTranslationKey() { -+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); -+ } - // Paper end - } -diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 6b79b1ea43b713105f37de517019c033477f9835..135749c789d44f0af1ad11ccd1b208f1e28853eb 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -43,6 +43,7 @@ import org.bukkit.Registry; - import org.bukkit.UnsafeValues; - import org.bukkit.advancement.Advancement; - import org.bukkit.block.data.BlockData; -+import org.bukkit.craftbukkit.block.CraftBlock; - import org.bukkit.craftbukkit.block.data.CraftBlockData; - import org.bukkit.craftbukkit.inventory.CraftItemStack; - import org.bukkit.craftbukkit.legacy.CraftLegacy; -@@ -418,6 +419,30 @@ public final class CraftMagicNumbers implements UnsafeValues { - throw new RuntimeException(); - } - } -+ -+ @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/patches/server/0521-Add-methods-to-get-translation-keys.patch b/patches/server/0521-Add-methods-to-get-translation-keys.patch new file mode 100644 index 000000000..d8cb4bd7c --- /dev/null +++ b/patches/server/0521-Add-methods-to-get-translation-keys.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Tue, 11 Aug 2020 19:16:09 +0200 +Subject: [PATCH] Add methods to get translation keys + +Co-authored-by: MeFisto94 + +diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +index d33c56ac47884ebcce98494377af26cc77f8d5f6..a1cac393ece249e5f18fbc0db6a7ad9f14dfb3a1 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +@@ -772,5 +772,15 @@ public class CraftBlock implements Block { + public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() { + return new com.destroystokyo.paper.block.CraftBlockSoundGroup(getNMS().getBlock().defaultBlockState().getSoundType()); + } ++ ++ @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 +index eb99e0c2462a2d1ab4508a5c3f1580b6e31d7465..c536eceef3365a7b726cd970df345ba1d055207d 100644 +--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java ++++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +@@ -192,6 +192,11 @@ public class CraftEnchantment extends Enchantment { + 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 +index 6b79b1ea43b713105f37de517019c033477f9835..fedbe226c549b103b957beb9feea34350e6220be 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +@@ -418,6 +418,30 @@ public final class CraftMagicNumbers implements UnsafeValues { + throw new RuntimeException(); + } + } ++ ++ @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 +index 6cd015dc5a2e012ac827c2b2d9aa5542b0591afb..b2e73df86683b88c83349b6d13456f5b051ac5d5 100644 +--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java ++++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java +@@ -7,7 +7,7 @@ import org.bukkit.Difficulty; + import org.junit.Assert; + import org.junit.Test; + +-public class TranslationKeyTest { ++public class TranslationKeyTest extends org.bukkit.support.AbstractTestingBase { + + @Test + public void testChatVisibilityKeys() { +@@ -16,4 +16,32 @@ public class TranslationKeyTest { + 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()) { ++ Assert.assertEquals(bukkitDifficulty + "'s translation key doesn't match", ((TranslatableComponent) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName()).getKey(), bukkitDifficulty.translationKey()); ++ } ++ } ++ ++ @Test ++ public void testGameruleKeys() { ++ for (org.bukkit.GameRule rule : org.bukkit.GameRule.values()) { ++ Assert.assertEquals(rule.getName() + "'s translation doesn't match", org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey()); ++ } ++ } ++ ++ @Test ++ public void testAttributeKeys() { ++ for (org.bukkit.attribute.Attribute attribute : org.bukkit.attribute.Attribute.values()) { ++ Assert.assertEquals("translation key mismatch for " + attribute, org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute).getDescriptionId(), attribute.translationKey()); ++ } ++ } ++ ++ @Test ++ public void testFireworkEffectType() { ++ for (org.bukkit.FireworkEffect.Type type : org.bukkit.FireworkEffect.Type.values()) { ++ 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)); ++ } ++ } + } diff --git a/patches/server/0529-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch b/patches/server/0529-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch index a6bffc693..a9ee6d23f 100644 --- a/patches/server/0529-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch +++ b/patches/server/0529-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch @@ -21,10 +21,10 @@ index 94a8dabc3dc63e426e093adb4336691161f55d68..dc89e1ed7fa19e5d9f80bb31377b634c + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 135749c789d44f0af1ad11ccd1b208f1e28853eb..8c1ac43cf5510a14d1d41ec45d189ad9711024da 100644 +index fedbe226c549b103b957beb9feea34350e6220be..f212ca8756782b12a746f86933f46b747481c87e 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -443,6 +443,10 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -442,6 +442,10 @@ public final class CraftMagicNumbers implements UnsafeValues { net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); return nmsItemStack.getItem().getDescriptionId(nmsItemStack); } diff --git a/patches/server/0549-Fix-client-lag-on-advancement-loading.patch b/patches/server/0549-Fix-client-lag-on-advancement-loading.patch index 9705bfe07..f66ea6fcf 100644 --- a/patches/server/0549-Fix-client-lag-on-advancement-loading.patch +++ b/patches/server/0549-Fix-client-lag-on-advancement-loading.patch @@ -15,10 +15,10 @@ manually reload the advancement data for all players, which normally takes place as a part of the datapack reloading. diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 8c1ac43cf5510a14d1d41ec45d189ad9711024da..58193c1f62f2ef68e6e0b99aa6008b00b833ee42 100644 +index f212ca8756782b12a746f86933f46b747481c87e..c0a08c3ac18b3ec0964c61c90df3263c50ece83d 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -307,7 +307,13 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -306,7 +306,13 @@ public final class CraftMagicNumbers implements UnsafeValues { Bukkit.getLogger().log(Level.SEVERE, "Error saving advancement " + key, ex); } diff --git a/patches/server/0558-Add-Destroy-Speed-API.patch b/patches/server/0558-Add-Destroy-Speed-API.patch index c9cf4dffc..a884675e2 100644 --- a/patches/server/0558-Add-Destroy-Speed-API.patch +++ b/patches/server/0558-Add-Destroy-Speed-API.patch @@ -6,11 +6,11 @@ Subject: [PATCH] Add Destroy Speed API Co-authored-by: Jake Potrebic diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index 078c4e9e4a2ff9009242f44eeec68421b8d99ac0..24f2eba1c39abce074740d928640dd0dd30f27db 100644 +index d936a86d5a95b4502944f9e76cc86d395c6dd4b8..9ec29486316012931e4547625801049eab806209 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -777,5 +777,23 @@ public class CraftBlock implements Block { - public String getTranslationKey() { +@@ -782,5 +782,23 @@ public class CraftBlock implements Block { + public String translationKey() { return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); } + diff --git a/patches/server/0609-Added-Vanilla-Entity-Tags.patch b/patches/server/0609-Added-Vanilla-Entity-Tags.patch index 8f54ff350..202905570 100644 --- a/patches/server/0609-Added-Vanilla-Entity-Tags.patch +++ b/patches/server/0609-Added-Vanilla-Entity-Tags.patch @@ -55,10 +55,10 @@ index 192c8651882286d6e1d2c7be021d2bd4d60e88cb..016299cc9e7327f5b29fd51df571fa23 throw new IllegalArgumentException(); } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 58193c1f62f2ef68e6e0b99aa6008b00b833ee42..21c1d6b7e97a1dee372ea1fa8eb95a712db63418 100644 +index c0a08c3ac18b3ec0964c61c90df3263c50ece83d..eb06ca21a964de3f3d6712387b72e8994f1f03bd 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -116,8 +116,17 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -115,8 +115,17 @@ public final class CraftMagicNumbers implements UnsafeValues { private static final Map MATERIAL_ITEM = new HashMap<>(); private static final Map MATERIAL_BLOCK = new HashMap<>(); private static final Map MATERIAL_FLUID = new HashMap<>(); @@ -76,7 +76,7 @@ index 58193c1f62f2ef68e6e0b99aa6008b00b833ee42..21c1d6b7e97a1dee372ea1fa8eb95a71 for (Block block : net.minecraft.core.Registry.BLOCK) { BLOCK_MATERIAL.put(block, Material.getMaterial(net.minecraft.core.Registry.BLOCK.getKey(block).getPath().toUpperCase(Locale.ROOT))); } -@@ -183,6 +192,14 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -182,6 +191,14 @@ public final class CraftMagicNumbers implements UnsafeValues { public static ResourceLocation key(Material mat) { return CraftNamespacedKey.toMinecraft(mat.getKey()); } diff --git a/patches/server/0639-Add-Block-isValidTool.patch b/patches/server/0639-Add-Block-isValidTool.patch index 5aae2e2ef..473b688fa 100644 --- a/patches/server/0639-Add-Block-isValidTool.patch +++ b/patches/server/0639-Add-Block-isValidTool.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add Block#isValidTool diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -index 3386fa8eaa890a7353ee152f27a313ee358ecb52..96712906e64e9a0d1325afd55156921f20709988 100644 +index 64589df0a05ddf023f66cdf2cf995a8a5ade2ca8..88bfa152681282b7bbd2e6f2d147920ce23abaf1 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java -@@ -814,5 +814,9 @@ public class CraftBlock implements Block { +@@ -819,5 +819,9 @@ public class CraftBlock implements Block { } return speed; } diff --git a/patches/server/0643-Item-Rarity-API.patch b/patches/server/0643-Item-Rarity-API.patch index 2ed39999c..febb7dfe3 100644 --- a/patches/server/0643-Item-Rarity-API.patch +++ b/patches/server/0643-Item-Rarity-API.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Item Rarity API diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 21c1d6b7e97a1dee372ea1fa8eb95a712db63418..e606c246f486eb0775a577ee7ccc87a8a4f313a2 100644 +index eb06ca21a964de3f3d6712387b72e8994f1f03bd..8ff6d0deb3532515cecdab1f50b8558ef7603f53 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -470,6 +470,20 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -469,6 +469,20 @@ public final class CraftMagicNumbers implements UnsafeValues { public int nextEntityId() { return net.minecraft.world.entity.Entity.nextEntityId(); } diff --git a/patches/server/0651-Expose-protocol-version.patch b/patches/server/0651-Expose-protocol-version.patch index d782c87f4..dbf1a7b69 100644 --- a/patches/server/0651-Expose-protocol-version.patch +++ b/patches/server/0651-Expose-protocol-version.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Expose protocol version diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index e606c246f486eb0775a577ee7ccc87a8a4f313a2..7cf7e838867aed87fec2319cd84be7466b57e09f 100644 +index 8ff6d0deb3532515cecdab1f50b8558ef7603f53..719a4811d9a9a754f7893c595d09187c494bbbae 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -484,6 +484,11 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -483,6 +483,11 @@ public final class CraftMagicNumbers implements UnsafeValues { public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) { return io.papermc.paper.inventory.ItemRarity.values()[getItem(itemStack.getType()).getRarity(CraftItemStack.asNMSCopy(itemStack)).ordinal()]; } diff --git a/patches/server/0685-ItemStack-repair-check-API.patch b/patches/server/0685-ItemStack-repair-check-API.patch index 301006886..32604aaea 100644 --- a/patches/server/0685-ItemStack-repair-check-API.patch +++ b/patches/server/0685-ItemStack-repair-check-API.patch @@ -5,10 +5,10 @@ Subject: [PATCH] ItemStack repair check API diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 7cf7e838867aed87fec2319cd84be7466b57e09f..24f5f6c7b1ca21515cdeb053f8e1f56004c800d0 100644 +index 719a4811d9a9a754f7893c595d09187c494bbbae..85a0639e8e65f4d085f605f09ca04a706a631d56 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -485,6 +485,14 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -484,6 +484,14 @@ public final class CraftMagicNumbers implements UnsafeValues { return io.papermc.paper.inventory.ItemRarity.values()[getItem(itemStack.getType()).getRarity(CraftItemStack.asNMSCopy(itemStack)).ordinal()]; } diff --git a/patches/server/0686-More-Enchantment-API.patch b/patches/server/0686-More-Enchantment-API.patch index db4987ddb..2b7991e87 100644 --- a/patches/server/0686-More-Enchantment-API.patch +++ b/patches/server/0686-More-Enchantment-API.patch @@ -5,7 +5,7 @@ Subject: [PATCH] More Enchantment API diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java -index eb99e0c2462a2d1ab4508a5c3f1580b6e31d7465..227aeb002d8c23b6dba0af268f0a3297454cb4e3 100644 +index c536eceef3365a7b726cd970df345ba1d055207d..11c1eb0e0bc326b28dc0cab16f67c413cc52e98c 100644 --- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -71,7 +71,7 @@ public class CraftEnchantment extends Enchantment { @@ -17,9 +17,9 @@ index eb99e0c2462a2d1ab4508a5c3f1580b6e31d7465..227aeb002d8c23b6dba0af268f0a3297 } @Override -@@ -192,6 +192,45 @@ public class CraftEnchantment extends Enchantment { - public net.kyori.adventure.text.Component displayName(int level) { - return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level)); +@@ -197,6 +197,45 @@ public class CraftEnchantment extends Enchantment { + public String translationKey() { + return this.target.getDescriptionId(); } + + @Override diff --git a/patches/server/0692-Attributes-API-for-item-defaults.patch b/patches/server/0692-Attributes-API-for-item-defaults.patch index 89c60b5d0..e29615da4 100644 --- a/patches/server/0692-Attributes-API-for-item-defaults.patch +++ b/patches/server/0692-Attributes-API-for-item-defaults.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Attributes API for item defaults diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 24f5f6c7b1ca21515cdeb053f8e1f56004c800d0..7a8db8d481e9487ea83a640af208242f4987ad28 100644 +index 85a0639e8e65f4d085f605f09ca04a706a631d56..72cfffd80ad76abe7cb16bc9133730338c07b6f6 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -493,6 +493,19 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -492,6 +492,19 @@ public final class CraftMagicNumbers implements UnsafeValues { return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial)); }