Problems with Events in BukkitPlugins

Discussion in 'Bukkit Help' started by 11011100, Jul 16, 2014.

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

    11011100

    Hello,
    I recently started writing Plugins for Bukkit-Servers.
    I wanted to write a Plugins which does following:
    When the Player has a Golden Carrot in his hand, he gets a NightVision-Effect.
    To check, if the player holds the item I wanted to use this:
    Code:java
    1. public void onPlayerItemHeld(PlayerItemHeldEvent event)
    2. {
    3. Player player = event.getPlayer();
    4. getLogger().info("Test");
    5. player.sendMessage("Test");
    6. if(player.getItemInHand().equals(Material.GOLDEN_CARROT))
    7. {
    8.  
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION,200,1));
    10. }
    11. }


    I added getLogger and sendMessage for testing. But nothing happens, there also are no text messages.

    What do I do wrong?

    It works now, I had to make some changes.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    nubebuster

    11011100 You added @EvenHandler right? That's all you needed to do.
     
  3. Offline

    jts3304

    Yes, you have to add @EventHandler above your method that the PlayerItemHeld event is in, you also have to register it, which I usually do when the plugin enables:
    Code:
    public void onEnable()
    {
        Bukkit.getServer().getPluginManager().registerEvents(Listener eventHandler, Plugin plugin);
    }
     
    11011100 likes this.
Thread Status:
Not open for further replies.

Share This Page