Advertisement
Guest User

Untitled

a guest
May 12th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. public double getDatedifference(Date firstDate, Date secondDate)throws ParseException {
  2.  
  3.  
  4.  
  5. long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
  6. double diff = TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS);
  7.  
  8. return diff;
  9. }
  10.  
  11. public void setConnectionTime(ProxiedPlayer p) throws ParseException, SQLException{
  12. connect();
  13. while(timeTable.next()) {
  14. if(timeTable.getString("name").equals(p.getDisplayName()) || timeTable.getString("uuid").equals(p.getUniqueId().toString())) {
  15. DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
  16. Date dateType = new Date();
  17. String date = dateFormat.format(dateType);
  18.  
  19. String date2 = timeTable.getString("lastConnection");
  20.  
  21. double diffLong = getDatedifference(dateFormat.parse(date), dateFormat.parse(date2));
  22.  
  23. double weekTime = timeTable.getDouble("weekTime") + diffLong;
  24.  
  25. double mounthTime = timeTable.getDouble("mounthTime") + diffLong;
  26.  
  27. double total = timeTable.getDouble("total") + diffLong;
  28.  
  29. String sql1 = "update timer set weekTime='" + weekTime + "' where name='" + p.getDisplayName() + "'";
  30.  
  31. String sql2 = "update timer set mounthTime='" + mounthTime + "' where name='" + p.getDisplayName() + "'";
  32.  
  33. String sql3 = "update timer set total='" + total + "' where name='" + p.getDisplayName() + "'";
  34.  
  35. statement.executeUpdate(sql1);
  36.  
  37. statement.executeUpdate(sql2);
  38.  
  39. statement.executeUpdate(sql3);
  40.  
  41.  
  42. }
  43. }
  44. disconnect();
  45. }
  46.  
  47. public void connect() throws SQLException {
  48. String url = "jdbc:mysql://localhost:34614/global";
  49. String user = "corebungee";
  50. String password = "pFBHhuFOPAH_yfgua_HBuogbafoy_gaf8INFHBaifbLb09FHNB9LAufAPfopçuhafgà98Fuhkok0LFAHçFAPGUhuFHZOPgfzvtyjuvv9NFZPHUONZFBU";
  51. connection= DriverManager.getConnection(url, user, password);
  52. statement = connection.createStatement();
  53. punishtable= statement.executeQuery("SELECT name, punishmentType from Punishments");
  54.  
  55. timeTable = statement.executeQuery("SELECT name, uuid, lastConnection, weekTime, mounthTime, total from timer");
  56. }
  57.  
  58. public void disconnect() throws SQLException {
  59. connection.close();
  60. punishtable.close();
  61. timeTable.close();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement