Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static HashMap<Player,Long> TimePlayed = new HashMap<>();
- public static HashMap<Player,Integer> TimePlayedTimer = new HashMap<>();
- public static Long getTimePlayed(final Player p){
- Bukkit.getScheduler().runTaskAsynchronously(plugin, new BukkitRunnable(){
- @Override
- public void run() {
- try{
- PreparedStatement ps = plugin.MySQL.openConnection().prepareStatement("SELECT playtime FROM users WHERE UUID='"+p.getUniqueId().toString()+"'");
- ResultSet rs = ps.executeQuery();
- if(!rs.next()){
- Stats.playtime.put(p, 0L);
- }
- Long playtime = rs.getLong("playtime");
- rs.close();
- Stats.playtime.put(p, playtime);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- Stats.playtime.put(p, 0L);
- }
- });
- TimePlayedTimer.put(p,Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new BukkitRunnable(){
- @Override
- public void run(){
- if(TimePlayed.get(p) != null){
- Bukkit.getScheduler().cancelTask(TimePlayedTimer.get(p));
- TimePlayedTimer.remove(p);
- Long timeplayed = TimePlayed.get(p);
- TimePlayed.remove(p);
- /**
- * This is the bit I am having issues with
- */
- return timeplayed;
- }
- }
- }, 0, 2));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement