" if " - with new item.

Discussion in 'Plugin Development' started by RoiyAk, Jun 5, 2013.

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

    RoiyAk

    I have this item:
    Code:
    List<String> lore = new ArrayList<String>();
            ItemStack ticket = new ItemStack(Material.PAPER);
            ItemMeta t = ticket.getItemMeta();
            t.setDisplayName(ChatColor.GREEN+"Lottery Ticket");
            lore.add(ChatColor.GRAY+"Iron");
            t.setLore(lore);
            ticket.setItemMeta(t);   
            ShapedRecipe sticket = new ShapedRecipe(ticket).shape(" D ", " R ", " S ").setIngredient('D', Material.IRON_INGOT).setIngredient('R', Material.REDSTONE).setIngredient('S', Material.STICK);
            getServer().addRecipe(sticket);
    and i have the code:
    Code:
                                                        if (player.getItemInHand().getType() == Material.PAPER)
                                                        {
                                                                if(player.getItemInHand().getItemMeta().getLore().equals(ChatColor.AQUA+"Diamond")
                                                                        {
     
                                                                    j.add(player.getName());
                                                                    int i = player.getItemInHand().getAmount();
                                                                    ItemStack n = new ItemStack(Material.PAPER, i - 1);
                                                                    player.setItemInHand(n);
                                                                    player.sendMessage(ChatColor.GREEN + "You have joined the lottery!");
                                                               
                                                            {
                                                   
                                                            else
                                                            {
                                                                    player.sendMessage(ChatColor.RED + "You must put ticket in your hand");
                                                            }
    {
    
    You can fix it for me? thank you!
     
  2. Offline

    chasechocolate

    The .getLore() method will return a List<String>, and you are assuming it is returning a single string. Use player.getItemInHand().getItemMeta().getLore().contains(ChatColor.AQUA + "Diamond").
     
  3. Offline

    RoiyAk

    Its work but i have more error with this code :(

    Code:
    if(player.getItemInHand().getItemMeta().getLore().contains(ChatColor.GRAY+"Iron"))
                                                            {
                                                       
                                                                    j.add(player.getName());
                                                                    int i = player.getItemInHand().getAmount();
                                                                    ItemStack n = new ItemStack(Material.PAPER, i - 1);
                                                                    player.setItemInHand(n);
                                                                    player.sendMessage(ChatColor.GREEN + "You have joined the lottery!");
                                                            }
                                                            
    If the player do the command with a regular paper have this error:
    "An interal error occurred while attempting to perfrom this command"

    how i can fix it?
     
  4. Offline

    chasechocolate

    RoiyAk what's the error in console?
     
  5. Offline

    RoiyAk


    [​IMG]
     
  6. Offline

    chasechocolate

    RoiyAk what is line 181 in the class "help"?
     
  7. Offline

    RoiyAk

    " if(player.getItemInHand().getItemMeta().getLore().contains(ChatColor.AQUA+"Diamond")) "
    this the code:
    http://pastebin.com/07VTKhUz
     
Thread Status:
Not open for further replies.

Share This Page