Solved Checking if first GUI/Inventory slot if empty.

Discussion in 'Plugin Development' started by Flawless_Programming, Oct 4, 2016.

Thread Status:
Not open for further replies.
  1. I've been making a test plugin where you earn cases in multiple ways. Im going to make a market where you can sell your cases and other items. First i want to create a inventory where you select which item you want to sell. In this inventory i want to line up all items you got by checking if you have any of this items or not.

    This is a bit of my code:

    for
    (ItemStack item : p.getInventory().getContents()){
    if(item == null){
    int cases1 = this.get1v1case(p.getName()).intValue();
    if (cases1 <= 0) {
    //null
    } else if (cases1 >= 0) {
    ItemStack i = new ItemStack(Material.CHEST, cases1);
    this.setName(i, ChatColor.RED + "§l1v1 cases");
    "GUIINVENTORY".setItem(marketsell.firstEmpty(), i);
    }
    }
    }

    This code kinda works but instead of filling the "FirstEmpty" slot it fills all the empty slots like it's repeating this again and again. I probably know why it does this but i can't find a good solution to it.

    Pls give a tip. :)
     
  2. Offline

    Zombie_Striker

  3. Offline

    xXkguyXx

    Why not use inv.addItem(itemstack);, or am i missing something here?
     
    Zombie_Striker likes this.
  4. @Zombie_Striker thanks for the help. It's solved now. I feel a bit dumb right now because i didn't think about that. ;)
     
  5. Offline

    Zombie_Striker

    @Flawless_Programming
    If your problem has been solved, mark this thread as solved. (go to the top of this page, click ThreadTools, click Edit Title, and click the prefixes and select solved)
     
Thread Status:
Not open for further replies.

Share This Page