EssentialsX

EssentialsX

2M Downloads

item question

Floffah opened this issue · 1 comments

commented

ngl im pretty confused as to how i would turn an item string (e.g. diamondhelmet 1 protection_environmental:2 from a kit) into an itemstack (with enchantments, names, lores, everything)

So far, i have this:

                        for (String item : kit.getItems()) {

                            boolean allowUnsafe = ku.getEss().getSettings().allowUnsafeEnchantments();
                            ItemStack citem = ku.getEss().getItemDb().get(item.split(" ")[0]);

                            MetaItemStack metaStack = new MetaItemStack(citem);

                            if (!metaStack.canSpawn(ku.getEss())) {
                                throw new Exception("Unable to spawn in item " + item.split(" ")[0]);
                            }

                            if (allowUnsafe && sender instanceof Player && !ku.getEss().getUser((Player) sender).isAuthorized("essentials.enchantments.allowunsafe")) {
                                allowUnsafe = false;
                            }

                            int metaStart = NumberUtil.isInt(item.split(" ")[1]) ? 2 : 1;

                            if (args.length > metaStart) {
                                metaStack.parseStringMeta(new CommandSource(sender), allowUnsafe, args, metaStart, ku.getEss());
                            }

                            citem = metaStack.getItemStack();

                            if(target.getInventory().firstEmpty() == -1) {
                                target.getWorld().dropItemNaturally(target.getLocation(), citem);
                            } else {
                                target.getInventory().addItem(citem);
                            }
                        }

But it only gives the player an item with none of the enchantments or names.

How do i do this?

commented

nevermind i got it.

for anyone looking at this because they cant figure it out either, dont check the args length check the split item length (i forgot that bit)