[Help] Get Chest contents and give it to the player

Discussion in 'Plugin Development' started by LordManegane, Jul 21, 2013.

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

    LordManegane

    Well i want a code that get the chest contents and give them to the player who right click it.
    I try something like this
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if(event.getClickedBlock().getType() == Material.CHEST){
    5.  
    6. event.setCancelled(true);
    7. event.getClickedBlock().setType(Material.AIR);
    8. ItemStack items = (ItemStack) event.getClickedBlock().getDrops();
    9. }
    10.  
    11. }
    12. }


    I try that but wont work =P help please
    Thanks
     
  2. Offline

    caseif

    Get a Chest instance from the block, then call:
    e.getPlayer().getInventory().addItems(chest.getInventory().getContents());
     
  3. Offline

    LordManegane

    AngryNerd
    I do this
    Code:java
    1. Chest chest = ((Chest) event.getClickedBlock());
    2. event.getPlayer().getInventory().addItem(chest.getInventory().getContents());
    3. event.getClickedBlock().setType(Material.AIR);
    4.  

    And crash on the chest stuff

    Little bump

    *BUMP* Oh, that hurts D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    Coolymt

    Let me fix the code for you.
     
Thread Status:
Not open for further replies.

Share This Page