1.12.2 Why does it issue the entire amount at once?

Discussion in 'Spigot Plugin Development' started by Ginger_14, Jan 12, 2020.

  1. Hi! Tell me pls, why it gives the entire amount at once, although not all items were in the inventory.
    Code (Text):
                number = 0;
                ItemStack is = inv.getItem(i);
                /////////////////////////////
                if (is == null || is.getType() == Material.WOOD_SWORD) {
                    number += 150;
                } if (is == null || is.getType() == Material.STONE_SWORD){
                    number += 175;
                }if (is == null || is.getType() == Material.IRON_SWORD) {
                    number += 225;
                } if (is == null || is.getType() == Material.DIAMOND_SWORD) {
                    number += 300;
                } if (is == null || is.getType() == Material.GOLD_SWORD) {
                    number += 200;
                } if (is == null || is.getType() == Material.DIAMOND_HOE) {
                    number += 50;
                }
     
  2. || means OR, not AND, so it triggers them all, because none of them are null.
     
  3. I think you are missing the "else" here lol.
     
  4. Pls:

    if(is == null){return};

    switch(is.getType())
    case...
    default: break;
    return;

    Or use a Map<Material, Integer> and use #get(Material)