Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static HashMap<Player, Long> playtime = new HashMap<>();
- public interface Callback<T>{
- public void execute(Long response);
- }
- public static void doAsyncGetPlaytime(final Player p, final Callback<Boolean> callback){
- new BukkitRunnable(){
- @Override
- public void run(){
- playtime.put(p, 0L);
- try{
- PreparedStatement ps = plugin.MySQL.openConnection().prepareStatement("SELECT playtime FROM users WHERE UUID='"+p.getUniqueId().toString()+"'");
- ResultSet rs = ps.executeQuery();
- if(rs.next()){
- playtime.put(p, rs.getLong("playtime"));
- }
- rs.close();
- }catch(Exception ex){
- ex.printStackTrace();
- }
- new BukkitRunnable()
- {
- @Override
- public void run()
- {
- callback.execute(playtime.get(p));
- }
- }.runTask(plugin);
- }
- }.runTaskAsynchronously(plugin);
- }
- Callback<Long> callback = new Callback<Long>()
- {
- public void execute(Long l)
- {
- return l;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement