Dramastically increase performance

Maybe fix low tps :O
This commit is contained in:
Xephi59 2015-06-27 04:19:59 +02:00
parent 34a87689ed
commit 030e9b599e
12 changed files with 1673 additions and 1300 deletions

View File

@ -54,9 +54,10 @@ import fr.xephi.authme.commands.RegisterCommand;
import fr.xephi.authme.commands.UnregisterCommand;
import fr.xephi.authme.datasource.CacheDataSource;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.FlatFileThread;
import fr.xephi.authme.datasource.MySQLThread;
import fr.xephi.authme.datasource.SQLiteThread;
import fr.xephi.authme.datasource.DatabaseCalls;
import fr.xephi.authme.datasource.FlatFile;
import fr.xephi.authme.datasource.MySQL;
import fr.xephi.authme.datasource.SQLite;
import fr.xephi.authme.listener.AuthMeBlockListener;
import fr.xephi.authme.listener.AuthMeChestShopListener;
import fr.xephi.authme.listener.AuthMeEntityListener;
@ -102,7 +103,6 @@ public class AuthMe extends JavaPlugin {
public HashMap<String, String> realIp = new HashMap<String, String>();
public MultiverseCore multiverse = null;
public Location essentialsSpawn;
public Thread databaseThread = null;
public LookupService ls = null;
public boolean antibotMod = false;
public boolean delayedAntiBot = true;
@ -205,26 +205,20 @@ public class AuthMe extends JavaPlugin {
*/
switch (Settings.getDataSource) {
case FILE:
FlatFileThread fileThread = new FlatFileThread();
fileThread.start();
FlatFile fileThread = new FlatFile();
database = fileThread;
databaseThread = fileThread;
final int a = database.getAccountsRegistered();
if (a >= 1000) {
ConsoleLogger.showError("YOU'RE USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
}
break;
case MYSQL:
MySQLThread sqlThread = new MySQLThread();
sqlThread.start();
MySQL sqlThread = new MySQL();
database = sqlThread;
databaseThread = sqlThread;
break;
case SQLITE:
SQLiteThread sqliteThread = new SQLiteThread();
sqliteThread.start();
SQLite sqliteThread = new SQLite();
database = sqliteThread;
databaseThread = sqliteThread;
final int b = database.getAccountsRegistered();
if (b >= 2000) {
ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
@ -234,19 +228,17 @@ public class AuthMe extends JavaPlugin {
if (Settings.isCachingEnabled) {
database = new CacheDataSource(this, database);
if (database instanceof CacheDataSource)
((CacheDataSource) database).start();
}
database = new DatabaseCalls(this, database);
dataManager = new DataManager(this, database);
dataManager.start();
// Setup API
api = new API(this, database);
// Setup Management
management = new Management(database, this);
management.start();
PluginManager pm = getServer().getPluginManager();
if (Settings.bungee) {
@ -485,16 +477,6 @@ public class AuthMe extends JavaPlugin {
database.close();
}
if (databaseThread != null) {
if (databaseThread.isAlive())
databaseThread.interrupt();
}
if (dataManager != null) {
if (dataManager.isAlive())
dataManager.interrupt();
}
if (Settings.isBackupActivated && Settings.isBackupOnStop) {
Boolean Backup = new PerformBackup(this).DoBackup();
if (Backup)

View File

@ -1,138 +1,154 @@
package fr.xephi.authme;
import java.io.File;
import java.util.List;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.Settings;
public class DataManager extends Thread {
public AuthMe plugin;
public DataSource database;
public DataManager(AuthMe plugin, DataSource database) {
this.plugin = plugin;
this.database = database;
}
public void run() {
}
public OfflinePlayer getOfflinePlayer(String name) {
OfflinePlayer result = null;
try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
if (op.getName().equalsIgnoreCase(name)) {
result = op;
break;
}
} catch (Exception e) {
}
return result;
}
public void purgeAntiXray(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
}
public void purgeLimitedCreative(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
}
public void purgeDat(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
}
public void purgeEssentials(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
}
@SuppressWarnings("deprecation")
public void purgePermissions(List<String> cleared, Permission permission) {
int i = 0;
for (String name : cleared) {
try {
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
for (String group : permission.getPlayerGroups((Player) p)) {
permission.playerRemoveGroup(null, p, group);
}
i++;
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");
}
}
package fr.xephi.authme;
import java.io.File;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.Settings;
public class DataManager {
public AuthMe plugin;
public DataSource database;
public DataManager(AuthMe plugin, DataSource database) {
this.plugin = plugin;
this.database = database;
}
public void run() {
}
public synchronized OfflinePlayer getOfflinePlayer(final String name) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
public synchronized OfflinePlayer call() throws Exception {
OfflinePlayer result = null;
try {
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
if (op.getName().equalsIgnoreCase(name)) {
result = op;
break;
}
} catch (Exception e) {
}
return result;
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (null);
}
}
public synchronized void purgeAntiXray(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
}
public synchronized void purgeLimitedCreative(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
}
public synchronized void purgeDat(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
if (player == null)
continue;
String playerName = player.getName();
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
}
public void purgeEssentials(List<String> cleared) {
int i = 0;
for (String name : cleared) {
try {
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
if (playerFile.exists()) {
playerFile.delete();
i++;
}
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
}
public synchronized void purgePermissions(List<String> cleared,
Permission permission) {
int i = 0;
for (String name : cleared) {
try {
OfflinePlayer p = this.getOfflinePlayer(name);
for (String group : permission.getPlayerGroups((Player) p)) {
permission.playerRemoveGroup(null, p, group);
}
i++;
} catch (Exception e) {
}
}
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");
}
}

View File

@ -243,4 +243,17 @@ public class PlayerAuth {
this.nickname = nickname;
}
public void set(PlayerAuth auth) {
this.setEmail(auth.getEmail());
this.setHash(auth.getHash());
this.setIp(auth.getIp());
this.setLastLogin(auth.getLastLogin());
this.setName(auth.getNickname());
this.setQuitLocX(auth.getQuitLocX());
this.setQuitLocY(auth.getQuitLocY());
this.setQuitLocZ(auth.getQuitLocZ());
this.setSalt(auth.getSalt());
this.setWorld(auth.getWorld());
}
}

View File

@ -8,7 +8,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.datasource.FlatFileThread;
import fr.xephi.authme.datasource.FlatFile;
import fr.xephi.authme.settings.Messages;
public class SqlToFlat implements Converter {
@ -26,8 +26,7 @@ public class SqlToFlat implements Converter {
@Override
public void run() {
try {
FlatFileThread flat = new FlatFileThread();
flat.start();
FlatFile flat = new FlatFile();
List<PlayerAuth> auths = database.getAllAuths();
int i = 0;
final int size = auths.size();
@ -38,8 +37,6 @@ public class SqlToFlat implements Converter {
sender.sendMessage("Conversion Status : " + i + " / " + size);
}
}
if (flat != null && flat.isAlive())
flat.interrupt();
sender.sendMessage("Successfully convert from SQL table to file auths.db");
return;
} catch (Exception ex) {

View File

@ -1,250 +1,245 @@
package fr.xephi.authme.datasource;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
public class CacheDataSource extends Thread implements DataSource {
private DataSource source;
public AuthMe plugin;
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
public CacheDataSource(AuthMe plugin, DataSource source) {
this.plugin = plugin;
this.source = source;
/*
* 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 isAuthAvailable !
*/
for(PlayerAuth auth : source.getAllAuths())
cache.put(auth.getNickname().toLowerCase(), auth);
}
public void run()
{
this.setName("AuthMeCacheThread");
}
@Override
public synchronized boolean isAuthAvailable(String user) {
if (cache.containsKey(user.toLowerCase()))
return true;
return false;
}
@Override
public synchronized PlayerAuth getAuth(String user) {
user = user.toLowerCase();
if (cache.containsKey(user)) {
return cache.get(user);
} else {
PlayerAuth auth = source.getAuth(user);
if (auth != null)
cache.put(user, auth);
return auth;
}
}
@Override
public synchronized boolean saveAuth(PlayerAuth auth) {
if (source.saveAuth(auth)) {
cache.put(auth.getNickname(), auth);
return true;
}
return false;
}
@Override
public synchronized boolean updatePassword(PlayerAuth auth) {
if (source.updatePassword(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setHash(auth.getHash());
return true;
}
return false;
}
@Override
public boolean updateSession(PlayerAuth auth) {
if (source.updateSession(auth)) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setIp(auth.getIp());
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
}
return true;
}
return false;
}
@Override
public boolean updateQuitLoc(PlayerAuth auth) {
if (source.updateQuitLoc(auth)) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
cache.get(auth.getNickname()).setWorld(auth.getWorld());
}
return true;
}
return false;
}
@Override
public int getIps(String ip) {
return source.getIps(ip);
}
@Override
public int purgeDatabase(long until) {
int cleared = source.purgeDatabase(until);
if (cleared > 0) {
for (PlayerAuth auth : cache.values()) {
if (auth.getLastLogin() < until) {
cache.remove(auth.getNickname());
}
}
}
return cleared;
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
if (cleared.size() > 0) {
for (PlayerAuth auth : cache.values()) {
if (auth.getLastLogin() < until) {
cache.remove(auth.getNickname());
}
}
}
return cleared;
}
@Override
public synchronized boolean removeAuth(String user) {
if (source.removeAuth(user)) {
cache.remove(user);
return true;
}
return false;
}
@Override
public synchronized void close() {
source.close();
this.interrupt();
}
@Override
public void reload() {
cache.clear();
source.reload();
for (Player player : plugin.getServer().getOnlinePlayers()) {
String user = player.getName().toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(user)) {
try {
PlayerAuth auth = source.getAuth(user);
cache.put(user, auth);
} catch (NullPointerException npe) {
}
}
}
}
@Override
public synchronized boolean updateEmail(PlayerAuth auth) {
if (source.updateEmail(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setEmail(auth.getEmail());
return true;
}
return false;
}
@Override
public synchronized boolean updateSalt(PlayerAuth auth) {
if (source.updateSalt(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setSalt(auth.getSalt());
return true;
}
return false;
}
@Override
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
return source.getAllAuthsByName(auth);
}
@Override
public synchronized List<String> getAllAuthsByIp(String ip) {
return source.getAllAuthsByIp(ip);
}
@Override
public synchronized List<String> getAllAuthsByEmail(String email) {
return source.getAllAuthsByEmail(email);
}
@Override
public synchronized void purgeBanned(List<String> banned) {
source.purgeBanned(banned);
for (PlayerAuth auth : cache.values()) {
if (banned.contains(auth.getNickname())) {
cache.remove(auth.getNickname());
}
}
}
@Override
public DataSourceType getType() {
return source.getType();
}
@Override
public boolean isLogged(String user) {
return source.isLogged(user.toLowerCase());
}
@Override
public void setLogged(String user) {
source.setLogged(user.toLowerCase());
}
@Override
public void setUnlogged(String user) {
source.setUnlogged(user.toLowerCase());
}
@Override
public void purgeLogged() {
source.purgeLogged();
}
@Override
public int getAccountsRegistered() {
return source.getAccountsRegistered();
}
@Override
public void updateName(String oldone, String newone) {
if (cache.containsKey(oldone)) {
cache.put(newone, cache.get(oldone));
cache.remove(oldone);
}
source.updateName(oldone, newone);
}
@Override
public List<PlayerAuth> getAllAuths() {
return source.getAllAuths();
}
}
package fr.xephi.authme.datasource;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
public class CacheDataSource implements DataSource {
private DataSource source;
public AuthMe plugin;
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
public CacheDataSource(AuthMe plugin, DataSource source) {
this.plugin = plugin;
this.source = source;
/*
* 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
* isAuthAvailable !
*/
for (PlayerAuth auth : source.getAllAuths())
cache.put(auth.getNickname().toLowerCase(), auth);
}
@Override
public synchronized boolean isAuthAvailable(String user) {
if (cache.containsKey(user.toLowerCase()))
return true;
return false;
}
@Override
public synchronized PlayerAuth getAuth(String user) {
user = user.toLowerCase();
if (cache.containsKey(user)) {
return cache.get(user);
} else {
PlayerAuth auth = source.getAuth(user);
if (auth != null)
cache.put(user, auth);
return auth;
}
}
@Override
public synchronized boolean saveAuth(PlayerAuth auth) {
if (source.saveAuth(auth)) {
cache.put(auth.getNickname(), auth);
return true;
}
return false;
}
@Override
public synchronized boolean updatePassword(PlayerAuth auth) {
if (source.updatePassword(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setHash(auth.getHash());
return true;
}
return false;
}
@Override
public boolean updateSession(PlayerAuth auth) {
if (source.updateSession(auth)) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setIp(auth.getIp());
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
}
return true;
}
return false;
}
@Override
public boolean updateQuitLoc(PlayerAuth auth) {
if (source.updateQuitLoc(auth)) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
cache.get(auth.getNickname()).setWorld(auth.getWorld());
}
return true;
}
return false;
}
@Override
public int getIps(String ip) {
return source.getIps(ip);
}
@Override
public int purgeDatabase(long until) {
int cleared = source.purgeDatabase(until);
if (cleared > 0) {
for (PlayerAuth auth : cache.values()) {
if (auth.getLastLogin() < until) {
cache.remove(auth.getNickname());
}
}
}
return cleared;
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
if (cleared.size() > 0) {
for (PlayerAuth auth : cache.values()) {
if (auth.getLastLogin() < until) {
cache.remove(auth.getNickname());
}
}
}
return cleared;
}
@Override
public synchronized boolean removeAuth(String user) {
if (source.removeAuth(user)) {
cache.remove(user);
return true;
}
return false;
}
@Override
public synchronized void close() {
source.close();
}
@Override
public void reload() {
cache.clear();
source.reload();
for (Player player : plugin.getServer().getOnlinePlayers()) {
String user = player.getName().toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(user)) {
try {
PlayerAuth auth = source.getAuth(user);
cache.put(user, auth);
} catch (NullPointerException npe) {
}
}
}
}
@Override
public synchronized boolean updateEmail(PlayerAuth auth) {
if (source.updateEmail(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setEmail(auth.getEmail());
return true;
}
return false;
}
@Override
public synchronized boolean updateSalt(PlayerAuth auth) {
if (source.updateSalt(auth)) {
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setSalt(auth.getSalt());
return true;
}
return false;
}
@Override
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
return source.getAllAuthsByName(auth);
}
@Override
public synchronized List<String> getAllAuthsByIp(String ip) {
return source.getAllAuthsByIp(ip);
}
@Override
public synchronized List<String> getAllAuthsByEmail(String email) {
return source.getAllAuthsByEmail(email);
}
@Override
public synchronized void purgeBanned(List<String> banned) {
source.purgeBanned(banned);
for (PlayerAuth auth : cache.values()) {
if (banned.contains(auth.getNickname())) {
cache.remove(auth.getNickname());
}
}
}
@Override
public DataSourceType getType() {
return source.getType();
}
@Override
public boolean isLogged(String user) {
return source.isLogged(user.toLowerCase());
}
@Override
public void setLogged(String user) {
source.setLogged(user.toLowerCase());
}
@Override
public void setUnlogged(String user) {
source.setUnlogged(user.toLowerCase());
}
@Override
public void purgeLogged() {
source.purgeLogged();
}
@Override
public int getAccountsRegistered() {
return source.getAccountsRegistered();
}
@Override
public void updateName(String oldone, String newone) {
if (cache.containsKey(oldone)) {
cache.put(newone, cache.get(oldone));
cache.remove(oldone);
}
source.updateName(oldone, newone);
}
@Override
public List<PlayerAuth> getAllAuths() {
return source.getAllAuths();
}
}

View File

@ -1,68 +1,68 @@
package fr.xephi.authme.datasource;
import java.util.List;
import fr.xephi.authme.cache.auth.PlayerAuth;
public interface DataSource {
public enum DataSourceType {
MYSQL,
FILE,
SQLITE
}
boolean isAuthAvailable(String user);
PlayerAuth getAuth(String user);
boolean saveAuth(PlayerAuth auth);
boolean updateSession(PlayerAuth auth);
boolean updatePassword(PlayerAuth auth);
int purgeDatabase(long until);
List<String> autoPurgeDatabase(long until);
boolean removeAuth(String user);
boolean updateQuitLoc(PlayerAuth auth);
int getIps(String ip);
List<String> getAllAuthsByName(PlayerAuth auth);
List<String> getAllAuthsByIp(String ip);
List<String> getAllAuthsByEmail(String email);
boolean updateEmail(PlayerAuth auth);
boolean updateSalt(PlayerAuth auth);
void close();
void reload();
void purgeBanned(List<String> banned);
DataSourceType getType();
boolean isLogged(String user);
void setLogged(String user);
void setUnlogged(String user);
void purgeLogged();
int getAccountsRegistered();
void updateName(String oldone, String newone);
List<PlayerAuth> getAllAuths();
}
package fr.xephi.authme.datasource;
import java.util.List;
import fr.xephi.authme.cache.auth.PlayerAuth;
public interface DataSource {
public enum DataSourceType {
MYSQL,
FILE,
SQLITE
}
boolean isAuthAvailable(String user);
PlayerAuth getAuth(String user);
boolean saveAuth(PlayerAuth auth);
boolean updateSession(PlayerAuth auth);
boolean updatePassword(PlayerAuth auth);
int purgeDatabase(long until);
List<String> autoPurgeDatabase(long until);
boolean removeAuth(String user);
boolean updateQuitLoc(PlayerAuth auth);
int getIps(String ip);
List<String> getAllAuthsByName(PlayerAuth auth);
List<String> getAllAuthsByIp(String ip);
List<String> getAllAuthsByEmail(String email);
boolean updateEmail(PlayerAuth auth);
boolean updateSalt(PlayerAuth auth);
void close();
void reload();
void purgeBanned(List<String> banned);
DataSourceType getType();
boolean isLogged(String user);
void setLogged(String user);
void setUnlogged(String user);
void purgeLogged();
int getAccountsRegistered();
void updateName(String oldone, String newone);
List<PlayerAuth> getAllAuths();
}

View File

@ -0,0 +1,382 @@
package fr.xephi.authme.datasource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
public class DatabaseCalls implements DataSource {
private AuthMe plugin;
private DataSource database;
public DatabaseCalls(AuthMe plugin, DataSource database) {
this.plugin = plugin;
this.database = database;
}
@Override
public synchronized boolean isAuthAvailable(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.isAuthAvailable(user);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized PlayerAuth getAuth(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<PlayerAuth> result = executor.submit(new Callable<PlayerAuth>() {
public PlayerAuth call() throws Exception {
return database.getAuth(user);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return null;
}
}
@Override
public synchronized boolean saveAuth(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.saveAuth(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized boolean updateSession(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.updateSession(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized boolean updatePassword(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.updatePassword(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized int purgeDatabase(final long until) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> result = executor.submit(new Callable<Integer>() {
public Integer call() throws Exception {
return database.purgeDatabase(until);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (0);
}
}
@Override
public synchronized List<String> autoPurgeDatabase(final long until) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return database.autoPurgeDatabase(until);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (new ArrayList<String>());
}
}
@Override
public synchronized boolean removeAuth(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.removeAuth(user);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized boolean updateQuitLoc(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.updateQuitLoc(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized int getIps(final String ip) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> result = executor.submit(new Callable<Integer>() {
public Integer call() throws Exception {
return database.getIps(ip);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (0);
}
}
@Override
public synchronized List<String> getAllAuthsByName(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return database.getAllAuthsByName(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (new ArrayList<String>());
}
}
@Override
public synchronized List<String> getAllAuthsByIp(final String ip) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return database.getAllAuthsByIp(ip);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (new ArrayList<String>());
}
}
@Override
public synchronized List<String> getAllAuthsByEmail(final String email) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<String>> result = executor.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return database.getAllAuthsByEmail(email);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (new ArrayList<String>());
}
}
@Override
public synchronized boolean updateEmail(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.updateEmail(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized boolean updateSalt(final PlayerAuth auth) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.updateSalt(auth);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized void close() {
database.close();
}
@Override
public synchronized void reload() {
database.reload();
}
@Override
public synchronized void purgeBanned(final List<String> banned) {
new Thread(new Runnable() {
@Override
public synchronized void run() {
database.purgeBanned(banned);
}
}).start();
}
@Override
public synchronized DataSourceType getType() {
return database.getType();
}
@Override
public synchronized boolean isLogged(final String user) {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return database.isLogged(user);
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (false);
}
}
@Override
public synchronized void setLogged(final String user) {
new Thread(new Runnable() {
@Override
public synchronized void run() {
database.setLogged(user);
}
}).start();
}
@Override
public synchronized void setUnlogged(final String user) {
new Thread(new Runnable() {
@Override
public synchronized void run() {
database.setUnlogged(user);
}
}).start();
}
@Override
public synchronized void purgeLogged() {
new Thread(new Runnable() {
@Override
public synchronized void run() {
database.purgeLogged();
}
}).start();
}
@Override
public synchronized int getAccountsRegistered() {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Integer> result = executor.submit(new Callable<Integer>() {
public Integer call() throws Exception {
return database.getAccountsRegistered();
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (0);
}
}
@Override
public synchronized void updateName(final String oldone, final String newone) {
new Thread(new Runnable() {
@Override
public synchronized void run() {
database.updateName(oldone, newone);
}
}).start();
}
@Override
public synchronized List<PlayerAuth> getAllAuths() {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<PlayerAuth>> result = executor.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception {
return database.getAllAuths();
}
});
try {
return result.get();
} catch (InterruptedException | ExecutionException e) {
return (new ArrayList<PlayerAuth>());
}
}
}

View File

@ -18,7 +18,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings;
public class MySQLThread extends Thread implements DataSource {
public class MySQL implements DataSource {
private String host;
private String port;
@ -42,7 +42,7 @@ public class MySQLThread extends Thread implements DataSource {
private List<String> columnOthers;
private MiniConnectionPoolManager conPool;
public void run() {
public MySQL() {
this.host = Settings.getMySQLHost;
this.port = Settings.getMySQLPort;
this.username = Settings.getMySQLUsername;
@ -94,7 +94,6 @@ public class MySQLThread extends Thread implements DataSource {
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
return;
}
this.setName("AuthMeMySQLThread");
}
private synchronized void connect() throws ClassNotFoundException,

View File

@ -16,7 +16,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings;
public class SQLiteThread extends Thread implements DataSource {
public class SQLite implements DataSource {
private String database;
private String tableName;
@ -34,7 +34,7 @@ public class SQLiteThread extends Thread implements DataSource {
private String columnID;
private Connection con;
public void run() {
public SQLite() {
this.database = Settings.getMySQLDatabase;
this.tableName = Settings.getMySQLTablename;
this.columnName = Settings.getMySQLColumnName;
@ -72,7 +72,6 @@ public class SQLiteThread extends Thread implements DataSource {
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
return;
}
this.setName("AuthMeSQLiteThread");
}
private synchronized void connect() throws ClassNotFoundException,

View File

@ -357,14 +357,9 @@ public class AuthMePlayerListener implements Listener {
return;
}
if (!data.isAuthAvailable(name)) {
if (!Settings.isForcedRegistrationEnabled) {
return;
}
}
if (!Settings.isForcedRegistrationEnabled) {
return;
if (!data.isAuthAvailable(name))
return;
}
if (!Settings.isMovementAllowed) {

View File

@ -1,55 +1,54 @@
package fr.xephi.authme.process;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.login.AsyncronousLogin;
import fr.xephi.authme.process.register.AsyncronousRegister;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
/**
*
* @authors Xephi59, <a
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
*
*/
public class Management extends Thread {
public DataSource database;
public AuthMe plugin;
public static RandomString rdm = new RandomString(Settings.captchaLength);
public PluginManager pm;
public Management(DataSource database, AuthMe plugin) {
this.database = database;
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void run() {
}
public void performLogin(final Player player, final String password,
final boolean forceLogin) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){
@Override
public void run() {
new AsyncronousLogin(player, password, forceLogin, plugin, database).process();
}
});
}
public void performRegister(final Player player, final String password,
final String email) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){
@Override
public void run() {
new AsyncronousRegister(player, password, email, plugin, database).process();
}
});
}
}
package fr.xephi.authme.process;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.process.login.AsyncronousLogin;
import fr.xephi.authme.process.register.AsyncronousRegister;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.Settings;
/**
*
* @authors Xephi59, <a
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
*
*/
public class Management {
public DataSource database;
public AuthMe plugin;
public static RandomString rdm = new RandomString(Settings.captchaLength);
public PluginManager pm;
public Management(DataSource database, AuthMe plugin) {
this.database = database;
this.plugin = plugin;
this.pm = plugin.getServer().getPluginManager();
}
public void performLogin(final Player player, final String password,
final boolean forceLogin) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
new AsyncronousLogin(player, password, forceLogin, plugin, database).process();
}
});
}
public void performRegister(final Player player, final String password,
final String email) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
new AsyncronousRegister(player, password, email, plugin, database).process();
}
});
}
}