Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.doodlemeat;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.Location;
- import java.sql.PreparedStatement;
- import se.doodlemeat.BasicLoggingTypes.BasicLoggingType;
- import se.doodlemeat.BasicLoggingTypes.DeathLog;
- public class DataLogger implements Runnable {
- private PlayersOnlineME plugin;
- private int tasksPerRun = 5;
- public DataLogger(PlayersOnlineME instance)
- {
- plugin = instance;
- }
- @Override
- public void run() {
- plugin.getLogger().info("Logs count: " + plugin.logs.size());
- // Perform all tasks
- //BasicLoggingType task = null;
- for(int i = 0; i < tasksPerRun; i++)
- {
- BasicLoggingType task = null;
- try {
- task = plugin.logs.take();
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- }
- /*
- // Generic data
- String player_name = task.getPlayername();
- Location player_location = task.getLocation();
- long time_stamp = task.getTimestamp();
- plugin.getLogger().info(player_name + " " + player_location.getX() + "," + player_location.getZ() + " : " + time_stamp);
- switch(task.getType())
- {
- case PLAYER_DEATH:
- DeathLog log = (DeathLog) task;
- PreparedStatement ps;
- try {
- ps = plugin.database.connection
- .prepareStatement("INSERT INTO player_deaths (user_id, x, y, z, time, cause) VALUES(?, ?, ?, ?, ?, ?);");
- ps.setInt(1, getUserID(player_name));
- ps.setInt(2, (int)player_location.getX());
- ps.setInt(3, (int)player_location.getY());
- ps.setInt(4, (int)player_location.getZ());
- ps.setLong(5, time_stamp);
- ps.setString(6, log.getDeathCause().getCause().name());
- ps.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- break;
- case PLAYER_LOGIN:
- // same here
- break;
- case PLAYER_QUIT:
- // and here
- break;
- default:
- break;
- }
- */
- }
- }
- private int getUserID(String player_name) {
- PreparedStatement ps;
- ResultSet rs = null;
- int id = 0;
- try {
- ps = plugin.database.connection
- .prepareStatement("SELECT id FROM " + plugin.table_name + " WHERE name = ?;");
- ps.setString(1, player_name);
- rs = ps.executeQuery();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- /*if(plugin.database.numRows(rs) == 0)
- {
- try {
- ps = plugin.database.connection
- .prepareStatement("INSERT INTO " + plugin.table_name + " (name, online) VALUES(?, 1);", Statement.RETURN_GENERATED_KEYS);
- ps.setString(1, player_name);
- rs = ps.executeQuery();
- rs.next();
- id = rs.getInt(1);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- else
- {*/
- try {
- rs.next();
- id = rs.getInt("id");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- //}
- plugin.getLogger().info("user-id: " + id);
- return id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement