M
M
Meakin2019-12-25 15:40:40
Java
Meakin, 2019-12-25 15:40:40

How to stop condition checks?

There are 2 conditions:

if(a == Action.LEFT_CLICK_BLOCK || a == Action.RIGHT_CLICK_BLOCK && (p.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SWORD || p.getInventory().getItemInMainHand().getType() == Material.IRON_SWORD) && e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.ENDER_CHEST) {
      e.setCancelled(true);
      p.sendMessage(ChatColor.BOLD + ("Убери меч из рук"));
      p.playSound(p.getLocation(), Sound.BLOCK_DISPENSER_FAIL, 2, 1);

    }
  if(a == Action.LEFT_CLICK_AIR && p.getInventory().getItemInMainHand().getType() == Material.APPLE ) {
    p.sendMessage("Ussed");
  }
  }
}

The fact is that when the condition says:
If we press the chest with the sword, but it turns out:
If we press any block with the sword (as stated in condition 2) and if we press the apple (as stated in condition 2) then ussed is displayed, and as a result in any case (it doesn't matter about the chest we press, or about other blocks, and it doesn't matter what object, sword or apple)
How to interrupt 1 condition so that another action or condition already starts doing / checking?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-01-13
@Terran37

The first thing you should do is make normal hyphens in the first block to make it easier to read the code.
The second is to rewrite the question itself once again.
I think that if you complete the first and second points, then you yourself will correct the error or supplement the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question