Return ItemMeta not working?

Discussion in 'Plugin Development' started by youngbawss22, Jan 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    youngbawss22

    I have been struggling with this for quite some time. Not too sure what i am doing wrong here. If somebody could point it out that would be great, thanks :).

    Listener class: (Called mech)
    Code:
        public ItemMeta addRecipeSpear()
        {
            ArrayList<String> lore = new ArrayList<String>();
            final ItemStack stick = new ItemStack(Material.STICK, 1);
            ItemMeta im = stick.getItemMeta();
            lore.add(ChatColor.BLUE + " Simple, but deadly.");
            lore.add(ChatColor.RED + " Damage: 15");
                im.setDisplayName("Spear");
                im.setLore(lore);
                stick.setItemMeta(im);
                ShapedRecipe spearr = new ShapedRecipe(stick);
                spearr.shape("F  ", " S ", "  S");
                spearr.setIngredient('S', Material.STICK);
                spearr.setIngredient('F', Material.FLINT);
                plugin.getServer().addRecipe(spearr);
                return im;
    Main class:
    Code:
    if(cmd.getName().equalsIgnoreCase("givespear")) {
                Mech M = new Mech(plugin);
                if(sender instanceof Player) {
                    Player p = (Player) sender;
                    Player tp = p.getServer().getPlayer(args[0]);
                    if(p.hasPermission("spearmod.give")) {
                        if(args.length == 2) {
                            if(args[1].equalsIgnoreCase("spear")) {
                                ItemMeta im = M.addRecipeSpear();
                                ItemStack is = new ItemStack(Material.STICK, 1);
                                tp.getInventory().addItem(is);
                                is.setItemMeta(im);
                            }
                        }
    The correct itemmeta is not being added to the itemstack.
     
  2. Offline

    CorrieKay

    add the meta, THEN add the item to the inventory.
     
  3. Offline

    youngbawss22

    -_-... thanks. Guess i couldn't figure out how to switch two lines of code on my own.
     
Thread Status:
Not open for further replies.

Share This Page