playtime.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. event.load("player_login");
  2. event.load("player_logout");
  3. executeOnce = databank.prepare("CREATE TABLE IF NOT EXISTS playtime (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, player_id INT NOT NULL, join_time BIGINT NOT NULL, leave_time BIGINT);");
  4. databank.workerExecute(executeOnce);
  5. msg("dev", "§bPlaytime §rloaded.");
  6. @wait
  7. wait();
  8. player_id = player.getId(player);
  9. igoto(event);
  10. goto("wait");
  11. @player_login
  12. deleteInvalidStatement = databank.prepare("DELETE FROM playtime WHERE player_id = ? AND leave_time IS NULL;", false);
  13. databank.setInt(deleteInvalidStatement, 1, player_id);
  14. databank.workerExecute(deleteInvalidStatement);
  15. joinTimeStatement = databank.prepare("INSERT INTO playtime (player_id, join_time) VALUES (?, ?);", false);
  16. databank.setInt(joinTimeStatement, 1, player_id);
  17. databank.setLong(joinTimeStatement, 2, time.getMillis());
  18. databank.workerExecute(joinTimeStatement);
  19. goto("wait");
  20. @player_logout
  21. leaveTimeStatement = databank.prepare("UPDATE playtime SET leave_time = ? WHERE player_id = ? AND leave_time IS NULL;", false);
  22. databank.setLong(leaveTimeStatement, 1, time.getMillis());
  23. databank.setInt(leaveTimeStatement, 2, player_id);
  24. databank.workerExecute(leaveTimeStatement);
  25. //Leavetime für /seen und /lastseen
  26. nowtime = time.getMillis();
  27. timeStatement = databank.prepare("INSERT INTO logoutdata (player_id,logouttime) SELECT ?, ? ON DUPLICATE KEY UPDATE logoutdata.logouttime=?;", false);
  28. databank.setInt(timeStatement, 1, player.getID(player));
  29. databank.setLong(timeStatement, 2, nowtime);
  30. databank.setLong(timeStatement, 3, nowtime);
  31. databank.workerExecute(timeStatement);
  32. goto("wait");