Fix and deprecate ItemStack#getI18NDisplayName (#7358)

This commit is contained in:
Jake Potrebic 2022-01-16 16:53:26 -08:00
parent 2fcdb1b8ed
commit 48f228173e
4 changed files with 9 additions and 3 deletions

View file

@ -23,8 +23,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * + *
+ * @param item Item to return Display name of + * @param item Item to return Display name of
+ * @return Display name of Item + * @return Display name of Item
+ * @deprecated {@link ItemStack} implements {@link net.kyori.adventure.translation.Translatable}; use that and
+ * {@link net.kyori.adventure.text.Component#translatable(net.kyori.adventure.translation.Translatable)} instead.
+ */ + */
+ @Nullable + @Nullable
+ @Deprecated
+ String getI18NDisplayName(@Nullable ItemStack item); + String getI18NDisplayName(@Nullable ItemStack item);
// Paper end // Paper end
} }
@ -43,8 +46,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * You must replace the language file embedded in the server jar. + * You must replace the language file embedded in the server jar.
+ * + *
+ * @return Display name of Item + * @return Display name of Item
+ * @deprecated {@link ItemStack} implements {@link net.kyori.adventure.translation.Translatable}; use that and
+ * {@link net.kyori.adventure.text.Component#translatable(net.kyori.adventure.translation.Translatable)} instead.
+ */ + */
+ @Nullable + @Nullable
+ @Deprecated
+ public String getI18NDisplayName() { + public String getI18NDisplayName() {
+ return Bukkit.getServer().getItemFactory().getI18NDisplayName(this); + return Bukkit.getServer().getItemFactory().getI18NDisplayName(this);
+ } + }

View file

@ -11,8 +11,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/inventory/ItemFactory.java --- a/src/main/java/org/bukkit/inventory/ItemFactory.java
+++ b/src/main/java/org/bukkit/inventory/ItemFactory.java +++ b/src/main/java/org/bukkit/inventory/ItemFactory.java
@@ -0,0 +0,0 @@ public interface ItemFactory { @@ -0,0 +0,0 @@ public interface ItemFactory {
*/
@Nullable @Nullable
@Deprecated
String getI18NDisplayName(@Nullable ItemStack item); String getI18NDisplayName(@Nullable ItemStack item);
+ +
+ /** + /**

View file

@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
@@ -0,0 +0,0 @@ public final class CraftItemFactory implements ItemFactory { @@ -0,0 +0,0 @@ public final class CraftItemFactory implements ItemFactory {
return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId()) : null; return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId(nms)) : null;
} }
+ +
+ @Override + @Override

View file

@ -26,7 +26,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ nms = CraftItemStack.asNMSCopy(item); + nms = CraftItemStack.asNMSCopy(item);
+ } + }
+ +
+ return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId()) : null; + return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId(nms)) : null;
+ } + }
// Paper end // Paper end
} }