mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 17:57:34 +01:00
#975: Add method to read ItemStack input
By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
parent
9340d95f92
commit
8400a7987a
@ -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);
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user