Solved PlayerInteractEvent

Discussion in 'Spigot Plugin Development' started by MaxKrissigo, May 11, 2016.

  1. So, for some reason my code isn't doing anything when a player right clicks a material with a certain lure and name. Not really sure why it isn't working, but there are no errors at all in the console etc.
    Code (Text):
           @EventHandler
            public void onPlayerInteract(PlayerInteractEvent e) {
             
                Player player = e.getPlayer();
                Action action = e.getAction();
             
                String name = Basic.getItemMeta().getDisplayName();
                List<String> lore = Basic.getItemMeta().getLore();
                     
                 if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) &&  player.getItemInHand().getType() == Material.DIAMOND && lore.contains("Right click this book for a random Basic Enchantment") && name.contains("Basic Random Enchantment Book")) {
                   
                     player.sendMessage("lol");
                   
                    }
            }
     
  2. You should strip the color just in case the lore has color. Also, you are probably receiving null pointer exceptions for not checking if there is item meta, and if there is a lore. Make sure you do all those things...
     
  3. Thanks for the help, I finally got it working.
     
  4. No problem, good luck :)