onClickEvent Help

Discussion in 'Plugin Development' started by XxPvPKnightxX, Mar 28, 2016.

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

    XxPvPKnightxX

    I can't figure out why I'm not receiving the items. The onSignCreate event works perfectly. Creates the sign and changes it but i'm not receiving the items when clicking it.


    Code:
    public class Signs implements Listener {
       
        @EventHandler
        public void onSignCreate(SignChangeEvent event){
            Player player = event.getPlayer();
            if(player.hasPermission("staffmode.fishing"))
            if(event.getLine(0).equalsIgnoreCase("Fishing")) {
                player.sendMessage(ChatColor.RED + "Fishing kit sign created!");
                event.setLine(0, ChatColor.BLUE + "[Fishing Kit]");
            }
            else {
                if(!player.hasPermission("staffmode.fishing"))
                event.setCancelled(true);
            }
        }
        public void onClick(PlayerInteractEvent e) {
            Player p = e.getPlayer();
           
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
               
                if(e.getClickedBlock().getState() instanceof Sign) {
                   
                    Sign s = (Sign) e.getClickedBlock().getState();
                   
                    if(s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[Fishing Kit]")){
                       
                        ItemStack fishingRod = new ItemStack(Material.FISHING_ROD);
                        fishingRod.addEnchantment(Enchantment.LURE, 2);
                        p.getInventory().addItem(fishingRod);
                    }
                }
            }else{
                return;
            }
        }
    
    }
    
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    mcdorli

    You need to put the @EventHandler annotation above every event
     
  4. Offline

    XxPvPKnightxX

    @timtower Yes, I registered the event on enable.
     
  5. Offline

    ChazSchmidt

    My guess is that this line " if(s.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[Fishing Kit]")){ " is the cause. Try adding a debugging message (e.g. log.info("1")) before and after this line to see if that if block ever fires.
     
Thread Status:
Not open for further replies.

Share This Page