Hi guys, I'm trying to send a message when someone right clicks on a red sandstone stair/dropper but when someone right clicks on a red sandstone stair it will send the message twice and when they click on the dropper it will only send once and I only want it to send once.. Code: Code (Text): @EventHandler(priority = EventPriority.HIGHEST) public void onBlockClick(PlayerInteractEvent event){ Player player = (Player) event.getPlayer(); if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { Block block = event.getClickedBlock(); if (block.getType() == Material.RED_SANDSTONE_STAIRS || block.getType() == Material.DROPPER) { event.setCancelled(true); player.sendMessage(ChatColor.DARK_AQUA + "1"); return; } } }
Write 2 different if statements. Code (Text): if (block.getType() == Material.RED_SANDSTONE_STAIRS) { event.setCancelled(true); player.sendMessage(ChatColor.DARK_AQUA + "1"); player.sendMessage(ChatColor.DARK_AQUA + "1"); return; } else if (block.getType() == Material.DROPPER){ event.setCancelled(true); player.sendMessage(ChatColor.DARK_AQUA + "1"); return; }
What do you mean? You want if he do that and take the message to not send it again? Or just to fix the messages?
I only want to sent the message once to the player because with the code that I gave you the message send twice when you right click a red sandstone stair and when you click on a dropper it will send one and I want it to send once..
You have to check if the player clicked with the main hand and cancel otherwise: Code (Text): if (event.getHand() != EquipmentSlot.HAND) return;