Solved Help! get ArmorContents and clearing inventory

Discussion in 'Plugin Development' started by QarthO, Feb 1, 2014.

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

    QarthO

    Im trying to make a plugin where when a player dies, his stuff is going to go into a chest. The chest spawns. and the items in his inventory are put into the chest but not the items in the 4 armor slots. And his items are still being dropped on the ground. Can someone help me?

    The code makes sense, but its not working... what did I do wrong?

    - Thanks

    (Code farther Down)

    Code:java
    1. @EventHandler
    2. public void ChestSpawn(PlayerDeathEvent event){
    3. Player p = event.getEntity().getPlayer();
    4. Location loc = p.getLocation();
    5. final Block block = loc.getBlock();
    6. final Block block2 = loc.getBlock().getRelative(BlockFace.NORTH);
    7.  
    8. final Material m1 = block.getType();
    9. final Material m2 = block2.getType();
    10.  
    11. block.setType(Material.CHEST);
    12. block2.setType(Material.CHEST);
    13.  
    14. Chest c = (Chest) block.getState();
    15. DoubleChest chest = (DoubleChest) c.getInventory().getHolder();
    16. Inventory inv = chest.getInventory();
    17. inv.addItem(p.getInventory().getContents());
    18. inv.addItem(p.getInventory().getArmorContents());
    19. event.getDrops().clear();


    Bump

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

    _Cookie_

    QarthO
    Try seeing if the player actually has armour contents:
    Code:java
    1. if(p.getInventory().getArmourContents() != null){
    2. //Code
    3. }
     
  3. Offline

    xTigerRebornx

    QarthO You are putting the 2nd chest above the other one, so it won't make a DoubleChest, it will just be 2 seperate chests, therefor when you get the inventory of the DoubleChest, it is only one chest big.
     
  4. Offline

    QarthO

    I tested it and both chests are beside each other, and if the player inventory has more than 27 stacks it does go into the chest. so the chest placing and the players inventory isn't the problem.

    The problem is that I cant get the players armor in the chest, and the players inventory isn't clearing.
     
  5. Offline

    d0mov0i

    add a message after the clearing. like system.out.println something. see if it got through
     
  6. Offline

    QarthO

    I made the following changes:

    Code:java
    1. @EventHandler
    2. public void ChestSpawn(PlayerDeathEvent e){
    3. Player p = e.getEntity();
    4. Location loc = p.getLocation();
    5.  
    6. final Block b1 = loc.getBlock();
    7. final Block b2 = loc.getBlock().getRelative(BlockFace.NORTH);
    8. final Material m1 = b1.getType();
    9. final Material m2 = b2.getType();
    10.  
    11. b1.setType(Material.CHEST);
    12. b2.setType(Material.CHEST);
    13.  
    14. Chest c = (Chest) b1.getState();
    15. DoubleChest chest = (DoubleChest) c.getInventory().getHolder();
    16. Inventory inv = chest.getInventory();
    17. inv.setContents(p.getInventory().getArmorContents());
    18. e.getDrops().clear();


    I removed the ".getPlayer()" so its only ".getEntity", when doing so, the "e.getDrops().clear()" is now clearing the players inventory. I also change "inv.addItem()" to inv.setContents() and it does put the players inventory in the chest, or if i changed it to "p.getInventory().getArmorContents()" it does put the players armor in the chest. But now how do I merge the two itemstacks into 1 so i can put both the players inventory and their armor in the chest?

    -Thanks Q
     
  7. Offline

    mrcheeseface2

    change prefix to solved
     
  8. Offline

    QarthO

    what?

    I solved it, didnt create a variable, just after inv.setContents(p.getInventory().getArmorContents())
    I put the inv.addItem(p.getInventory.getContents());

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

Share This Page