@Override
    public void run() {
        if (!stats)
            return;
        try {
            ResultSet r = sql.query("SELECT * FROM ctt_stats");
            HashMap<String, PlayerStats> p = new HashMap<String, PlayerStats>();
            while (r.next()) {
                p.put(r.getString("player"), new PlayerStats(r.getString("player"), r.getInt("wins"), r.getInt("losses"), r.getInt("kills"), r.getInt("deaths")));
            }

            for (Entry<String, PlayerStats> en : plugin.getPlayerStats().entrySet()) {
                PlayerStats s = en.getValue();
                if (p.get(s.getName()) != null) {
                    if (s.equals(p.get(s.getName()))) {
                        CTT.debug(en.getKey() + "'s stats haven't changed");
                        continue;
                    }
                }
                try {
                    ResultSet rs = sql.query("SELECT * FROM ctt_stats WHERE player='" + s.getName() + "'");
                    if (rs.next()) {
                        sql.query("UPDATE ctt_stats SET wins=" + s.getWins() + ", losses=" + s.getLosses() + ", kills=" + s.getKills() + ", deaths=" + s.getDeaths() + " WHERE player='" + s.getName() + "'");
                    } else {
                        sql.query("INSERT INTO ctt_stats (player, wins, losses, kills, deaths) VALUES ('" + s.getName() + "', " + s.getWins() + ", " + s.getLosses() + ", " + s.getKills() + ", " + s.getDeaths() + ")");
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                    CTT.send("Failed to update stats for " + s.getName());
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        updateTops();
    }