diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index 15b2226671..5b40a1b2a2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -1,5 +1,10 @@ package org.bukkit.craftbukkit.inventory; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.commands.arguments.item.ArgumentParserItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.Item; import org.apache.commons.lang.Validate; import org.bukkit.Color; import org.bukkit.Material; @@ -340,6 +345,25 @@ public final class CraftItemFactory implements ItemFactory { return DEFAULT_LEATHER_COLOR; } + @Override + public ItemStack createItemStack(String input) throws IllegalArgumentException { + try { + ArgumentParserItemStack arg = new ArgumentParserItemStack(new StringReader(input), false).parse(); // false = no tags + + Item item = arg.getItem(); + net.minecraft.world.item.ItemStack nmsItemStack = new net.minecraft.world.item.ItemStack(item); + + NBTTagCompound nbt = arg.getNbt(); + if (nbt != null) { + nmsItemStack.setTag(nbt); + } + + return CraftItemStack.asCraftMirror(nmsItemStack); + } catch (CommandSyntaxException ex) { + throw new IllegalArgumentException("Could not parse ItemStack: " + input, ex); + } + } + @Override public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException { return ((CraftMetaItem) meta).updateMaterial(material); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 92005c2df3..fd3fdefe06 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -1057,6 +1057,13 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { return removed > 0; } + @Override + public String getAsString() { + NBTTagCompound tag = new NBTTagCompound(); + applyToItem(tag); + return tag.toString(); + } + @Override public CustomItemTagContainer getCustomTagContainer() { return new DeprecatedCustomTagContainer(this.getPersistentDataContainer());