Listener not registering

Discussion in 'Plugin Development' started by herghost, Feb 5, 2014.

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

    herghost

    Hi All

    After two years away from trying to learn plugin development I am back!


    Basically my problem is this, my onplayerjoin just does nothing! I have added a sendMessage just saying hello when I login but this does not fire, can anyone see anything obvious I am missing?

    Main File:

    Code:
    package herghost.com.ZombieApoc;
     
    import java.sql.Connection;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public final class ZombieApoc extends JavaPlugin {
     
        MySQL MySQL = new MySQL(this, "localhost", "3306", "zombieapoc", "zombie", "*removed");
        Connection c = null;
       
       
     
       
        public void onEnable()
        {
            c = MySQL.openConnection();
           
            getServer().getPluginManager().registerEvents(new MyPlayerListener(), this);
           
           
            getCommand("basic").setExecutor(new Executer());
            //getCommand("login").setExecutor(new Executer());
        }
    }
    
    My Listener
    Code:
    package herghost.com.ZombieApoc;
     
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
     
     
    public class MyPlayerListener implements Listener  {
       
        MySQL MySQL = new MySQL(null, "localhost", "3306", "zombieapoc", "zombie", "*removed");
        Connection c = null;
             
           
       
        public void onPlayerJoin(PlayerJoinEvent event) throws SQLException
        {
           
            c=MySQL.openConnection();
           
            String name = event.getPlayer().getName();
            Player p = Bukkit.getPlayer(name);
           
            p.sendMessage("Hello");
            //Check Player is in database
            Statement statement = c.createStatement();
            ResultSet res = statement.executeQuery("SELECT * FROM players WHERE PlayerName = '" + name + "';");
            res.next();
           
            if(res.getString("PlayerName") == null)
            {
                p.sendMessage("You must register first! type /register desiredpassword emailaddress");
            }
            else
            {
                statement.executeUpdate("Update players SET online = 1 WHERE PlayerName = '"+name+"';");
            }
           
           
        }
     
    }
    
    Many thanks

    Bukkit 1.7.2 - RO3
     
  2. Offline

    Goblom

    You are missing your EventHandler

    Code:
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) throws SQLException {
        //do event stuff
    }
    
     
Thread Status:
Not open for further replies.

Share This Page