M
M
Meakin2019-12-25 14:11:12
Java
Meakin, 2019-12-25 14:11:12

How to make a double IF condition in Java?

I have a condition (If in hand = a stone sword, and the block on which we press the chest, then) for example: (If in the hand there is a stone sword or an iron sword or a wooden sword and the block on which we press the chest, then, but works like:
If in hand a stone sword or an iron sword or "a wooden sword and a block on which we press the chest" i.e. only with the latter)
Code:

Code
if(a == Action.LEFT_CLICK_BLOCK && a == Action.RIGHT_CLICK_BLOCK && p.getInventory().getItemInMainHand().getType() == Material.DIAMOND_SWORD && 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);
  }

UPD: Do not offer versions of the question without -API- (There is work going on with the Bukkit API) and the essence does not really change

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DDwrt100, 2019-12-25
@Meakin

if(a==0 || b ==1 ){do(a,b)} else{
if(a==0){do(a)} }

something like this ?

I
Igor, 2019-12-25
@DMGarikk

(the question is poorly worded),
but from what I understand, separate the logical blocks in the condition with parentheses and everything will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question