mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
changed settings load method.
This commit is contained in:
parent
7c56dec476
commit
0b23074770
@ -53,7 +53,7 @@ import java.util.zip.GZIPInputStream;
|
|||||||
|
|
||||||
public class AuthMe extends JavaPlugin {
|
public class AuthMe extends JavaPlugin {
|
||||||
|
|
||||||
private static Server server;
|
private final Server server = getServer();
|
||||||
private static Logger authmeLogger = Logger.getLogger("AuthMe");
|
private static Logger authmeLogger = Logger.getLogger("AuthMe");
|
||||||
private static AuthMe authme;
|
private static AuthMe authme;
|
||||||
public Management management;
|
public Management management;
|
||||||
@ -76,7 +76,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
public boolean isCitizensActive = false;
|
public boolean isCitizensActive = false;
|
||||||
public boolean CombatTag = false;
|
public boolean CombatTag = false;
|
||||||
public boolean legacyChestShop = false;
|
public boolean legacyChestShop = false;
|
||||||
public boolean BungeeCord = false;
|
|
||||||
public boolean antibotMod = false;
|
public boolean antibotMod = false;
|
||||||
public boolean delayedAntiBot = true;
|
public boolean delayedAntiBot = true;
|
||||||
public ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
public ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
||||||
@ -93,14 +92,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataSource getAuthMeDatabase() {
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthMeDatabase(DataSource database) {
|
|
||||||
this.database = database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessages(Messages m) {
|
public void setMessages(Messages m) {
|
||||||
this.m = m;
|
this.m = m;
|
||||||
}
|
}
|
||||||
@ -120,8 +111,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// TODO: split the plugin in more modules
|
// TODO: split the plugin in more modules
|
||||||
// TODO: remove vault as hard dependency
|
// TODO: remove vault as hard dependency
|
||||||
|
|
||||||
server = getServer();
|
|
||||||
PluginManager pm = server.getPluginManager();
|
PluginManager pm = server.getPluginManager();
|
||||||
|
|
||||||
// Setup the Logger
|
// Setup the Logger
|
||||||
@ -131,9 +120,11 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// TODO: new configuration style (more files)
|
// TODO: new configuration style (more files)
|
||||||
try {
|
try {
|
||||||
settings = new Settings(this);
|
settings = new Settings(this);
|
||||||
|
settings.reload();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
ConsoleLogger.showError("Can't load the configuration file... Something went wrong, to avoid security issues the server will shutdown!");
|
ConsoleLogger.showError("Can't load the configuration file... Something went wrong, to avoid security issues the server will shutdown!");
|
||||||
this.getServer().shutdown();
|
server.shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +223,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// Connect to the database and setup tables
|
// Connect to the database and setup tables
|
||||||
try {
|
try {
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
} catch (ClassNotFoundException | SQLException | PoolInitializationException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.writeStackTrace(ex);
|
ConsoleLogger.writeStackTrace(ex);
|
||||||
ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!");
|
ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!");
|
||||||
stopOrUnload();
|
stopOrUnload();
|
||||||
@ -346,7 +337,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
public void stopOrUnload() {
|
public void stopOrUnload() {
|
||||||
if (Settings.isStopEnabled) {
|
if (Settings.isStopEnabled) {
|
||||||
ConsoleLogger.showError("THE SERVER IS GOING TO SHUTDOWN AS DEFINED IN THE CONFIGURATION!");
|
ConsoleLogger.showError("THE SERVER IS GOING TO SHUTDOWN AS DEFINED IN THE CONFIGURATION!");
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
server.shutdown();
|
||||||
} else {
|
} else {
|
||||||
server.getPluginManager().disablePlugin(AuthMe.getInstance());
|
server.getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
}
|
}
|
||||||
@ -391,7 +382,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
|
||||||
Converter converter = new ForceFlatToSqlite(database, this);
|
Converter converter = new ForceFlatToSqlite(database, this);
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, converter);
|
server.getScheduler().runTaskAsynchronously(this, converter);
|
||||||
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !");
|
ConsoleLogger.showError("FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !");
|
||||||
ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart");
|
ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart");
|
||||||
}
|
}
|
||||||
@ -512,12 +503,12 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Check the presence of CombatTag
|
// Check the presence of CombatTag
|
||||||
public void checkCombatTag() {
|
public void checkCombatTag() {
|
||||||
this.CombatTag = this.getServer().getPluginManager().isPluginEnabled("CombatTag");
|
this.CombatTag = server.getPluginManager().isPluginEnabled("CombatTag");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if Citizens is active
|
// Check if Citizens is active
|
||||||
public void checkCitizens() {
|
public void checkCitizens() {
|
||||||
this.isCitizensActive = this.getServer().getPluginManager().isPluginEnabled("Citizens");
|
this.isCitizensActive = server.getPluginManager().isPluginEnabled("Citizens");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a player/command sender have a permission
|
// Check if a player/command sender have a permission
|
||||||
@ -703,8 +694,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Need to review the code below!
|
|
||||||
|
|
||||||
public String getCountryCode(String ip) {
|
public String getCountryCode(String ip) {
|
||||||
if (lookupService != null) {
|
if (lookupService != null) {
|
||||||
return lookupService.getCountry(ip).getCode();
|
return lookupService.getCountry(ip).getCode();
|
||||||
@ -751,12 +740,12 @@ public class AuthMe extends JavaPlugin {
|
|||||||
message = message.replace("&", "\u00a7");
|
message = message.replace("&", "\u00a7");
|
||||||
message = message.replace("{PLAYER}", player.getName());
|
message = message.replace("{PLAYER}", player.getName());
|
||||||
message = message.replace("{ONLINE}", "" + playersOnline);
|
message = message.replace("{ONLINE}", "" + playersOnline);
|
||||||
message = message.replace("{MAXPLAYERS}", "" + this.getServer().getMaxPlayers());
|
message = message.replace("{MAXPLAYERS}", "" + server.getMaxPlayers());
|
||||||
message = message.replace("{IP}", getIP(player));
|
message = message.replace("{IP}", getIP(player));
|
||||||
message = message.replace("{LOGINS}", "" + PlayerCache.getInstance().getLogged());
|
message = message.replace("{LOGINS}", "" + PlayerCache.getInstance().getLogged());
|
||||||
message = message.replace("{WORLD}", player.getWorld().getName());
|
message = message.replace("{WORLD}", player.getWorld().getName());
|
||||||
message = message.replace("{SERVER}", this.getServer().getServerName());
|
message = message.replace("{SERVER}", server.getServerName());
|
||||||
message = message.replace("{VERSION}", this.getServer().getBukkitVersion());
|
message = message.replace("{VERSION}", server.getBukkitVersion());
|
||||||
message = message.replace("{COUNTRY}", this.getCountryName(getIP(player)));
|
message = message.replace("{COUNTRY}", this.getCountryName(getIP(player)));
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@ -7,13 +13,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
import net.milkbowl.vault.permission.Permission;
|
|
||||||
|
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
|
|
||||||
public AuthMe plugin;
|
public AuthMe plugin;
|
||||||
@ -150,7 +149,7 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void purgePermissions(List<String> cleared,
|
public synchronized void purgePermissions(List<String> cleared,
|
||||||
Permission permission) {
|
Permission permission) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String name : cleared) {
|
for (String name : cleared) {
|
||||||
try {
|
try {
|
||||||
@ -170,24 +169,19 @@ public class DataManager {
|
|||||||
return true;
|
return true;
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
Future<Boolean> result = executor.submit(new Callable<Boolean>() {
|
||||||
|
@Override
|
||||||
public synchronized Boolean call() throws Exception {
|
public synchronized Boolean call() throws Exception {
|
||||||
Boolean result = null;
|
for (OfflinePlayer op : Utils.getOnlinePlayers())
|
||||||
try {
|
if (op.getName().equalsIgnoreCase(name)) {
|
||||||
for (OfflinePlayer op : Utils.getOnlinePlayers())
|
return true;
|
||||||
if (op.getName().equalsIgnoreCase(name)) {
|
}
|
||||||
result = true;
|
return false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
return result.get().booleanValue();
|
return result.get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return (false);
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import com.zaxxer.hikari.pool.PoolInitializationException;
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.Utils;
|
||||||
@ -28,7 +27,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -110,48 +108,23 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||||
plugin.getSettings().reload();
|
|
||||||
m.reloadMessages();
|
|
||||||
plugin.database.close();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
plugin.getSettings().reload();
|
||||||
|
m.reloadMessages();
|
||||||
|
plugin.database.close();
|
||||||
plugin.setupDatabase();
|
plugin.setupDatabase();
|
||||||
} catch (ClassNotFoundException nfe) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!");
|
ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!");
|
||||||
if (Settings.isStopEnabled) {
|
plugin.stopOrUnload();
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
} else {
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} catch (SQLException sqle) {
|
|
||||||
ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!");
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
} else {
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} catch (PoolInitializationException pie) {
|
|
||||||
ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!");
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
} else {
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.send(sender, "reload");
|
m.send(sender, "reload");
|
||||||
} else if (args[0].equalsIgnoreCase("lastlogin")) {
|
} else if (args[0].equalsIgnoreCase("lastlogin")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
sender.sendMessage("Usage: /authme lastlogin <playername>");
|
sender.sendMessage("Usage: /authme lastlogin <playername>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
try {
|
try {
|
||||||
auth = plugin.database.getAuth(args[1].toLowerCase());
|
auth = plugin.database.getAuth(args[1].toLowerCase());
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
@ -177,31 +150,30 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!args[1].contains(".")) {
|
if (!args[1].contains(".")) {
|
||||||
final CommandSender fSender = sender;
|
|
||||||
final String[] arguments = args;
|
final String[] arguments = args;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
String message = "[AuthMe] ";
|
String message = "[AuthMe] ";
|
||||||
try {
|
try {
|
||||||
auth = plugin.database.getAuth(arguments[1].toLowerCase());
|
auth = plugin.database.getAuth(arguments[1].toLowerCase());
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
m.send(fSender, "unknown_user");
|
m.send(sender, "unknown_user");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(fSender, "unknown_user");
|
m.send(sender, "unknown_user");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
List<String> accountList = plugin.database.getAllAuthsByName(auth);
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
m.send(fSender, "user_unknown");
|
m.send(sender, "user_unknown");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (accountList.size() == 1) {
|
if (accountList.size() == 1) {
|
||||||
fSender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -214,13 +186,12 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
message = message + ".";
|
message = message + ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fSender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
fSender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final CommandSender fSender = sender;
|
|
||||||
final String[] arguments = args;
|
final String[] arguments = args;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@ -228,16 +199,16 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
public void run() {
|
public void run() {
|
||||||
String message = "[AuthMe] ";
|
String message = "[AuthMe] ";
|
||||||
if (arguments[1] == null) {
|
if (arguments[1] == null) {
|
||||||
fSender.sendMessage("[AuthMe] Please put a valid IP");
|
sender.sendMessage("[AuthMe] Please put a valid IP");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
List<String> accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
fSender.sendMessage("[AuthMe] This IP does not exist in the database");
|
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (accountList.size() == 1) {
|
if (accountList.size() == 1) {
|
||||||
fSender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " is a single account player");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -250,8 +221,8 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
message = message + ".";
|
message = message + ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fSender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
sender.sendMessage("[AuthMe] " + arguments[1] + " has " + String.valueOf(accountList.size()) + " accounts");
|
||||||
fSender.sendMessage(message);
|
sender.sendMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@ -374,7 +345,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("purgebannedplayers")) {
|
} else if (args[0].equalsIgnoreCase("purgebannedplayers")) {
|
||||||
List<String> bannedPlayers = new ArrayList<String>();
|
List<String> bannedPlayers = new ArrayList<>();
|
||||||
for (OfflinePlayer off : plugin.getServer().getBannedPlayers()) {
|
for (OfflinePlayer off : plugin.getServer().getBannedPlayers()) {
|
||||||
bannedPlayers.add(off.getName().toLowerCase());
|
bannedPlayers.add(off.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.Utils;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import fr.xephi.authme.Utils;
|
|
||||||
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 {
|
public class CacheDataSource implements DataSource {
|
||||||
|
|
||||||
private DataSource source;
|
private DataSource source;
|
||||||
public AuthMe plugin;
|
public AuthMe plugin;
|
||||||
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<String, PlayerAuth>();
|
private ConcurrentHashMap<String, PlayerAuth> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public CacheDataSource(AuthMe plugin, DataSource source) {
|
public CacheDataSource(AuthMe plugin, DataSource source) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -24,8 +23,9 @@ public class CacheDataSource implements DataSource {
|
|||||||
* load the server, but it will be much easier to check for an
|
* load the server, but it will be much easier to check for an
|
||||||
* isAuthAvailable !
|
* isAuthAvailable !
|
||||||
*/
|
*/
|
||||||
for (PlayerAuth auth : source.getAllAuths())
|
for (PlayerAuth auth : source.getAllAuths()) {
|
||||||
cache.put(auth.getNickname().toLowerCase(), auth);
|
cache.put(auth.getNickname().toLowerCase(), auth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -144,12 +144,8 @@ public class CacheDataSource implements DataSource {
|
|||||||
for (Player player : Utils.getOnlinePlayers()) {
|
for (Player player : Utils.getOnlinePlayers()) {
|
||||||
String user = player.getName().toLowerCase();
|
String user = player.getName().toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
if (PlayerCache.getInstance().isAuthenticated(user)) {
|
||||||
try {
|
PlayerAuth auth = source.getAuth(user);
|
||||||
PlayerAuth auth = source.getAuth(user);
|
cache.put(user, auth);
|
||||||
cache.put(user, auth);
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,33 +19,34 @@ public final class Settings extends YamlConfiguration {
|
|||||||
// This is not an option!
|
// This is not an option!
|
||||||
public static Boolean antiBotInAction = false;
|
public static Boolean antiBotInAction = false;
|
||||||
|
|
||||||
public static final File PLUGIN_FOLDER;
|
public static final File PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
|
||||||
public static final File CACHE_FOLDER;
|
public static final File CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
|
||||||
public static final File AUTH_FILE;
|
public static final File AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
|
||||||
public static final File SETTINGS_FILE;
|
public static final File SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
||||||
|
|
||||||
public static File messageFile;
|
public static File messageFile;
|
||||||
public static List<String> allowCommands = null;
|
public static List<String> allowCommands;
|
||||||
public static List<String> getJoinPermissions = null;
|
public static List<String> getJoinPermissions;
|
||||||
public static List<String> getUnrestrictedName = null;
|
public static List<String> getUnrestrictedName;
|
||||||
private static List<String> getRestrictedIp;
|
public static List<String> getRestrictedIp;
|
||||||
public static List<String> getMySQLOtherUsernameColumn = null;
|
public static List<String> getMySQLOtherUsernameColumn;
|
||||||
public static List<String> getForcedWorlds = null;
|
public static List<String> getForcedWorlds;
|
||||||
public static List<String> countries = null;
|
public static List<String> countries;
|
||||||
public static List<String> countriesBlacklist = null;
|
public static List<String> countriesBlacklist;
|
||||||
public static List<String> forceCommands = null;
|
public static List<String> forceCommands;
|
||||||
public static List<String> forceCommandsAsConsole = null;
|
public static List<String> forceCommandsAsConsole;
|
||||||
public static List<String> forceRegisterCommands = null;
|
public static List<String> forceRegisterCommands;
|
||||||
public static List<String> forceRegisterCommandsAsConsole = null;
|
public static List<String> forceRegisterCommandsAsConsole;
|
||||||
|
public static List<String> welcomeMsg;
|
||||||
|
public static List<String> unsafePasswords;
|
||||||
|
public static List<String> emailBlacklist;
|
||||||
|
public static List<String> emailWhitelist;
|
||||||
public static DataSourceType getDataSource;
|
public static DataSourceType getDataSource;
|
||||||
public static HashAlgorithm getPasswordHash;
|
public static HashAlgorithm getPasswordHash;
|
||||||
public static Boolean useLogging = false;
|
public static boolean useLogging = false;
|
||||||
public static int purgeDelay = 60;
|
public static int purgeDelay = 60;
|
||||||
public static List<String> welcomeMsg = null;
|
|
||||||
public static List<String> unsafePasswords;
|
|
||||||
public static List<String> emailBlacklist = null;
|
|
||||||
public static List<String> emailWhitelist = null;
|
|
||||||
|
|
||||||
public static Boolean isPermissionCheckEnabled, isRegistrationEnabled,
|
public static boolean isPermissionCheckEnabled, isRegistrationEnabled,
|
||||||
isForcedRegistrationEnabled, isTeleportToSpawnEnabled,
|
isForcedRegistrationEnabled, isTeleportToSpawnEnabled,
|
||||||
isSessionsEnabled, isChatAllowed, isAllowRestrictedIp,
|
isSessionsEnabled, isChatAllowed, isAllowRestrictedIp,
|
||||||
isMovementAllowed, isKickNonRegisteredEnabled,
|
isMovementAllowed, isKickNonRegisteredEnabled,
|
||||||
@ -91,35 +92,28 @@ public final class Settings extends YamlConfiguration {
|
|||||||
|
|
||||||
protected static YamlConfiguration configFile;
|
protected static YamlConfiguration configFile;
|
||||||
|
|
||||||
static {
|
|
||||||
PLUGIN_FOLDER = AuthMe.getInstance().getDataFolder();
|
|
||||||
CACHE_FOLDER = new File(PLUGIN_FOLDER, "cache");
|
|
||||||
AUTH_FILE = new File(PLUGIN_FOLDER, "auths.db");
|
|
||||||
SETTINGS_FILE = new File(PLUGIN_FOLDER, "config.yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Settings(AuthMe plugin) {
|
public Settings(AuthMe plugin) {
|
||||||
configFile = (YamlConfiguration) plugin.getConfig();
|
configFile = (YamlConfiguration) plugin.getConfig();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
boolean exist = exists();
|
}
|
||||||
|
|
||||||
|
public final void reload() throws Exception {
|
||||||
|
plugin.getLogger().info("Loading Configuration File...");
|
||||||
|
boolean exist = SETTINGS_FILE.exists();
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
plugin.saveDefaultConfig();
|
plugin.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
load();
|
load(SETTINGS_FILE);
|
||||||
loadConfigOptions(exist);
|
if (exist) {
|
||||||
|
mergeConfig();
|
||||||
|
}
|
||||||
|
loadVariables();
|
||||||
|
if (exist) {
|
||||||
|
saveDefaults();
|
||||||
|
}
|
||||||
messageFile = new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + messagesLanguage + ".yml");
|
messageFile = new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + messagesLanguage + ".yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfigOptions(boolean exist) {
|
|
||||||
plugin.getLogger().info("Loading Configuration File...");
|
|
||||||
if (exist)
|
|
||||||
mergeConfig();
|
|
||||||
|
|
||||||
loadVariables();
|
|
||||||
|
|
||||||
if (exist)
|
|
||||||
saveDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void loadVariables() {
|
public static void loadVariables() {
|
||||||
@ -513,27 +507,6 @@ public final class Settings extends YamlConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the configuration from disk
|
|
||||||
*
|
|
||||||
* @return True if loaded successfully
|
|
||||||
*/
|
|
||||||
public final boolean load() {
|
|
||||||
try {
|
|
||||||
load(SETTINGS_FILE);
|
|
||||||
return true;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void reload() {
|
|
||||||
if (!exists()) {
|
|
||||||
plugin.saveDefaultConfig();
|
|
||||||
}
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the configuration to disk
|
* Saves the configuration to disk
|
||||||
*
|
*
|
||||||
@ -548,15 +521,6 @@ public final class Settings extends YamlConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple function for if the Configuration file exists
|
|
||||||
*
|
|
||||||
* @return True if configuration exists on disk
|
|
||||||
*/
|
|
||||||
public final boolean exists() {
|
|
||||||
return SETTINGS_FILE.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves current configuration (plus defaults) to disk.
|
* Saves current configuration (plus defaults) to disk.
|
||||||
* <p>
|
* <p>
|
||||||
|
Loading…
Reference in New Issue
Block a user