improve DatabaseCalls,

This commit is contained in:
DNx5 2015-09-15 14:38:55 +07:00
parent 91d6ead466
commit 3620b712b7
7 changed files with 109 additions and 333 deletions

View File

@ -53,13 +53,14 @@ import java.util.zip.GZIPInputStream;
public class AuthMe extends JavaPlugin { public class AuthMe extends JavaPlugin {
private final Server server = getServer();
private static Logger authmeLogger = Logger.getLogger("AuthMe");
private static AuthMe authme; private static AuthMe authme;
private final Server server = getServer();
private final Logger authmeLogger = Logger.getLogger("AuthMe");
public Management management; public Management management;
public NewAPI api; public NewAPI api;
private Utils utils = Utils.getInstance(); private Utils utils = Utils.getInstance();
public SendMailSSL mail = null; public SendMailSSL mail;
private Settings settings; private Settings settings;
private Messages m; private Messages m;
public DataManager dataManager; public DataManager dataManager;
@ -70,8 +71,8 @@ public class AuthMe extends JavaPlugin {
public Permission permission; public Permission permission;
public Essentials ess; public Essentials ess;
public Location essentialsSpawn; public Location essentialsSpawn;
public MultiverseCore multiverse = null; public MultiverseCore multiverse;
public LookupService lookupService = null; public LookupService lookupService;
public CitizensCommunicator citizens; public CitizensCommunicator citizens;
public boolean isCitizensActive = false; public boolean isCitizensActive = false;
public boolean CombatTag = false; public boolean CombatTag = false;
@ -82,7 +83,6 @@ public class AuthMe extends JavaPlugin {
public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>(); public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
public ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>(); public ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>();
public ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>(); public ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>();
protected static String vgUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
public static AuthMe getInstance() { public static AuthMe getInstance() {
return authme; return authme;
@ -131,14 +131,6 @@ public class AuthMe extends JavaPlugin {
// Setup otherAccounts file // Setup otherAccounts file
otherAccounts = OtherAccounts.getInstance(); otherAccounts = OtherAccounts.getInstance();
// Configuration Security Warnings
if (!Settings.isForceSingleSessionEnabled) {
ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
}
if (Settings.getSessionTimeout == 0 && Settings.isSessionsEnabled) {
ConsoleLogger.showError("WARNING!!! You set session timeout to 0, this may cause security issues!");
}
// Setup messages // Setup messages
m = Messages.getInstance(); m = Messages.getInstance();
@ -148,8 +140,9 @@ public class AuthMe extends JavaPlugin {
Metrics metrics = new Metrics(this); Metrics metrics = new Metrics(this);
metrics.start(); metrics.start();
ConsoleLogger.info("Metrics started successfully!"); ConsoleLogger.info("Metrics started successfully!");
} catch (IOException e) { } catch (Exception e) {
// Failed to submit the metrics data // Failed to submit the metrics data
ConsoleLogger.writeStackTrace(e);
ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway..."); ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway...");
} }
@ -258,8 +251,8 @@ public class AuthMe extends JavaPlugin {
// Reload support hook // Reload support hook
if (Settings.reloadSupport) { if (Settings.reloadSupport) {
int playersOnline = Utils.getOnlinePlayers().size();
if (database != null) { if (database != null) {
int playersOnline = Utils.getOnlinePlayers().size();
if (playersOnline < 1) { if (playersOnline < 1) {
database.purgeLogged(); database.purgeLogged();
} else { } else {
@ -281,15 +274,15 @@ public class AuthMe extends JavaPlugin {
pm.registerEvents(new AuthMeServerListener(this), this); pm.registerEvents(new AuthMeServerListener(this), this);
// Register commands // Register commands
this.getCommand("authme").setExecutor(new AdminCommand(this)); getCommand("authme").setExecutor(new AdminCommand(this));
this.getCommand("register").setExecutor(new RegisterCommand(this)); getCommand("register").setExecutor(new RegisterCommand(this));
this.getCommand("login").setExecutor(new LoginCommand(this)); getCommand("login").setExecutor(new LoginCommand(this));
this.getCommand("changepassword").setExecutor(new ChangePasswordCommand(this)); getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
this.getCommand("logout").setExecutor(new LogoutCommand(this)); getCommand("logout").setExecutor(new LogoutCommand(this));
this.getCommand("unregister").setExecutor(new UnregisterCommand(this)); getCommand("unregister").setExecutor(new UnregisterCommand(this));
this.getCommand("email").setExecutor(new EmailCommand(this)); getCommand("email").setExecutor(new EmailCommand(this));
this.getCommand("captcha").setExecutor(new CaptchaCommand(this)); getCommand("captcha").setExecutor(new CaptchaCommand(this));
this.getCommand("converter").setExecutor(new ConverterCommand(this)); getCommand("converter").setExecutor(new ConverterCommand(this));
// Purge on start if enabled // Purge on start if enabled
autoPurge(); autoPurge();
@ -297,6 +290,14 @@ public class AuthMe extends JavaPlugin {
// Start Email recall task if needed // Start Email recall task if needed
recallEmail(); recallEmail();
// Configuration Security Warnings
if (!Settings.isForceSingleSessionEnabled) {
ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
}
if (Settings.getSessionTimeout == 0 && Settings.isSessionsEnabled) {
ConsoleLogger.showError("WARNING!!! You set session timeout to 0, this may cause security issues!");
}
// Sponsor messages // Sponsor messages
ConsoleLogger.info("AuthMe hooks perfectly with the VERYGAMES server hosting!"); ConsoleLogger.info("AuthMe hooks perfectly with the VERYGAMES server hosting!");
ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt."); ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt.");
@ -331,6 +332,8 @@ public class AuthMe extends JavaPlugin {
// Disabled correctly // Disabled correctly
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!"); ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!");
authme = null;
} }
// Stop/unload the server/plugin as defined in the configuration // Stop/unload the server/plugin as defined in the configuration
@ -789,7 +792,7 @@ public class AuthMe extends JavaPlugin {
@Deprecated @Deprecated
public String getVeryGamesIP(Player player) { public String getVeryGamesIP(Player player) {
String realIP = player.getAddress().getAddress().getHostAddress(); String realIP = player.getAddress().getAddress().getHostAddress();
String sUrl = vgUrl; String sUrl = "http://monitor-1.verygames.net/api/?action=ipclean-real-ip&out=raw&ip=%IP%&port=%PORT%";
sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()).replace("%PORT%", "" + player.getAddress().getPort()); sUrl = sUrl.replace("%IP%", player.getAddress().getAddress().getHostAddress()).replace("%PORT%", "" + player.getAddress().getPort());
try { try {
URL url = new URL(sUrl); URL url = new URL(sUrl);

View File

@ -8,7 +8,7 @@ public class PlayerCache {
private ConcurrentHashMap<String, PlayerAuth> cache; private ConcurrentHashMap<String, PlayerAuth> cache;
private PlayerCache() { private PlayerCache() {
cache = new ConcurrentHashMap<String, PlayerAuth>(); cache = new ConcurrentHashMap<>();
} }
public void addPlayer(PlayerAuth auth) { public void addPlayer(PlayerAuth auth) {

View File

@ -11,22 +11,25 @@ import java.util.concurrent.ConcurrentHashMap;
public class CacheDataSource implements DataSource { public class CacheDataSource implements DataSource {
private DataSource source; private final DataSource source;
public AuthMe plugin;
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
public CacheDataSource(AuthMe plugin, DataSource source) { public CacheDataSource(AuthMe plugin, DataSource src) {
this.plugin = plugin; this.source = src;
this.source = source;
/* /*
* We need to load all players in cache ... It will took more time to * We need to load all players in cache ... It will took more time to
* load the server, but it will be much easier to check for an * load the server, but it will be much easier to check for an
* isAuthAvailable ! * isAuthAvailable !
*/ */
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable(){
@Override
public void run() {
for (PlayerAuth auth : source.getAllAuths()) { for (PlayerAuth auth : source.getAllAuths()) {
cache.put(auth.getNickname().toLowerCase(), auth); cache.put(auth.getNickname().toLowerCase(), auth);
} }
} }
});
}
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(String user) {

View File

@ -6,7 +6,7 @@ import java.util.List;
public interface DataSource { public interface DataSource {
public enum DataSourceType { enum DataSourceType {
MYSQL, MYSQL,
FILE, FILE,
SQLITE, SQLITE,

View File

@ -1,67 +1,42 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import fr.xephi.authme.cache.auth.PlayerAuth;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import fr.xephi.authme.cache.auth.PlayerAuth;
public class DatabaseCalls implements DataSource { public class DatabaseCalls implements DataSource {
private DataSource database; private DataSource database;
private final ExecutorService exec;
public DatabaseCalls(DataSource database) { public DatabaseCalls(DataSource database) {
this.database = database; this.database = database;
this.exec = Executors.newCachedThreadPool();
} }
@Override @Override
public synchronized boolean isAuthAvailable(final String user) { public synchronized boolean isAuthAvailable(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.isAuthAvailable(user); return database.isAuthAvailable(user);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized PlayerAuth getAuth(final String user) { public synchronized PlayerAuth getAuth(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
PlayerAuth result;
try { try {
result = executor.submit(new Callable<PlayerAuth>() { return exec.submit(new Callable<PlayerAuth>() {
public PlayerAuth call() throws Exception { public PlayerAuth call() throws Exception {
return database.getAuth(user); return database.getAuth(user);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return null;
} catch (ExecutionException e1) {
return null;
} finally {
executor.shutdown();
}
try {
return result;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
@ -69,332 +44,183 @@ public class DatabaseCalls implements DataSource {
@Override @Override
public synchronized boolean saveAuth(final PlayerAuth auth) { public synchronized boolean saveAuth(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.saveAuth(auth); return database.saveAuth(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized boolean updateSession(final PlayerAuth auth) { public synchronized boolean updateSession(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.updateSession(auth); return database.updateSession(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized boolean updatePassword(final PlayerAuth auth) { public synchronized boolean updatePassword(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.updatePassword(auth); return database.updatePassword(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized int purgeDatabase(final long until) { public synchronized int purgeDatabase(final long until) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Integer result;
try { try {
result = executor.submit(new Callable<Integer>() { return exec.submit(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
return database.purgeDatabase(until); return database.purgeDatabase(until);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return 0;
} catch (ExecutionException e1) {
return 0;
} finally {
executor.shutdown();
}
try {
return result.intValue();
} catch (Exception e) { } catch (Exception e) {
return (0); return -1;
} }
} }
@Override @Override
public synchronized List<String> autoPurgeDatabase(final long until) { public synchronized List<String> autoPurgeDatabase(final long until) {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<String> result;
try { try {
result = executor.submit(new Callable<List<String>>() { return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception { public List<String> call() throws Exception {
return database.autoPurgeDatabase(until); return database.autoPurgeDatabase(until);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return new ArrayList<String>();
} catch (ExecutionException e1) {
return new ArrayList<String>();
} finally {
executor.shutdown();
}
try {
return result;
} catch (Exception e) { } catch (Exception e) {
return (new ArrayList<String>()); return new ArrayList<>();
} }
} }
@Override @Override
public synchronized boolean removeAuth(final String user) { public synchronized boolean removeAuth(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.removeAuth(user); return database.removeAuth(user);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized boolean updateQuitLoc(final PlayerAuth auth) { public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.updateQuitLoc(auth); return database.updateQuitLoc(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized int getIps(final String ip) { public synchronized int getIps(final String ip) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Integer result;
try { try {
result = executor.submit(new Callable<Integer>() { return exec.submit(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
return database.getIps(ip); return database.getIps(ip);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return 0;
} catch (ExecutionException e1) {
return 0;
} finally {
executor.shutdown();
}
try {
return result.intValue();
} catch (Exception e) { } catch (Exception e) {
return (0); return -1;
} }
} }
@Override @Override
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<String> result;
try { try {
result = executor.submit(new Callable<List<String>>() { return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception { public List<String> call() throws Exception {
return database.getAllAuthsByName(auth); return database.getAllAuthsByName(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return new ArrayList<String>();
} catch (ExecutionException e1) {
return new ArrayList<String>();
} finally {
executor.shutdown();
}
try {
return result;
} catch (Exception e) { } catch (Exception e) {
return (new ArrayList<String>()); return new ArrayList<>();
} }
} }
@Override @Override
public synchronized List<String> getAllAuthsByIp(final String ip) { public synchronized List<String> getAllAuthsByIp(final String ip) {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<String> result;
try { try {
result = executor.submit(new Callable<List<String>>() { return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception { public List<String> call() throws Exception {
return database.getAllAuthsByIp(ip); return database.getAllAuthsByIp(ip);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return new ArrayList<String>();
} catch (ExecutionException e1) {
return new ArrayList<String>();
} finally {
executor.shutdown();
}
try {
return result;
} catch (Exception e) { } catch (Exception e) {
return (new ArrayList<String>()); return new ArrayList<>();
} }
} }
@Override @Override
public synchronized List<String> getAllAuthsByEmail(final String email) { public synchronized List<String> getAllAuthsByEmail(final String email) {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<String> result;
try { try {
result = executor.submit(new Callable<List<String>>() { return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception { public List<String> call() throws Exception {
return database.getAllAuthsByEmail(email); return database.getAllAuthsByEmail(email);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return new ArrayList<String>();
} catch (ExecutionException e1) {
return new ArrayList<String>();
} finally {
executor.shutdown();
}
try {
return result;
} catch (Exception e) { } catch (Exception e) {
return (new ArrayList<String>()); return new ArrayList<>();
} }
} }
@Override @Override
public synchronized boolean updateEmail(final PlayerAuth auth) { public synchronized boolean updateEmail(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.updateEmail(auth); return database.updateEmail(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized boolean updateSalt(final PlayerAuth auth) { public synchronized boolean updateSalt(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.updateSalt(auth); return database.updateSalt(auth);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized void close() { public synchronized void close() {
try {
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
database.close(); database.close();
} catch (Exception e) {
e.printStackTrace();
}
} }
@Override @Override
@ -405,8 +231,6 @@ public class DatabaseCalls implements DataSource {
@Override @Override
public synchronized void purgeBanned(final List<String> banned) { public synchronized void purgeBanned(final List<String> banned) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override
public synchronized void run() { public synchronized void run() {
database.purgeBanned(banned); database.purgeBanned(banned);
} }
@ -420,139 +244,90 @@ public class DatabaseCalls implements DataSource {
@Override @Override
public synchronized boolean isLogged(final String user) { public synchronized boolean isLogged(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Boolean result;
try { try {
result = executor.submit(new Callable<Boolean>() { return exec.submit(new Callable<Boolean>() {
public Boolean call() throws Exception { public Boolean call() throws Exception {
return database.isLogged(user); return database.isLogged(user);
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return false;
} catch (ExecutionException e1) {
return false;
} finally {
executor.shutdown();
}
try {
return result.booleanValue();
} catch (Exception e) { } catch (Exception e) {
return (false); return false;
} }
} }
@Override @Override
public synchronized void setLogged(final String user) { public synchronized void setLogged(final String user) {
new Thread(new Runnable() { exec.execute(new Runnable() {
@Override
public synchronized void run() { public synchronized void run() {
database.setLogged(user); database.setLogged(user);
} }
}).start(); });
} }
@Override @Override
public synchronized void setUnlogged(final String user) { public synchronized void setUnlogged(final String user) {
new Thread(new Runnable() { exec.execute(new Runnable() {
@Override
public synchronized void run() { public synchronized void run() {
database.setUnlogged(user); database.setUnlogged(user);
} }
}).start(); });
} }
@Override @Override
public synchronized void purgeLogged() { public synchronized void purgeLogged() {
new Thread(new Runnable() { exec.execute(new Runnable() {
@Override
public synchronized void run() { public synchronized void run() {
database.purgeLogged(); database.purgeLogged();
} }
}).start(); });
} }
@Override @Override
public synchronized int getAccountsRegistered() { public synchronized int getAccountsRegistered() {
ExecutorService executor = Executors.newSingleThreadExecutor();
Integer result;
try { try {
result = executor.submit(new Callable<Integer>() { return exec.submit(new Callable<Integer>() {
public Integer call() throws Exception { public Integer call() throws Exception {
return database.getAccountsRegistered(); return database.getAccountsRegistered();
} }
}).get(); }).get();
} catch (InterruptedException e1) {
return 0;
} catch (ExecutionException e1) {
return 0;
} finally {
executor.shutdown();
}
try {
return result.intValue();
} catch (Exception e) { } catch (Exception e) {
return (0); return -1;
} }
} }
@Override @Override
public synchronized void updateName(final String oldone, public synchronized void updateName(final String oldone, final String newone) {
final String newone) { exec.execute(new Runnable() {
new Thread(new Runnable() {
@Override
public synchronized void run() { public synchronized void run() {
database.updateName(oldone, newone); database.updateName(oldone, newone);
} }
}).start(); });
} }
@Override @Override
public synchronized List<PlayerAuth> getAllAuths() { public synchronized List<PlayerAuth> getAllAuths() {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<PlayerAuth> result;
try { try {
result = executor.submit(new Callable<List<PlayerAuth>>() { return exec.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception { public List<PlayerAuth> call() throws Exception {
return database.getAllAuths(); return database.getAllAuths();
} }
}).get(); }).get();
} catch (InterruptedException e1) { } catch (Exception e) {
return (new ArrayList<PlayerAuth>()); return new ArrayList<>();
} catch (ExecutionException e1) {
return (new ArrayList<PlayerAuth>());
} finally {
executor.shutdown();
} }
return result;
} }
@Override @Override
public List<PlayerAuth> getLoggedPlayers() { public List<PlayerAuth> getLoggedPlayers() {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<PlayerAuth> result;
try { try {
result = executor.submit(new Callable<List<PlayerAuth>>() { return exec.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception { public List<PlayerAuth> call() throws Exception {
return database.getLoggedPlayers(); return database.getLoggedPlayers();
} }
}).get(); }).get();
} catch (InterruptedException e1) { } catch (Exception e) {
return (new ArrayList<PlayerAuth>()); return new ArrayList<>();
} catch (ExecutionException e1) {
return (new ArrayList<PlayerAuth>());
} finally {
executor.shutdown();
} }
return result;
} }
} }

View File

@ -235,14 +235,13 @@ public class MySQL implements DataSource {
} }
} }
@SuppressWarnings("resource")
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(String user) {
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
PlayerAuth pAuth = null; PlayerAuth pAuth = null;
int id = -1; int id;
try { try {
con = getConnection(); con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
@ -1019,7 +1018,7 @@ public class MySQL implements DataSource {
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<PlayerAuth>(); List<PlayerAuth> auths = new ArrayList<>();
Connection con = null; Connection con = null;
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
@ -1028,7 +1027,7 @@ public class MySQL implements DataSource {
pst = con.prepareStatement("SELECT * FROM " + tableName + ";"); pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
rs = pst.executeQuery(); rs = pst.executeQuery();
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth = null; PlayerAuth pAuth;
int id = rs.getInt(columnID); int id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
@ -1052,10 +1051,8 @@ public class MySQL implements DataSource {
byte[] bytes = blob.getBytes(1, (int) blob.length()); byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes)); pAuth.setHash(new String(bytes));
} }
if (rsid != null)
rsid.close(); rsid.close();
} }
if (pAuth != null)
auths.add(pAuth); auths.add(pAuth);
} }
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -30,8 +30,7 @@ public class Management {
this.pm = plugin.getServer().getPluginManager(); this.pm = plugin.getServer().getPluginManager();
} }
public void performLogin(final Player player, final String password, public void performLogin(final Player player, final String password, final boolean forceLogin) {
final boolean forceLogin) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override @Override
@ -41,8 +40,7 @@ public class Management {
}); });
} }
public void performRegister(final Player player, final String password, public void performRegister(final Player player, final String password, final String email) {
final String email) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override @Override