invalid EventHandler

Discussion in 'Plugin Development' started by fatalwir, Apr 19, 2014.

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

    fatalwir

    Hello, I'm getting this in console and I don't know why. Everything else works fine.
    Code:
    [14:45:51 ERROR]: [FW-WoWutils] FW-WoWutils v1.1 attempted to register an invalid EventHandler method signature "public boolean cz.fatalwir.wowutils.WoWutils.onCommand(org.bukkit.command.CommandSender,org.bukkit.command.Command,java.lang.String,java.lang.String[])" in class cz.fatalwir.wowutils.WoWutils
    Here's my plugin.yml
    Code:
    name: FW-WoWutils
    version: 1.1
    author: fatalwir
    website: http://fatalwir.cz
     
    main:  cz.fatalwir.wowutils.WoWutils
    database: false
    prefix: FW-WoWutils
     
    commands:
      progress:
        description: Shows quest progress of given player.
        usage: /progress <nick>
        permission: fwwowutils.progress
     
    permissions:
      fwwowutils.progress:
        description: Gives access to /progress command.
    And here's source code:
    Code:java
    1. package cz.fatalwir.wowutils;
    2.  
    3. import java.util.List;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.EventPriority;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.event.player.PlayerQuitEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. /**
    17. *
    18. * @author Ondřej Kolář (fatalwir)
    19. */
    20.  
    21. public class WoWutils extends JavaPlugin implements Listener {
    22.  
    23. @Override
    24. public void onEnable() {
    25. this.getServer().getPluginManager().registerEvents(this, this);
    26. }
    27.  
    28. @Override
    29. public void onDisable() {
    30. }
    31.  
    32. @EventHandler
    33. public void onPlayerJoinEvent(PlayerJoinEvent event){
    34. Player player = event.getPlayer();
    35. event.setJoinMessage(ChatColor.RESET + player.getName() + ChatColor.GRAY + ChatColor.ITALIC + " se pripojil");
    36. }
    37.  
    38. @EventHandler
    39. public void onPlayerQuitEvent(PlayerQuitEvent event){
    40. Player player = event.getPlayer();
    41. event.setQuitMessage(ChatColor.RESET + player.getName() + ChatColor.GRAY + ChatColor.ITALIC + " se odpojil");
    42. }
    43.  
    44. @EventHandler(priority = EventPriority.NORMAL)
    45. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    46. if(cmd.getName().equalsIgnoreCase("progress")) {
    47. if(sender.hasPermission("fwwowutils.progress")) {
    48. //some code here
    49. }else {
    50. sender.sendMessage(ChatColor.RED + "Nemas opravneni na tento prikaz!");
    51. return true;
    52. }
    53. }
    54. return false;
    55. }
    56. }


    Can anyone tells me why? Thanks.
     
  2. Offline

    TomFromCollege

    You should use OnCommand as a CommandExecutor
    Just make sure you add the command to the plugin.yml
    Code:
    package cz.fatalwir.wowutils;
     
    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    /**
    *
    * @author Ondřej Kolář (fatalwir)
    */
     
    public class WoWutils extends JavaPlugin implements Listener, CommandExecutor {
     
        @Override
        public void onEnable() {
            this.getServer().getPluginCommand("progress").setExecutor(this);
            this.getServer().getPluginManager().registerEvents(this, this);
        }
     
        @Override
        public void onDisable() {
        }
     
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event){
            Player player = event.getPlayer();
            event.setJoinMessage(ChatColor.RESET + player.getName() + ChatColor.GRAY + ChatColor.ITALIC + " se pripojil");
        }
     
        @EventHandler
        public void onPlayerQuitEvent(PlayerQuitEvent event){
            Player player = event.getPlayer();
            event.setQuitMessage(ChatColor.RESET + player.getName() + ChatColor.GRAY + ChatColor.ITALIC + " se odpojil");
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("progress")) {
                if(sender.hasPermission("fwwowutils.progress")) {
                    //some code here
                }else {
                    sender.sendMessage(ChatColor.RED + "Nemas opravneni na tento prikaz!");
                    return true;
                }
            }
            return false;
        }
    }
     
  3. Offline

    Badeye

    fatalwir
    You are trying to Register a Bukkit Event where there is none. the onCommand void is no "real" bukkit event, so adding the Eventhandler will cause Errors. Just remove it :)

    What TomFromCollege said can be done aswell, but i highly prefer your method, just without the EventHandler infront :p
     
  4. Offline

    AdamQpzm

    TomFromCollege The main class doesn't ever actually need to implement CommandExecutor :)

    Badeye I'm confused - isn't that what TomFromCollege suggested doing? What's the difference?
     
  5. Offline

    Badeye

    AdamQpzm Oeh i thought he just added a CommandExecutor o.o But anyways, glad you fixed your problem :)
     
  6. Offline

    AdamQpzm

  7. Offline

    fatalwir

    "The best solution to our problem is usually the easiest one." Thank you Badeye.
     
  8. Offline

    Badeye

    AdamQpzm Oh right, i mixed up the names, i assumed you where OP
    fatalwir Glad that i was able to help you, and yeah those are some deep words right there :)
     
Thread Status:
Not open for further replies.

Share This Page