Solved OnRightClickEvent, not registering

Discussion in 'Plugin Development' started by ProSl3nderMan, Oct 18, 2015.

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

    ProSl3nderMan

    Hey guys, I'm trying to open a gui and send a message when ever someone right clicks a cookie but for some odd reason it's not registering. There's no error's in the code (eclipse) and no error's in the console. Here's my code:

    Code:
    package me.Pro.Events;
    
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    import me.Pro.BOZ.Main;
    import me.Pro.Menus.MainGUI;
    
    public class OnRightClick implements Listener {
       
        public OnRightClick(Main plugin) {}
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            if(event.getPlayer().getInventory().getItemInHand().getType() == Material.COOKIE) {
                if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    event.getPlayer().sendMessage("test complete");
                    MainGUI.openGUI(event.getPlayer());
                }
            }   
        }
    }
    
    Thanks in advance!
     
  2. Offline

    pookeythekid

    Have you registered the listener when the plugin enables?
     
  3. Offline

    ProSl3nderMan

    @pookeythekid
    I believe I did, is this how you register the listener?:
    Code:
    new OnJoin(this);
    new OnRightClick(this);
    OnJoin is an event that works, and that's all I did for OnJoin in onEnable so I figured it would work for my OnRightClick event.

    My apologies, you are right. I did not register the event:
    main.getServer().getPluginManager().registerEvents(this, main);
    ^ that's what I did for OnJoin and failed to see before this post. Please pardon this post haha

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
Thread Status:
Not open for further replies.

Share This Page