Player inventory to chest with ArrayList

Discussion in 'Plugin Development' started by Mike3132, Dec 3, 2021.

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

    Mike3132

    Players inventory is not casting into the chest. It just drops when they reach 0 health.
    Should I use (PlayerDeathEvent) instead? Or is there something simple I am missing


    //Set Chest
    player.getLocation().getBlock().setType(Material.CHEST);Chest chest = (Chest) player.getLocation().getBlock().getState();if (player.getInventory().isEmpty()) {
    return;}

    //Chest Inventory
    ArrayList<ItemStack> a = new ArrayList<>();for (ItemStack i : player.getInventory().getContents()) {
    if (i != null) {
    a.add(i);}

    }

    //Set Chest Inventory
    if (player.getHealth() == 0 ) {
    chest.getInventory().setContents(a.toArray(new ItemStack[a.size()]));}

    I promise the code is fomratted right in my IDE idk how to format it on here
     
    Last edited: Dec 3, 2021
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Mike3132

    Is this not for coding help?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Mike3132 But you just post code, you are not saying what is wrong or what you want.
     
  5. Offline

    Mike3132

    My aplogizes I thought you was supposed to do that in the header. I will edit that now.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Mike3132 What is the context of the code? All we have are a couple lines, post the full method please.
     
  7. Offline

    Mike3132

    I am sorry for wasting your time I figured it out. Can you just delete this shit show of a post please.
     
  8. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page