mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-11 06:38:00 +02:00
same fix for normal sqlite
This commit is contained in:
parent
6f22aa779b
commit
c473e81eb9
@ -1,19 +1,13 @@
|
||||
package fr.xephi.authme.datasource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLite implements DataSource {
|
||||
|
||||
private String database;
|
||||
@ -34,7 +28,7 @@ public class SQLite implements DataSource {
|
||||
private String columnLogged;
|
||||
private String columnRealName;
|
||||
|
||||
public SQLite() {
|
||||
public SQLite() throws ClassNotFoundException, SQLException {
|
||||
this.database = Settings.getMySQLDatabase;
|
||||
this.tableName = Settings.getMySQLTablename;
|
||||
this.columnName = Settings.getMySQLColumnName;
|
||||
@ -55,29 +49,13 @@ public class SQLite implements DataSource {
|
||||
try {
|
||||
this.connect();
|
||||
this.setup();
|
||||
} catch (ClassNotFoundException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
if (Settings.isStopEnabled) {
|
||||
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled)
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
if (Settings.isStopEnabled) {
|
||||
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
||||
AuthMe.getInstance().getServer().shutdown();
|
||||
}
|
||||
if (!Settings.isStopEnabled)
|
||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||
return;
|
||||
} catch (ClassNotFoundException | SQLException cnf) {
|
||||
ConsoleLogger.showError("Can't use SQLITE... !");
|
||||
throw cnf;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void connect()
|
||||
throws ClassNotFoundException, SQLException {
|
||||
private synchronized void connect() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
ConsoleLogger.info("SQLite driver loaded");
|
||||
this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||
@ -273,7 +251,7 @@ public class SQLite implements DataSource {
|
||||
public List<String> autoPurgeDatabase(long until) {
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||
pst.setLong(1, until);
|
||||
@ -284,7 +262,7 @@ public class SQLite implements DataSource {
|
||||
return list;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
@ -423,7 +401,7 @@ public class SQLite implements DataSource {
|
||||
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<String>();
|
||||
List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
pst.setString(1, auth.getIp());
|
||||
@ -434,9 +412,9 @@ public class SQLite implements DataSource {
|
||||
return countIp;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
@ -447,7 +425,7 @@ public class SQLite implements DataSource {
|
||||
public List<String> getAllAuthsByIp(String ip) {
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countIp = new ArrayList<String>();
|
||||
List<String> countIp = new ArrayList<>();
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||
pst.setString(1, ip);
|
||||
@ -458,9 +436,9 @@ public class SQLite implements DataSource {
|
||||
return countIp;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
@ -471,7 +449,7 @@ public class SQLite implements DataSource {
|
||||
public List<String> getAllAuthsByEmail(String email) {
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
List<String> countEmail = new ArrayList<String>();
|
||||
List<String> countEmail = new ArrayList<>();
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||
pst.setString(1, email);
|
||||
@ -482,9 +460,9 @@ public class SQLite implements DataSource {
|
||||
return countEmail;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} catch (NullPointerException npe) {
|
||||
return new ArrayList<String>();
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
@ -542,11 +520,9 @@ public class SQLite implements DataSource {
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -560,11 +536,9 @@ public class SQLite implements DataSource {
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -577,18 +551,16 @@ public class SQLite implements DataSource {
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAccountsRegistered() {
|
||||
int result = 0;
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs;
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||
rs = pst.executeQuery();
|
||||
@ -614,23 +586,21 @@ public class SQLite implements DataSource {
|
||||
pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
return;
|
||||
} finally {
|
||||
close(pst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getAllAuths() {
|
||||
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs;
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth = null;
|
||||
PlayerAuth pAuth;
|
||||
if (rs.getString(columnIp).isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
@ -640,8 +610,7 @@ public class SQLite implements DataSource {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
if (pAuth != null)
|
||||
auths.add(pAuth);
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
@ -654,14 +623,14 @@ public class SQLite implements DataSource {
|
||||
|
||||
@Override
|
||||
public List<PlayerAuth> getLoggedPlayers() {
|
||||
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||
List<PlayerAuth> auths = new ArrayList<>();
|
||||
PreparedStatement pst = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs;
|
||||
try {
|
||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||
rs = pst.executeQuery();
|
||||
while (rs.next()) {
|
||||
PlayerAuth pAuth = null;
|
||||
PlayerAuth pAuth;
|
||||
if (rs.getString(columnIp).isEmpty()) {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
} else {
|
||||
@ -671,8 +640,7 @@ public class SQLite implements DataSource {
|
||||
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
|
||||
}
|
||||
}
|
||||
if (pAuth != null)
|
||||
auths.add(pAuth);
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user