Need help with dupe plugin

Discussion in 'Plugin Development' started by logantp, Dec 20, 2017.

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

    logantp

    Ok so I have created a plugin where a player types /dupe and it opens a inventory with 27 slots.
    I want to make it so every 1 sceond, it loops through each item, checks if its null or if the stack size is 64, if its not then it increases the item amount by 1
    for example:

    for each item in Inventory inv{
    if item === null or if item.amount <= 64{
    // do nothing
    } else {
    int item = item.getAmount();
    item++;
    }
    }
     
  2. Offline

    AdamDev

    @logantp
    1. When doing a for loop for an inventory use "int i = 0;i<inv.getSize();i++"
    2. Never use item++; in a for loop unless your using a slot
    3. Make an integer that gets the maximum stack size for the item.
    4. Use item.setAmount(int from #2); instead of using item.getAmount(); and then adding it.
    5. Your if statement would never work because "===" can't compare in java, that's javascript that does that. To compare in java its "=="
    6. Where it says "// do nothing" it would be just "return (true or false if needed);"
    Hope this helps!
    ~ AdamDev
     
  3. Offline

    Unknown123

    Use if (item != null && item.getAmount > 64)
     
  4. Offline

    logantp

    Thanks so much, it worked.
    And yes, I did a lot of JavaScript before Java so its a bad habit I am trying to fix.
    Thank you.
     
  5. Offline

    AdamDev

    @logantp
    Glad to help and make sure to mark your thread as solved. Happy new year.
     
Thread Status:
Not open for further replies.

Share This Page