Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double getDatedifference(Date firstDate, Date secondDate)throws ParseException {
- long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
- double diff = TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS);
- return diff;
- }
- public void setConnectionTime(ProxiedPlayer p) throws ParseException, SQLException{
- connect();
- while(timeTable.next()) {
- if(timeTable.getString("name").equals(p.getDisplayName()) || timeTable.getString("uuid").equals(p.getUniqueId().toString())) {
- DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
- Date dateType = new Date();
- String date = dateFormat.format(dateType);
- String date2 = timeTable.getString("lastConnection");
- double diffLong = getDatedifference(dateFormat.parse(date), dateFormat.parse(date2));
- double weekTime = timeTable.getDouble("weekTime") + diffLong;
- double mounthTime = timeTable.getDouble("mounthTime") + diffLong;
- double total = timeTable.getDouble("total") + diffLong;
- String sql1 = "update timer set weekTime='" + weekTime + "' where name='" + p.getDisplayName() + "'";
- String sql2 = "update timer set mounthTime='" + mounthTime + "' where name='" + p.getDisplayName() + "'";
- String sql3 = "update timer set total='" + total + "' where name='" + p.getDisplayName() + "'";
- statement.executeUpdate(sql1);
- statement.executeUpdate(sql2);
- statement.executeUpdate(sql3);
- }
- }
- disconnect();
- }
- public void connect() throws SQLException {
- String url = "jdbc:mysql://localhost:34614/global";
- String user = "corebungee";
- String password = "pFBHhuFOPAH_yfgua_HBuogbafoy_gaf8INFHBaifbLb09FHNB9LAufAPfopçuhafgà98Fuhkok0LFAHçFAPGUhuFHZOPgfzvtyjuvv9NFZPHUONZFBU";
- connection= DriverManager.getConnection(url, user, password);
- statement = connection.createStatement();
- punishtable= statement.executeQuery("SELECT name, punishmentType from Punishments");
- timeTable = statement.executeQuery("SELECT name, uuid, lastConnection, weekTime, mounthTime, total from timer");
- }
- public void disconnect() throws SQLException {
- connection.close();
- punishtable.close();
- timeTable.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement