Create chest when item pickup

Discussion in 'Plugin Development' started by wouter0100, Sep 19, 2012.

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

    wouter0100

    Hey,

    I'm trying to create a function that when the an item got picked up by a player, the item got removed and placed in a new created chest.

    Script:
    Code:
    event.getItem().remove();
                 
                        Location chestLocation = event.getItem().getLocation();
                 
                        if(!(chestLocation.getBlock() instanceof Chest))
                        {
                            chestLocation.getBlock().setType(Material.CHEST);
                     
                            if(!(chestLocation.getBlock() instanceof Chest))
                            {
                                player.sendMessage(ChatColor.RED + "[BLOCK]" + ChatColor.GOLD + " Because an error the item has been removed.");
                                event.setCancelled(true);
                                return;
                            }
                        }
                 
                        Chest blockChest = (Chest) chestLocation.getBlock();
                 
                        blockChest.getInventory().setItem(blockChest.getInventory().firstEmpty(), event.getItem().getItemStack());
    Always it stops by the Because an error messages, what do i wrong?

    //No errors, and the chest is created when the messages comes.

    Thanks!
    Wouter0100
     
  2. Offline

    Netizen

    What error message are you getting? Is it a stack trace or is it the error message "Because an error the item has been removed?"
     
  3. Offline

    wouter0100

    its the error message,

    player.sendMessage(ChatColor.RED + "[BLOCK]" + ChatColor.GOLD + " Because an error the item has been removed.");

    solved :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page