Solved Message problem

Discussion in 'Spigot Plugin Development' started by JustCedric, May 24, 2016.

  1. 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;
                        }
            }
        }
     
    #1 JustCedric, May 24, 2016
    Last edited: May 24, 2016
  2. 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;
    }
     
  3. I only want to send the message once..
     
  4. 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?
     
  5. 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..
     
  6. Make an else if statement then its simple
     
  7. You have to check if the player clicked with the main hand and cancel otherwise:
    Code (Text):
    if (event.getHand() != EquipmentSlot.HAND) return;
     
  8. Sorry for the late response, but thanks it work :)