Solved Executing event when right-clicking air

Discussion in 'Plugin Development' started by Froshin, May 19, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Froshin

    Code:
    @EventHandler
        public void onInteractEvent(PlayerInteractEvent e) {
         
     
     
            if (e.getAction() == Action.RIGHT_CLICK_AIR) {
               
       
              Player p = e.getPlayer();
              p.sendMessage("Well, at the very least you're right clicking air.");
              if(p.getItemInHand().getType() == Material.SLIME_BALL) {
           
              p.sendMessage("It recognizes the slime ball!");
           
                }
           
             
             
              if(p.getItemInHand().getType() == Material.DIAMOND_PICKAXE) {
                  p.sendMessage("It recognizes the pickaxe");
                  if (p.getItemInHand().getItemMeta().getDisplayName() == ChatColor.YELLOW + "Divine Pick"){
             
                   
                         
                          p.sendMessage("It works!");
                         
                       
                     
                  }}}}
    I want to execute an event when I right click. It does not event execute p.sendMessage("Well, at the very least you're right clicking air.");

    What could be the error?

    Thanks in advance!
     
  2. Offline

    GodzOfMadness

    Froshin
    Are you registering your events?
     
    Froshin likes this.
  3. Offline

    Froshin

    GodzOfMadness Oops.

    Edit: Still doesn't register the custom display name, could it be due to colors?
     
  4. Offline

    GodzOfMadness

    Froshin You use the equals method to compare strings, like if(item.getItemMeta().getDisplayName().equals(name))
     
    Froshin likes this.
  5. Offline

    Froshin

    GodzOfMadness

    Thanks! However, both custom pickaxes return "It works"; despite one of them having both the color prefix and the string wrong. A vanilla pickaxe did not return this.

    Any clue on why?
    ChatColor.GOLD + "Terra X"
    vs
    ChatColor.YELLOW + "Divine Pick"

    I suspect it's the ChatColor that doesn't really work with the equals method?
    Thanks in advance!
     
Thread Status:
Not open for further replies.

Share This Page