What is it with @EventHandlers?

Discussion in 'Plugin Development' started by legostarwarszach, May 10, 2013.

Thread Status:
Not open for further replies.
  1. So I'm basically trying to make it were when a person dies, a lighting strikes down. What's the problem?
    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            Player player = event.getEntity();
            Location location = player.getLocation();
            World world = player.getWorld();
            world.strikeLightning(location);
        }
     
        
    Full code: http://pastebin.com/XjSAGcsn
     
  2. Offline

    Me4502

    Have you registered the event listener?
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    The problem is that this is just a method, and it is not in a plugin.
     
    devilquak likes this.
  4. Offline

    ZeusAllMighty11

    in your main class that extends javaplugin, add

    Code:
    getServer().getPluginManager().registerEvents(someClass(), this);
    
    Where someClass is a local variable to represent the listener class, or you can initiate it
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    Show not tell. As it stands no one can tell you what you have done wrong with your plugin.
     
  6. Offline

    Deathmarine

    Even though your class implements Listener it must be registered to the PluginManager inorder for the annotations to have any meaning.

    add this to your onEnable method.
    Code:
    this.getServer().getPluginManager().registerEvents(this, this);
     
    legostarwarszach likes this.
  7. Offline

    Sagacious_Zed Bukkit Docs

Thread Status:
Not open for further replies.

Share This Page