From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar <aikar@aikar.co> Date: Wed, 4 May 2016 23:55:48 -0400 Subject: [PATCH] ensureServerConversions API This will take a Bukkit ItemStack and run it through any conversions a server process would perform on it, to ensure it meets latest minecraft expectations. diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java index 333884bc8fe45c66d37a1bbcebc10ea655d2055f..c1ec8efffd5ff2a4dcb1d761be9a431a62284607 100644 --- a/src/main/java/org/bukkit/inventory/ItemFactory.java +++ b/src/main/java/org/bukkit/inventory/ItemFactory.java @@ -236,4 +236,18 @@ public interface ItemFactory { @Deprecated(since = "1.18.1", forRemoval = true) String getI18NDisplayName(@Nullable ItemStack item); // Paper end - add getI18NDisplayName + + // Paper start - ensure server conversions API + /** + * Minecraft's updates are converting simple item stacks into more complex NBT oriented Item Stacks. + * + * Use this method to ensure any desired data conversions are processed. + * The input itemstack will not be the same as the returned itemstack. + * + * @param item The item to process conversions on + * @return A potentially Data-Converted-ItemStack + */ + @NotNull + ItemStack ensureServerConversions(@NotNull ItemStack item); + // Paper end - ensure server conversions API } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index e2cc1ea49f5b7fa06ef388c922184835a84f9440..e66a958bc36ac774081d5e71966f312ebb8228d9 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -566,7 +566,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat } } - return result; + return result.ensureServerConversions(); // Paper } /** @@ -643,6 +643,19 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat return Bukkit.getServer().getItemFactory().displayName(this); } + /** + * Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks. + * + * Use this method to ensure any desired data conversions are processed. + * The input itemstack will not be the same as the returned itemstack. + * + * @return A potentially Data Converted ItemStack + */ + @NotNull + public ItemStack ensureServerConversions() { + return Bukkit.getServer().getItemFactory().ensureServerConversions(this); + } + /** * Gets the Display name as seen in the Client. * Currently the server only supports the English language. To override this,