Java server error

Discussion in 'Plugin Development' started by jackpdot, Nov 18, 2016.

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

    jackpdot

    Hi everyone, I'm trying to make a Minecraft server with Java/Eclipse, and I have run into an error
    EventHandle v1.0 attempted to register an invalid EventHandler method signature "public boolean me.raycharlesman.PlayerListener.onEnter(org.bukkit.command.CommandSender,org.bukkit.command.Command,java.lang.String,java.lang.String[])" in class me.raycharlesman.PlayerListener

    This is my Main class:
    Code:
    package me.raycharlesman;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MyFirstPlugin extends JavaPlugin {
    
        @Override
        public void onEnable() {
           new PlayerListener(this);
        }
      
        @Override
        public void onDisable() {
          
        }
      
    }
    And this is my listener:
    Code:
    package me.raycharlesman;
    
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    
    
    public class PlayerListener implements Listener {
      
        public PlayerListener(MyFirstPlugin plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
    
        @EventHandler
        public boolean onEnter(CommandSender sender, Command cmd, String label, String[] args) {
          
    
            return getServer().dispatchCommand(getServer().getConsoleSender(), "summon LightningBolt" + args[3]);
        }
    
        private Server getServer() {
            // TODO Auto-generated method stub
            return null;
        }
      
    }
    Thank you in advance to anyone who helps me with this error.
     
    Last edited by a moderator: Nov 18, 2016
  2. @jackpdot You are mixing events and commands. You are also making a useless and null getServer.
     
  3. Offline

    HeartandSoul

    It is possible mixing events and commands with constructors.

    Also, use the static method getServer() that comes with Bukkit, not yours. The one you made returns nothing.
     
  4. Offline

    Zombie_Striker

    @jackpdot
    I just want to highlight this part:
    Are you sure you mean making your server with Java, or do you mean making a Plugin with Java? Because, if it is the first, this thread needs to be moved to BukkitAlternatives or Offtopic.

    Also, there is no "onEnter" method in Bukkit. Unless you plan on making your own command system, you need to use onCommand.
     
  5. Offline

    Marnixje90


    Formatted code:
    Code:
    package me.raycharlesman;
    
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    
    
    public class PlayerListener implements Listener {
    
        public PlayerListener(MyFirstPlugin plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, this);
        }
    
       
      
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
         Player p = (Player) sender; // sets the sender as Player (p)
    
    // Make your own commands here:
    
    // example:
    
    if (cmd.getName().equalsIgnoreCase("test")) {
                    p.sendMessage(ChatColor.RED + "Congratz, this is your first command!");
    
    
                }
    
            return true;
        }
    
    
      
    
    }

    *Dont forget plugin.yml *!!
     
  6. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page