Dont continue

Discussion in 'Spigot Plugin Development' started by Zocker1_3, Aug 15, 2018.

  1. I’m not sure what you’re asking but the first if-statement will return false if there is no item so the for-loop will keep on going.
     
  2. Because you put
    Code (Java):
    break;
    in all if/else if/else statements.
    Code (Java):
    break;
    is used to exit a loop so only one execution occurs.
    Code (Java):
    for (int i = 0; i < p.getInventory().getSize(); i++) {
        ItemStack itemStack = p.getInventory().getItem(i);
        if (itemStack != null && itemStack.getType() == Material.PAPER && itemStack.getItemMeta().getDisplayName().equals("§3Ticket")) {
            if (itemStack.getAmount() > 1) {
                itemStack.setAmount(itemStack.getAmount() - 1);
                p.getInventory().setItem(i, itemStack);
                p.closeInventory();
                p.teleport(Locations.getUBahnLocation(name));
                p.sendMessage("§3UBahn §7| §3Ticket für eine Fahrt nach: §e" + name + " §3eingelöst.");
            } else if (itemStack.getAmount() == 1) {
                p.getInventory().setItem(i, null);
                p.closeInventory();
                p.teleport(Locations.getUBahnLocation(name));
                p.sendMessage("§3UBahn §7| §3Ticket für eine Fahrt nach: §e" + name + " §3eingelöst.");
            } else {
                p.getInventory().setItem(i, null);
            }
        }
    }
    int i = randomInteger();
    p.teleport(Locations.getUBahnLocation(name));
    p.closeInventory();
    if (i >= 45 && i <= 55) {
        p.sendMessage("§3UBahn §7| §3Du wurdest beim Schwarzfahren erwischt und angezeigt!");
        // MySQL.addToFahndung(p.getUniqueId(), p.getName(), "schwarzfahren");
    }
    p.sendMessage("§3UBahn §7| §3Ticket für eine Fahrt nach: §e" + name +  "§3eingelöst..");
    This should fix your problem.
     
  3. The Problem is that it only should continue if there is no item when it should stop