Event handler not triggering for playerInteractEvent

Discussion in 'Plugin Development' started by revivedbear, Nov 20, 2017.

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

    revivedbear

    I have this code that I want to check if a user opens a chest

    @EventHandler
    public void playerInteractEvent(PlayerInteractEvent e) {
    PluginManager manager = getServer().getPluginManager();
    manager.registerEvents(this, this);
    if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    Player p = (Player) e.getPlayer();
    if (e.getClickedBlock().getType() == Material.CHEST) {

    p.sendMessage("Player has opened chest");

    }
    }
    }

    however it doesn't work, also how would I check if the player opened a chest with a specific name
     
  2. Online

    timtower Administrator Administrator Moderator

    @revivedbear Don't register the event INSIDE the handler.
     
  3. Offline

    revivedbear

    I am a bit of a newbie, how would I write this properly?
     
  4. Offline

    Zombie_Striker

    @revivedbear
    put this:
    in the onEnable
     
Thread Status:
Not open for further replies.

Share This Page