View difference between Paste ID: GkME6uhh and SB2XR1h2
SHOW: | | - or go back to the newest paste.
1
static HashMap<Player, Long> playtime = new HashMap<>();
2
3
public interface Callback<T>{
4
    public void execute(Long response);
5
}
6
7
public static void doAsyncGetPlaytime(final Player p, final Callback<Boolean> callback){
8
    new BukkitRunnable(){
9
    	
10
        @Override
11
        public void run(){
12
13
        	
14
        	playtime.put(p, 0L);
15
            try{
16
				PreparedStatement ps = plugin.MySQL.openConnection().prepareStatement("SELECT playtime FROM users WHERE UUID='"+p.getUniqueId().toString()+"'");
17
				ResultSet rs = ps.executeQuery();
18
				if(rs.next()){
19
					playtime.put(p, rs.getLong("playtime"));
20
				}
21
				rs.close();
22
			}catch(Exception ex){
23
				ex.printStackTrace();
24
			}
25
            
26
            new BukkitRunnable()
27
            {
28
                @Override
29
                public void run()
30
                {
31
                    callback.execute(playtime.get(p));
32
                }
33
            }.runTask(plugin);
34
        }
35
    }.runTaskAsynchronously(plugin);
36
}
37
38
Callback<Long> callback = new Callback<Long>()
39
	{
40
	    public void execute(Long l)
41
	    {
42-
	        // Do whatever with the boolean
42+
	        return l;
43
	    }
44
	};