mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 18:55:11 +01:00
Dramastically increase performance
Maybe fix low tps :O
This commit is contained in:
parent
34a87689ed
commit
030e9b599e
@ -54,9 +54,10 @@ import fr.xephi.authme.commands.RegisterCommand;
|
|||||||
import fr.xephi.authme.commands.UnregisterCommand;
|
import fr.xephi.authme.commands.UnregisterCommand;
|
||||||
import fr.xephi.authme.datasource.CacheDataSource;
|
import fr.xephi.authme.datasource.CacheDataSource;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.datasource.FlatFileThread;
|
import fr.xephi.authme.datasource.DatabaseCalls;
|
||||||
import fr.xephi.authme.datasource.MySQLThread;
|
import fr.xephi.authme.datasource.FlatFile;
|
||||||
import fr.xephi.authme.datasource.SQLiteThread;
|
import fr.xephi.authme.datasource.MySQL;
|
||||||
|
import fr.xephi.authme.datasource.SQLite;
|
||||||
import fr.xephi.authme.listener.AuthMeBlockListener;
|
import fr.xephi.authme.listener.AuthMeBlockListener;
|
||||||
import fr.xephi.authme.listener.AuthMeChestShopListener;
|
import fr.xephi.authme.listener.AuthMeChestShopListener;
|
||||||
import fr.xephi.authme.listener.AuthMeEntityListener;
|
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 HashMap<String, String> realIp = new HashMap<String, String>();
|
||||||
public MultiverseCore multiverse = null;
|
public MultiverseCore multiverse = null;
|
||||||
public Location essentialsSpawn;
|
public Location essentialsSpawn;
|
||||||
public Thread databaseThread = null;
|
|
||||||
public LookupService ls = null;
|
public LookupService ls = null;
|
||||||
public boolean antibotMod = false;
|
public boolean antibotMod = false;
|
||||||
public boolean delayedAntiBot = true;
|
public boolean delayedAntiBot = true;
|
||||||
@ -205,26 +205,20 @@ public class AuthMe extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
switch (Settings.getDataSource) {
|
switch (Settings.getDataSource) {
|
||||||
case FILE:
|
case FILE:
|
||||||
FlatFileThread fileThread = new FlatFileThread();
|
FlatFile fileThread = new FlatFile();
|
||||||
fileThread.start();
|
|
||||||
database = fileThread;
|
database = fileThread;
|
||||||
databaseThread = fileThread;
|
|
||||||
final int a = database.getAccountsRegistered();
|
final int a = database.getAccountsRegistered();
|
||||||
if (a >= 1000) {
|
if (a >= 1000) {
|
||||||
ConsoleLogger.showError("YOU'RE USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
|
ConsoleLogger.showError("YOU'RE USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
MySQLThread sqlThread = new MySQLThread();
|
MySQL sqlThread = new MySQL();
|
||||||
sqlThread.start();
|
|
||||||
database = sqlThread;
|
database = sqlThread;
|
||||||
databaseThread = sqlThread;
|
|
||||||
break;
|
break;
|
||||||
case SQLITE:
|
case SQLITE:
|
||||||
SQLiteThread sqliteThread = new SQLiteThread();
|
SQLite sqliteThread = new SQLite();
|
||||||
sqliteThread.start();
|
|
||||||
database = sqliteThread;
|
database = sqliteThread;
|
||||||
databaseThread = sqliteThread;
|
|
||||||
final int b = database.getAccountsRegistered();
|
final int b = database.getAccountsRegistered();
|
||||||
if (b >= 2000) {
|
if (b >= 2000) {
|
||||||
ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
|
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) {
|
if (Settings.isCachingEnabled) {
|
||||||
database = new CacheDataSource(this, database);
|
database = new CacheDataSource(this, database);
|
||||||
if (database instanceof CacheDataSource)
|
|
||||||
((CacheDataSource) database).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
database = new DatabaseCalls(this, database);
|
||||||
|
|
||||||
dataManager = new DataManager(this, database);
|
dataManager = new DataManager(this, database);
|
||||||
dataManager.start();
|
|
||||||
|
|
||||||
// Setup API
|
// Setup API
|
||||||
api = new API(this, database);
|
api = new API(this, database);
|
||||||
|
|
||||||
// Setup Management
|
// Setup Management
|
||||||
management = new Management(database, this);
|
management = new Management(database, this);
|
||||||
management.start();
|
|
||||||
|
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
if (Settings.bungee) {
|
if (Settings.bungee) {
|
||||||
@ -485,16 +477,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (databaseThread != null) {
|
|
||||||
if (databaseThread.isAlive())
|
|
||||||
databaseThread.interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataManager != null) {
|
|
||||||
if (dataManager.isAlive())
|
|
||||||
dataManager.interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Settings.isBackupActivated && Settings.isBackupOnStop) {
|
if (Settings.isBackupActivated && Settings.isBackupOnStop) {
|
||||||
Boolean Backup = new PerformBackup(this).DoBackup();
|
Boolean Backup = new PerformBackup(this).DoBackup();
|
||||||
if (Backup)
|
if (Backup)
|
||||||
|
@ -1,138 +1,154 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import org.bukkit.Bukkit;
|
import java.util.concurrent.Executors;
|
||||||
import org.bukkit.OfflinePlayer;
|
import java.util.concurrent.Future;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
public class DataManager extends Thread {
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public AuthMe plugin;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
public DataSource database;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
public DataManager(AuthMe plugin, DataSource database) {
|
public class DataManager {
|
||||||
this.plugin = plugin;
|
|
||||||
this.database = database;
|
public AuthMe plugin;
|
||||||
}
|
public DataSource database;
|
||||||
|
|
||||||
public void run() {
|
public DataManager(AuthMe plugin, DataSource database) {
|
||||||
}
|
this.plugin = plugin;
|
||||||
|
this.database = database;
|
||||||
public OfflinePlayer getOfflinePlayer(String name) {
|
}
|
||||||
OfflinePlayer result = null;
|
|
||||||
try {
|
public void run() {
|
||||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
|
}
|
||||||
if (op.getName().equalsIgnoreCase(name)) {
|
|
||||||
result = op;
|
public synchronized OfflinePlayer getOfflinePlayer(final String name) {
|
||||||
break;
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
}
|
Future<OfflinePlayer> result = executor.submit(new Callable<OfflinePlayer>() {
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
public synchronized OfflinePlayer call() throws Exception {
|
||||||
return result;
|
OfflinePlayer result = null;
|
||||||
}
|
try {
|
||||||
|
for (OfflinePlayer op : Bukkit.getOfflinePlayers())
|
||||||
public void purgeAntiXray(List<String> cleared) {
|
if (op.getName().equalsIgnoreCase(name)) {
|
||||||
int i = 0;
|
result = op;
|
||||||
for (String name : cleared) {
|
break;
|
||||||
try {
|
}
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
} catch (Exception e) {
|
||||||
if (player == null)
|
}
|
||||||
continue;
|
return result;
|
||||||
String playerName = player.getName();
|
}
|
||||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
|
});
|
||||||
if (playerFile.exists()) {
|
try {
|
||||||
playerFile.delete();
|
return result.get();
|
||||||
i++;
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
}
|
return (null);
|
||||||
} catch (Exception e) {
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
|
public synchronized void purgeAntiXray(List<String> cleared) {
|
||||||
}
|
int i = 0;
|
||||||
|
for (String name : cleared) {
|
||||||
public void purgeLimitedCreative(List<String> cleared) {
|
try {
|
||||||
int i = 0;
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
for (String name : cleared) {
|
if (player == null)
|
||||||
try {
|
continue;
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
String playerName = player.getName();
|
||||||
if (player == null)
|
File playerFile = new File("." + File.separator + "plugins" + File.separator + "AntiXRayData" + File.separator + "PlayerData" + File.separator + playerName);
|
||||||
continue;
|
if (playerFile.exists()) {
|
||||||
String playerName = player.getName();
|
playerFile.delete();
|
||||||
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
|
i++;
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
} catch (Exception e) {
|
||||||
i++;
|
}
|
||||||
}
|
}
|
||||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " AntiXRayData Files");
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
|
||||||
i++;
|
public synchronized void purgeLimitedCreative(List<String> cleared) {
|
||||||
}
|
int i = 0;
|
||||||
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
|
for (String name : cleared) {
|
||||||
if (playerFile.exists()) {
|
try {
|
||||||
playerFile.delete();
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
i++;
|
if (player == null)
|
||||||
}
|
continue;
|
||||||
} catch (Exception e) {
|
String playerName = player.getName();
|
||||||
}
|
File playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + ".yml");
|
||||||
}
|
if (playerFile.exists()) {
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
|
playerFile.delete();
|
||||||
}
|
i++;
|
||||||
|
}
|
||||||
public void purgeDat(List<String> cleared) {
|
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_creative.yml");
|
||||||
int i = 0;
|
if (playerFile.exists()) {
|
||||||
for (String name : cleared) {
|
playerFile.delete();
|
||||||
try {
|
i++;
|
||||||
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
}
|
||||||
if (player == null)
|
playerFile = new File("." + File.separator + "plugins" + File.separator + "LimitedCreative" + File.separator + "inventories" + File.separator + playerName + "_adventure.yml");
|
||||||
continue;
|
if (playerFile.exists()) {
|
||||||
String playerName = player.getName();
|
playerFile.delete();
|
||||||
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat");
|
i++;
|
||||||
if (playerFile.exists()) {
|
}
|
||||||
playerFile.delete();
|
} catch (Exception e) {
|
||||||
i++;
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " LimitedCreative Survival, Creative and Adventure files");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
public synchronized void purgeDat(List<String> cleared) {
|
||||||
}
|
int i = 0;
|
||||||
|
for (String name : cleared) {
|
||||||
public void purgeEssentials(List<String> cleared) {
|
try {
|
||||||
int i = 0;
|
org.bukkit.OfflinePlayer player = getOfflinePlayer(name);
|
||||||
for (String name : cleared) {
|
if (player == null)
|
||||||
try {
|
continue;
|
||||||
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
String playerName = player.getName();
|
||||||
if (playerFile.exists()) {
|
File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat");
|
||||||
playerFile.delete();
|
if (playerFile.exists()) {
|
||||||
i++;
|
playerFile.delete();
|
||||||
}
|
i++;
|
||||||
} catch (Exception e) {
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles");
|
}
|
||||||
}
|
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files");
|
||||||
|
}
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void purgePermissions(List<String> cleared, Permission permission) {
|
public void purgeEssentials(List<String> cleared) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String name : cleared) {
|
for (String name : cleared) {
|
||||||
try {
|
try {
|
||||||
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml");
|
||||||
for (String group : permission.getPlayerGroups((Player) p)) {
|
if (playerFile.exists()) {
|
||||||
permission.playerRemoveGroup(null, p, group);
|
playerFile.delete();
|
||||||
}
|
i++;
|
||||||
i++;
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " Permissions");
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -243,4 +243,17 @@ public class PlayerAuth {
|
|||||||
this.nickname = nickname;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import fr.xephi.authme.AuthMe;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.datasource.FlatFileThread;
|
import fr.xephi.authme.datasource.FlatFile;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
|
|
||||||
public class SqlToFlat implements Converter {
|
public class SqlToFlat implements Converter {
|
||||||
@ -26,8 +26,7 @@ public class SqlToFlat implements Converter {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
FlatFileThread flat = new FlatFileThread();
|
FlatFile flat = new FlatFile();
|
||||||
flat.start();
|
|
||||||
List<PlayerAuth> auths = database.getAllAuths();
|
List<PlayerAuth> auths = database.getAllAuths();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
final int size = auths.size();
|
final int size = auths.size();
|
||||||
@ -38,8 +37,6 @@ public class SqlToFlat implements Converter {
|
|||||||
sender.sendMessage("Conversion Status : " + i + " / " + size);
|
sender.sendMessage("Conversion Status : " + i + " / " + size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flat != null && flat.isAlive())
|
|
||||||
flat.interrupt();
|
|
||||||
sender.sendMessage("Successfully convert from SQL table to file auths.db");
|
sender.sendMessage("Successfully convert from SQL table to file auths.db");
|
||||||
return;
|
return;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -1,250 +1,245 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
public class CacheDataSource extends Thread implements DataSource {
|
|
||||||
|
public class CacheDataSource implements DataSource {
|
||||||
private DataSource source;
|
|
||||||
public AuthMe plugin;
|
private DataSource source;
|
||||||
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
|
public AuthMe plugin;
|
||||||
|
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
|
||||||
public CacheDataSource(AuthMe plugin, DataSource source) {
|
|
||||||
this.plugin = plugin;
|
public CacheDataSource(AuthMe plugin, DataSource source) {
|
||||||
this.source = source;
|
this.plugin = plugin;
|
||||||
/*
|
this.source = source;
|
||||||
* We need to load all players in cache ...
|
/*
|
||||||
* It will took more time to load the server,
|
* We need to load all players in cache ... It will took more time to
|
||||||
* but it will be much easier to check for an isAuthAvailable !
|
* 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);
|
for (PlayerAuth auth : source.getAllAuths())
|
||||||
}
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
|
}
|
||||||
public void run()
|
|
||||||
{
|
@Override
|
||||||
this.setName("AuthMeCacheThread");
|
public synchronized boolean isAuthAvailable(String user) {
|
||||||
}
|
if (cache.containsKey(user.toLowerCase()))
|
||||||
|
return true;
|
||||||
@Override
|
return false;
|
||||||
public synchronized boolean isAuthAvailable(String user) {
|
}
|
||||||
if (cache.containsKey(user.toLowerCase()))
|
|
||||||
return true;
|
@Override
|
||||||
return false;
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
}
|
user = user.toLowerCase();
|
||||||
|
if (cache.containsKey(user)) {
|
||||||
@Override
|
return cache.get(user);
|
||||||
public synchronized PlayerAuth getAuth(String user) {
|
} else {
|
||||||
user = user.toLowerCase();
|
PlayerAuth auth = source.getAuth(user);
|
||||||
if (cache.containsKey(user)) {
|
if (auth != null)
|
||||||
return cache.get(user);
|
cache.put(user, auth);
|
||||||
} else {
|
return auth;
|
||||||
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);
|
||||||
@Override
|
return true;
|
||||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
}
|
||||||
if (source.saveAuth(auth)) {
|
return false;
|
||||||
cache.put(auth.getNickname(), auth);
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||||
}
|
if (source.updatePassword(auth)) {
|
||||||
|
if (cache.containsKey(auth.getNickname()))
|
||||||
@Override
|
cache.get(auth.getNickname()).setHash(auth.getHash());
|
||||||
public synchronized boolean updatePassword(PlayerAuth auth) {
|
return true;
|
||||||
if (source.updatePassword(auth)) {
|
}
|
||||||
if (cache.containsKey(auth.getNickname()))
|
return false;
|
||||||
cache.get(auth.getNickname()).setHash(auth.getHash());
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public boolean updateSession(PlayerAuth auth) {
|
||||||
}
|
if (source.updateSession(auth)) {
|
||||||
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
@Override
|
cache.get(auth.getNickname()).setIp(auth.getIp());
|
||||||
public boolean updateSession(PlayerAuth auth) {
|
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
|
||||||
if (source.updateSession(auth)) {
|
}
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
return true;
|
||||||
cache.get(auth.getNickname()).setIp(auth.getIp());
|
}
|
||||||
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||||
}
|
if (source.updateQuitLoc(auth)) {
|
||||||
|
if (cache.containsKey(auth.getNickname())) {
|
||||||
@Override
|
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
|
||||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
|
||||||
if (source.updateQuitLoc(auth)) {
|
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
cache.get(auth.getNickname()).setWorld(auth.getWorld());
|
||||||
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
|
}
|
||||||
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
|
return true;
|
||||||
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
|
}
|
||||||
cache.get(auth.getNickname()).setWorld(auth.getWorld());
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public int getIps(String ip) {
|
||||||
}
|
return source.getIps(ip);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public int getIps(String ip) {
|
@Override
|
||||||
return source.getIps(ip);
|
public int purgeDatabase(long until) {
|
||||||
}
|
int cleared = source.purgeDatabase(until);
|
||||||
|
if (cleared > 0) {
|
||||||
@Override
|
for (PlayerAuth auth : cache.values()) {
|
||||||
public int purgeDatabase(long until) {
|
if (auth.getLastLogin() < until) {
|
||||||
int cleared = source.purgeDatabase(until);
|
cache.remove(auth.getNickname());
|
||||||
if (cleared > 0) {
|
}
|
||||||
for (PlayerAuth auth : cache.values()) {
|
}
|
||||||
if (auth.getLastLogin() < until) {
|
}
|
||||||
cache.remove(auth.getNickname());
|
return cleared;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
return cleared;
|
public List<String> autoPurgeDatabase(long until) {
|
||||||
}
|
List<String> cleared = source.autoPurgeDatabase(until);
|
||||||
|
if (cleared.size() > 0) {
|
||||||
@Override
|
for (PlayerAuth auth : cache.values()) {
|
||||||
public List<String> autoPurgeDatabase(long until) {
|
if (auth.getLastLogin() < until) {
|
||||||
List<String> cleared = source.autoPurgeDatabase(until);
|
cache.remove(auth.getNickname());
|
||||||
if (cleared.size() > 0) {
|
}
|
||||||
for (PlayerAuth auth : cache.values()) {
|
}
|
||||||
if (auth.getLastLogin() < until) {
|
}
|
||||||
cache.remove(auth.getNickname());
|
return cleared;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@Override
|
||||||
return cleared;
|
public synchronized boolean removeAuth(String user) {
|
||||||
}
|
if (source.removeAuth(user)) {
|
||||||
|
cache.remove(user);
|
||||||
@Override
|
return true;
|
||||||
public synchronized boolean removeAuth(String user) {
|
}
|
||||||
if (source.removeAuth(user)) {
|
return false;
|
||||||
cache.remove(user);
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
return false;
|
public synchronized void close() {
|
||||||
}
|
source.close();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public synchronized void close() {
|
@Override
|
||||||
source.close();
|
public void reload() {
|
||||||
this.interrupt();
|
cache.clear();
|
||||||
}
|
source.reload();
|
||||||
|
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||||
@Override
|
String user = player.getName().toLowerCase();
|
||||||
public void reload() {
|
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
||||||
cache.clear();
|
try {
|
||||||
source.reload();
|
PlayerAuth auth = source.getAuth(user);
|
||||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
cache.put(user, auth);
|
||||||
String user = player.getName().toLowerCase();
|
} catch (NullPointerException npe) {
|
||||||
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());
|
||||||
@Override
|
return true;
|
||||||
public synchronized boolean updateEmail(PlayerAuth auth) {
|
}
|
||||||
if (source.updateEmail(auth)) {
|
return false;
|
||||||
if (cache.containsKey(auth.getNickname()))
|
}
|
||||||
cache.get(auth.getNickname()).setEmail(auth.getEmail());
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public synchronized boolean updateSalt(PlayerAuth auth) {
|
||||||
return false;
|
if (source.updateSalt(auth)) {
|
||||||
}
|
if (cache.containsKey(auth.getNickname()))
|
||||||
|
cache.get(auth.getNickname()).setSalt(auth.getSalt());
|
||||||
@Override
|
return true;
|
||||||
public synchronized boolean updateSalt(PlayerAuth auth) {
|
}
|
||||||
if (source.updateSalt(auth)) {
|
return false;
|
||||||
if (cache.containsKey(auth.getNickname()))
|
}
|
||||||
cache.get(auth.getNickname()).setSalt(auth.getSalt());
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||||
return false;
|
return source.getAllAuthsByName(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
|
public synchronized List<String> getAllAuthsByIp(String ip) {
|
||||||
return source.getAllAuthsByName(auth);
|
return source.getAllAuthsByIp(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
public synchronized List<String> getAllAuthsByEmail(String email) {
|
||||||
return source.getAllAuthsByIp(ip);
|
return source.getAllAuthsByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
public synchronized void purgeBanned(List<String> banned) {
|
||||||
return source.getAllAuthsByEmail(email);
|
source.purgeBanned(banned);
|
||||||
}
|
for (PlayerAuth auth : cache.values()) {
|
||||||
|
if (banned.contains(auth.getNickname())) {
|
||||||
@Override
|
cache.remove(auth.getNickname());
|
||||||
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
|
@Override
|
||||||
public DataSourceType getType() {
|
public boolean isLogged(String user) {
|
||||||
return source.getType();
|
return source.isLogged(user.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogged(String user) {
|
public void setLogged(String user) {
|
||||||
return source.isLogged(user.toLowerCase());
|
source.setLogged(user.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLogged(String user) {
|
public void setUnlogged(String user) {
|
||||||
source.setLogged(user.toLowerCase());
|
source.setUnlogged(user.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUnlogged(String user) {
|
public void purgeLogged() {
|
||||||
source.setUnlogged(user.toLowerCase());
|
source.purgeLogged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void purgeLogged() {
|
public int getAccountsRegistered() {
|
||||||
source.purgeLogged();
|
return source.getAccountsRegistered();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAccountsRegistered() {
|
public void updateName(String oldone, String newone) {
|
||||||
return source.getAccountsRegistered();
|
if (cache.containsKey(oldone)) {
|
||||||
}
|
cache.put(newone, cache.get(oldone));
|
||||||
|
cache.remove(oldone);
|
||||||
@Override
|
}
|
||||||
public void updateName(String oldone, String newone) {
|
source.updateName(oldone, newone);
|
||||||
if (cache.containsKey(oldone)) {
|
}
|
||||||
cache.put(newone, cache.get(oldone));
|
|
||||||
cache.remove(oldone);
|
@Override
|
||||||
}
|
public List<PlayerAuth> getAllAuths() {
|
||||||
source.updateName(oldone, newone);
|
return source.getAllAuths();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public List<PlayerAuth> getAllAuths() {
|
|
||||||
return source.getAllAuths();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,68 +1,68 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
|
||||||
public interface DataSource {
|
public interface DataSource {
|
||||||
|
|
||||||
public enum DataSourceType {
|
public enum DataSourceType {
|
||||||
|
|
||||||
MYSQL,
|
MYSQL,
|
||||||
FILE,
|
FILE,
|
||||||
SQLITE
|
SQLITE
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAuthAvailable(String user);
|
boolean isAuthAvailable(String user);
|
||||||
|
|
||||||
PlayerAuth getAuth(String user);
|
PlayerAuth getAuth(String user);
|
||||||
|
|
||||||
boolean saveAuth(PlayerAuth auth);
|
boolean saveAuth(PlayerAuth auth);
|
||||||
|
|
||||||
boolean updateSession(PlayerAuth auth);
|
boolean updateSession(PlayerAuth auth);
|
||||||
|
|
||||||
boolean updatePassword(PlayerAuth auth);
|
boolean updatePassword(PlayerAuth auth);
|
||||||
|
|
||||||
int purgeDatabase(long until);
|
int purgeDatabase(long until);
|
||||||
|
|
||||||
List<String> autoPurgeDatabase(long until);
|
List<String> autoPurgeDatabase(long until);
|
||||||
|
|
||||||
boolean removeAuth(String user);
|
boolean removeAuth(String user);
|
||||||
|
|
||||||
boolean updateQuitLoc(PlayerAuth auth);
|
boolean updateQuitLoc(PlayerAuth auth);
|
||||||
|
|
||||||
int getIps(String ip);
|
int getIps(String ip);
|
||||||
|
|
||||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||||
|
|
||||||
List<String> getAllAuthsByIp(String ip);
|
List<String> getAllAuthsByIp(String ip);
|
||||||
|
|
||||||
List<String> getAllAuthsByEmail(String email);
|
List<String> getAllAuthsByEmail(String email);
|
||||||
|
|
||||||
boolean updateEmail(PlayerAuth auth);
|
boolean updateEmail(PlayerAuth auth);
|
||||||
|
|
||||||
boolean updateSalt(PlayerAuth auth);
|
boolean updateSalt(PlayerAuth auth);
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
void purgeBanned(List<String> banned);
|
void purgeBanned(List<String> banned);
|
||||||
|
|
||||||
DataSourceType getType();
|
DataSourceType getType();
|
||||||
|
|
||||||
boolean isLogged(String user);
|
boolean isLogged(String user);
|
||||||
|
|
||||||
void setLogged(String user);
|
void setLogged(String user);
|
||||||
|
|
||||||
void setUnlogged(String user);
|
void setUnlogged(String user);
|
||||||
|
|
||||||
void purgeLogged();
|
void purgeLogged();
|
||||||
|
|
||||||
int getAccountsRegistered();
|
int getAccountsRegistered();
|
||||||
|
|
||||||
void updateName(String oldone, String newone);
|
void updateName(String oldone, String newone);
|
||||||
|
|
||||||
List<PlayerAuth> getAllAuths();
|
List<PlayerAuth> getAllAuths();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
382
src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java
Normal file
382
src/main/java/fr/xephi/authme/datasource/DatabaseCalls.java
Normal 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>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -18,7 +18,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
|
|||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
public class MySQLThread extends Thread implements DataSource {
|
public class MySQL implements DataSource {
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private String port;
|
private String port;
|
||||||
@ -42,7 +42,7 @@ public class MySQLThread extends Thread implements DataSource {
|
|||||||
private List<String> columnOthers;
|
private List<String> columnOthers;
|
||||||
private MiniConnectionPoolManager conPool;
|
private MiniConnectionPoolManager conPool;
|
||||||
|
|
||||||
public void run() {
|
public MySQL() {
|
||||||
this.host = Settings.getMySQLHost;
|
this.host = Settings.getMySQLHost;
|
||||||
this.port = Settings.getMySQLPort;
|
this.port = Settings.getMySQLPort;
|
||||||
this.username = Settings.getMySQLUsername;
|
this.username = Settings.getMySQLUsername;
|
||||||
@ -94,7 +94,6 @@ public class MySQLThread extends Thread implements DataSource {
|
|||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setName("AuthMeMySQLThread");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void connect() throws ClassNotFoundException,
|
private synchronized void connect() throws ClassNotFoundException,
|
@ -16,7 +16,7 @@ import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
|
|||||||
import fr.xephi.authme.settings.PlayersLogs;
|
import fr.xephi.authme.settings.PlayersLogs;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
public class SQLiteThread extends Thread implements DataSource {
|
public class SQLite implements DataSource {
|
||||||
|
|
||||||
private String database;
|
private String database;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
@ -34,7 +34,7 @@ public class SQLiteThread extends Thread implements DataSource {
|
|||||||
private String columnID;
|
private String columnID;
|
||||||
private Connection con;
|
private Connection con;
|
||||||
|
|
||||||
public void run() {
|
public SQLite() {
|
||||||
this.database = Settings.getMySQLDatabase;
|
this.database = Settings.getMySQLDatabase;
|
||||||
this.tableName = Settings.getMySQLTablename;
|
this.tableName = Settings.getMySQLTablename;
|
||||||
this.columnName = Settings.getMySQLColumnName;
|
this.columnName = Settings.getMySQLColumnName;
|
||||||
@ -72,7 +72,6 @@ public class SQLiteThread extends Thread implements DataSource {
|
|||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setName("AuthMeSQLiteThread");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void connect() throws ClassNotFoundException,
|
private synchronized void connect() throws ClassNotFoundException,
|
@ -357,14 +357,9 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.isAuthAvailable(name)) {
|
|
||||||
if (!Settings.isForcedRegistrationEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Settings.isForcedRegistrationEnabled) {
|
if (!Settings.isForcedRegistrationEnabled) {
|
||||||
return;
|
if (!data.isAuthAvailable(name))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Settings.isMovementAllowed) {
|
if (!Settings.isMovementAllowed) {
|
||||||
|
@ -1,55 +1,54 @@
|
|||||||
package fr.xephi.authme.process;
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.process.login.AsyncronousLogin;
|
import fr.xephi.authme.process.login.AsyncronousLogin;
|
||||||
import fr.xephi.authme.process.register.AsyncronousRegister;
|
import fr.xephi.authme.process.register.AsyncronousRegister;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @authors Xephi59, <a
|
* @authors Xephi59, <a
|
||||||
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
* href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Management extends Thread {
|
public class Management {
|
||||||
|
|
||||||
public DataSource database;
|
public DataSource database;
|
||||||
public AuthMe plugin;
|
public AuthMe plugin;
|
||||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
||||||
public PluginManager pm;
|
public PluginManager pm;
|
||||||
|
|
||||||
public Management(DataSource database, AuthMe plugin) {
|
public Management(DataSource database, AuthMe plugin) {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.pm = plugin.getServer().getPluginManager();
|
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() {
|
||||||
public void performLogin(final Player player, final String password,
|
|
||||||
final boolean forceLogin) {
|
@Override
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){
|
public void run() {
|
||||||
@Override
|
new AsyncronousLogin(player, password, forceLogin, plugin, database).process();
|
||||||
public void run() {
|
}
|
||||||
new AsyncronousLogin(player, password, forceLogin, plugin, database).process();
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
public void performRegister(final Player player, final String password,
|
||||||
|
final String email) {
|
||||||
public void performRegister(final Player player, final String password,
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
final String email) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
new AsyncronousRegister(player, password, email, plugin, database).process();
|
||||||
new AsyncronousRegister(player, password, email, plugin, database).process();
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user