Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 450-new-settings-rewrite
Conflicts: src/main/java/fr/xephi/authme/AuthMe.java src/main/java/fr/xephi/authme/settings/Settings.java src/main/java/fr/xephi/authme/settings/custom/NewSetting.java
This commit is contained in:
@@ -1,9 +1,35 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
|
||||
import fr.xephi.authme.api.API;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@@ -58,33 +84,6 @@ import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||
@@ -213,7 +212,7 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Load settings and custom configurations, if it fails, stop the server due to security reasons.
|
||||
newSettings = createNewSetting();
|
||||
if (loadSettings()) {
|
||||
if (!loadSettings()) {
|
||||
server.shutdown();
|
||||
setEnabled(false);
|
||||
return;
|
||||
@@ -225,9 +224,8 @@ public class AuthMe extends JavaPlugin {
|
||||
try {
|
||||
setupDatabase();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!");
|
||||
ConsoleLogger.logException("Fatal error occurred during database connection! "
|
||||
+ "Authme initialization aborted!", e);
|
||||
stopOrUnload();
|
||||
return;
|
||||
}
|
||||
@@ -242,9 +240,8 @@ public class AuthMe extends JavaPlugin {
|
||||
// Setup otherAccounts file
|
||||
this.otherAccounts = OtherAccounts.getInstance();
|
||||
|
||||
|
||||
// Set up Metrics
|
||||
setupMetrics();
|
||||
MetricsStarter.setupMetrics(plugin, newSettings);
|
||||
|
||||
// Set console filter
|
||||
setupConsoleFilter();
|
||||
@@ -429,12 +426,11 @@ public class AuthMe extends JavaPlugin {
|
||||
try {
|
||||
settings = new Settings(this);
|
||||
Settings.reload();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Can't load the configuration file... Something went wrong. "
|
||||
+ "To avoid security issues the server will shut down!");
|
||||
server.shutdown();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Can't load the configuration file... Something went wrong. "
|
||||
+ "To avoid security issues the server will shut down!", e);
|
||||
server.shutdown();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -463,46 +459,6 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Metrics.
|
||||
*/
|
||||
private void setupMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
Graph languageGraph = metrics.createGraph("Messages language");
|
||||
Graph backendGraph = metrics.createGraph("Database backend");
|
||||
|
||||
// Custom graphs
|
||||
if (newSettings.getMessagesFile().exists()) {
|
||||
String messagesLanguage = newSettings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
languageGraph.addPlotter(new Metrics.Plotter(messagesLanguage) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
DataSource.DataSourceType dataSource = newSettings.getProperty(DatabaseSettings.BACKEND);
|
||||
backendGraph.addPlotter(new Metrics.Plotter(dataSource.toString()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
metrics.start();
|
||||
ConsoleLogger.info("Metrics started successfully!");
|
||||
} catch (Exception e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway... (Encountered "
|
||||
+ StringUtils.formatException(e) + ")");
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Save player data
|
||||
@@ -516,40 +472,6 @@ public class AuthMe extends JavaPlugin {
|
||||
new PerformBackup(plugin, newSettings).doBackup(PerformBackup.BackupCause.STOP);
|
||||
}
|
||||
|
||||
List<BukkitTask> pendingTasks = getServer().getScheduler().getPendingTasks();
|
||||
for (Iterator<BukkitTask> iterator = pendingTasks.iterator(); iterator.hasNext();) {
|
||||
BukkitTask pendingTask = iterator.next();
|
||||
if (!pendingTask.getOwner().equals(this) || pendingTask.isSync()) {
|
||||
//remove all irrelevant tasks
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
getLogger().log(Level.INFO, "Waiting for {0} tasks to finish", pendingTasks.size());
|
||||
int progress = 0;
|
||||
try {
|
||||
for (BukkitTask pendingTask : pendingTasks) {
|
||||
int maxTries = 5;
|
||||
int taskId = pendingTask.getTaskId();
|
||||
while (getServer().getScheduler().isCurrentlyRunning(taskId)) {
|
||||
if (maxTries <= 0) {
|
||||
getLogger().log(Level.INFO, "Async task {0} times out after to many tries", taskId);
|
||||
break;
|
||||
}
|
||||
|
||||
//one second
|
||||
Thread.sleep(1000);
|
||||
maxTries--;
|
||||
}
|
||||
|
||||
progress++;
|
||||
getLogger().log(Level.INFO, "Progress: {0} / {1}", new Object[]{progress, pendingTasks.size()});
|
||||
}
|
||||
} catch (InterruptedException interruptedException) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Close the database
|
||||
if (database != null) {
|
||||
database.close();
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Wrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -32,10 +33,9 @@ public final class ConsoleLogger {
|
||||
*/
|
||||
public static void info(String message) {
|
||||
wrapper.getLogger().info(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
if (Settings.useLogging) {
|
||||
writeLog(message);
|
||||
}
|
||||
writeLog("" + message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,10 +45,9 @@ public final class ConsoleLogger {
|
||||
*/
|
||||
public static void showError(String message) {
|
||||
wrapper.getLogger().warning(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
if (Settings.useLogging) {
|
||||
writeLog("ERROR: " + message);
|
||||
}
|
||||
writeLog("ERROR: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,12 +71,22 @@ public final class ConsoleLogger {
|
||||
/**
|
||||
* Write a StackTrace into the log.
|
||||
*
|
||||
* @param ex Exception
|
||||
* @param th The Throwable whose stack trace should be logged
|
||||
*/
|
||||
public static void writeStackTrace(Exception ex) {
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
public static void writeStackTrace(Throwable th) {
|
||||
if (Settings.useLogging) {
|
||||
writeLog(Throwables.getStackTraceAsString(th));
|
||||
}
|
||||
writeLog(Throwables.getStackTraceAsString(ex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a Throwable with the provided message and saves the stack trace to the log file.
|
||||
*
|
||||
* @param message The message to accompany the exception
|
||||
* @param th The Throwable to log
|
||||
*/
|
||||
public static void logException(String message, Throwable th) {
|
||||
showError(message + " " + StringUtils.formatException(th));
|
||||
writeStackTrace(th);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.mcstats.Metrics;
|
||||
import org.mcstats.Metrics.Graph;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MetricsStarter {
|
||||
|
||||
private MetricsStarter() {
|
||||
}
|
||||
|
||||
public static void setupMetrics(AuthMe plugin, NewSetting settings) {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(plugin);
|
||||
|
||||
final Graph languageGraph = metrics.createGraph("Messages Language");
|
||||
final String messagesLanguage = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
languageGraph.addPlotter(new Metrics.Plotter(messagesLanguage) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
final Graph databaseBackend = metrics.createGraph("Database Backend");
|
||||
final String dataSource = settings.getProperty(DatabaseSettings.BACKEND).toString();
|
||||
databaseBackend.addPlotter(new Metrics.Plotter(dataSource) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Submit metrics
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
// Failed to submit the metrics data
|
||||
ConsoleLogger.logException("Can't start Metrics! The plugin will work anyway...", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,7 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("Error occurred during reload of AuthMe: aborting");
|
||||
ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!");
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.logException("Aborting! Encountered exception during reload of AuthMe:", e);
|
||||
plugin.stopOrUnload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ public class RoyalAuthConverter implements Converter {
|
||||
PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName());
|
||||
data.saveAuth(auth);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Error while trying to import " + o.getName() + " RoyalAuth datas");
|
||||
ConsoleLogger.logException("Error while trying to import " + o.getName() + " RoyalAuth data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -27,7 +28,7 @@ class vAuthFileReader {
|
||||
}
|
||||
|
||||
public void convert() {
|
||||
final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml");
|
||||
final File file = new File(plugin.getDataFolder().getParent() + File.separator + "vAuth" + File.separator + "passwords.yml");
|
||||
Scanner scanner;
|
||||
try {
|
||||
scanner = new Scanner(file);
|
||||
@@ -52,8 +53,8 @@ class vAuthFileReader {
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
scanner.close();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.logException("Error while trying to import some vAuth data", e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,12 +64,10 @@ class vAuthFileReader {
|
||||
}
|
||||
|
||||
private String getName(UUID uuid) {
|
||||
try {
|
||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||
if (op.getUniqueId().compareTo(uuid) == 0)
|
||||
return op.getName();
|
||||
for (OfflinePlayer op : Bukkit.getOfflinePlayers()) {
|
||||
if (op.getUniqueId().compareTo(uuid) == 0) {
|
||||
return op.getName();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,13 @@ import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.google.common.cache.RemovalListeners;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -23,7 +19,6 @@ import java.util.concurrent.TimeUnit;
|
||||
public class CacheDataSource implements DataSource {
|
||||
|
||||
private final DataSource source;
|
||||
private final ExecutorService exec;
|
||||
private final LoadingCache<String, Optional<PlayerAuth>> cachedAuths;
|
||||
|
||||
/**
|
||||
@@ -33,10 +28,9 @@ public class CacheDataSource implements DataSource {
|
||||
*/
|
||||
public CacheDataSource(DataSource src) {
|
||||
this.source = src;
|
||||
this.exec = Executors.newCachedThreadPool();
|
||||
cachedAuths = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(5, TimeUnit.MINUTES)
|
||||
.removalListener(RemovalListeners.asynchronous(new RemovalListener<String, Optional<PlayerAuth>>() {
|
||||
this.cachedAuths = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(8, TimeUnit.MINUTES)
|
||||
.removalListener(new RemovalListener<String, Optional<PlayerAuth>>() {
|
||||
@Override
|
||||
public void onRemoval(RemovalNotification<String, Optional<PlayerAuth>> removalNotification) {
|
||||
String name = removalNotification.getKey();
|
||||
@@ -44,7 +38,7 @@ public class CacheDataSource implements DataSource {
|
||||
cachedAuths.getUnchecked(name);
|
||||
}
|
||||
}
|
||||
}, exec))
|
||||
})
|
||||
.build(
|
||||
new CacheLoader<String, Optional<PlayerAuth>>() {
|
||||
public Optional<PlayerAuth> load(String key) {
|
||||
@@ -168,24 +162,13 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
try {
|
||||
exec.shutdown();
|
||||
exec.awaitTermination(8, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
source.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() { // unused method
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.reload();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
});
|
||||
source.reload();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -214,13 +197,8 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public synchronized void purgeBanned(final List<String> banned) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.purgeBanned(banned);
|
||||
cachedAuths.invalidateAll(banned);
|
||||
}
|
||||
});
|
||||
source.purgeBanned(banned);
|
||||
cachedAuths.invalidateAll(banned);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,33 +213,18 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public void setLogged(final String user) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
});
|
||||
source.setLogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlogged(final String user) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
});
|
||||
source.setUnlogged(user.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void purgeLogged() {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.purgeLogged();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
});
|
||||
source.purgeLogged();
|
||||
cachedAuths.invalidateAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,14 +233,9 @@ public class CacheDataSource implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateName(final String oldOne, final String newOne) {
|
||||
exec.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
source.updateName(oldOne, newOne);
|
||||
cachedAuths.invalidate(oldOne);
|
||||
}
|
||||
});
|
||||
public void updateName(final String oldOne, final String newOne) { // unused method
|
||||
source.updateName(oldOne, newOne);
|
||||
cachedAuths.invalidate(oldOne);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -257,8 +257,7 @@ public class MySQL implements DataSource {
|
||||
ResultSet rs = pst.executeQuery();
|
||||
return rs.next();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -276,8 +275,7 @@ public class MySQL implements DataSource {
|
||||
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -322,8 +320,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
return null;
|
||||
}
|
||||
return pAuth;
|
||||
@@ -525,8 +522,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -589,8 +585,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -623,8 +618,7 @@ public class MySQL implements DataSource {
|
||||
pst.setLong(1, until);
|
||||
result = pst.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -647,8 +641,7 @@ public class MySQL implements DataSource {
|
||||
st.executeUpdate();
|
||||
st.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -680,8 +673,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -702,8 +694,7 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -722,8 +713,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return countIp;
|
||||
}
|
||||
@@ -739,8 +729,7 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -750,9 +739,8 @@ public class MySQL implements DataSource {
|
||||
try {
|
||||
reloadArguments();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL configuration!");
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
ConsoleLogger.logException("Can't reconnect to MySQL database... " +
|
||||
"Please check your MySQL configuration! Encountered", ex);
|
||||
AuthMe.getInstance().stopOrUnload();
|
||||
}
|
||||
}
|
||||
@@ -778,8 +766,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -798,8 +785,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -818,8 +804,7 @@ public class MySQL implements DataSource {
|
||||
rs.close();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return countEmail;
|
||||
}
|
||||
@@ -834,8 +819,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,8 +838,7 @@ public class MySQL implements DataSource {
|
||||
ResultSet rs = pst.executeQuery();
|
||||
isLogged = rs.next() && (rs.getInt(columnLogged) == 1);
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
return isLogged;
|
||||
}
|
||||
@@ -870,8 +853,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,8 +867,7 @@ public class MySQL implements DataSource {
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,9 +880,8 @@ public class MySQL implements DataSource {
|
||||
pst.setInt(2, 1);
|
||||
pst.executeUpdate();
|
||||
pst.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -916,9 +896,8 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -931,9 +910,8 @@ public class MySQL implements DataSource {
|
||||
pst.setString(1, newOne);
|
||||
pst.setString(2, oldOne);
|
||||
pst.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,9 +955,8 @@ public class MySQL implements DataSource {
|
||||
pst.close();
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return auths;
|
||||
}
|
||||
@@ -1021,11 +998,14 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
auths.add(pAuth);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
}
|
||||
return auths;
|
||||
}
|
||||
|
||||
private static void logSqlException(SQLException e) {
|
||||
ConsoleLogger.logException("Error during SQL operation:", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -170,8 +170,7 @@ public class SQLite implements DataSource {
|
||||
!columnSalt.isEmpty() ? rs.getString(columnSalt) : null);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ConsoleLogger.showError(ex.getMessage());
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
ConsoleLogger.logException("Error getting password:", ex);
|
||||
} finally {
|
||||
close(rs);
|
||||
close(pst);
|
||||
|
||||
@@ -108,6 +108,9 @@ public class AuthMePlayerListener implements Listener {
|
||||
if (Settings.useEssentialsMotd && cmd.equals("/motd")) {
|
||||
return;
|
||||
}
|
||||
if(!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) {
|
||||
return;
|
||||
}
|
||||
if (Settings.allowCommands.contains(cmd)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,8 +135,7 @@ public class ModuleManager {
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
ConsoleLogger.writeStackTrace(ex);
|
||||
ConsoleLogger.showError("Cannot load " + pathToJar.getName() + " jar file !");
|
||||
ConsoleLogger.logException("Cannot load " + pathToJar.getName() + " jar file!", ex);
|
||||
} finally {
|
||||
try {
|
||||
if (jarFile != null) {
|
||||
|
||||
@@ -49,6 +49,13 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
|
||||
protected void restoreSpeedEffect() {
|
||||
if (Settings.isRemoveSpeedEnabled) {
|
||||
player.setWalkSpeed(0.0F);
|
||||
player.setFlySpeed(0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method run.
|
||||
*
|
||||
@@ -77,6 +84,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
if (Settings.applyBlindEffect)
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
|
||||
player.setOp(false);
|
||||
restoreSpeedEffect();
|
||||
// Player is now logout... Time to fire event !
|
||||
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
|
||||
if (Settings.bungee)
|
||||
|
||||
@@ -85,8 +85,7 @@ public class AsyncRegister {
|
||||
passwordRegister();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.logException("Error during async register process", e);
|
||||
m.send(player, MessageKey.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,7 @@ public abstract class CustomConfiguration extends YamlConfiguration {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.showError("Failed to load config from JAR");
|
||||
ConsoleLogger.logException("Failed to load config from JAR", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -181,8 +181,7 @@ public class NewSetting {
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.showError("Could not save config file - " + StringUtils.formatException(e));
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.logException("Could not save config file:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class Settings {
|
||||
enableProtection, enableAntiBot, recallEmail, useWelcomeMessage,
|
||||
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
|
||||
checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect,
|
||||
kickPlayersBeforeStopping,
|
||||
kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional,
|
||||
customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase;
|
||||
public static String getNickRegex, getUnloggedinGroup, getMySQLHost,
|
||||
getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase,
|
||||
@@ -189,6 +189,7 @@ public final class Settings {
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
|
||||
allowAllCommandsIfRegIsOptional = configFile.getBoolean("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false);
|
||||
allowCommands = new ArrayList<>();
|
||||
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
||||
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
||||
|
||||
@@ -18,13 +18,19 @@ public class RestrictionSettings implements SettingsClass {
|
||||
public static final Property<Boolean> ALLOW_CHAT =
|
||||
newProperty("settings.restrictions.allowChat", false);
|
||||
|
||||
@Comment({
|
||||
"Allow unlogged users to use all the commands if registration is not forced!",
|
||||
"WARNING: use this only if you need it!)"})
|
||||
public static final Property<Boolean> ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL =
|
||||
newProperty("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false);
|
||||
|
||||
@Comment("Allowed commands for unauthenticated players")
|
||||
public static final Property<List<String>> ALLOW_COMMANDS =
|
||||
newProperty(PropertyType.STRING_LIST, "settings.restrictions.allowCommands",
|
||||
"login", "register", "l", "reg", "email", "captcha");
|
||||
|
||||
@Comment("Max number of allowed registrations per IP")
|
||||
// TODO ljacqu 20160109: If 0 == unlimited, add this fact ot the comment
|
||||
// TODO ljacqu 20160109: If 0 == unlimited, add this fact to the comment
|
||||
public static final Property<Integer> MAX_REGISTRATION_PER_IP =
|
||||
newProperty("settings.restrictions.maxRegPerIp", 1);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GeoLiteAPI {
|
||||
plugin.getLogger().info(LICENSE);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
// TODO ljacqu 20151123: Log the exception instead of just swallowing it
|
||||
ConsoleLogger.logException("Could not find/download GeoLiteAPI", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class GeoLiteAPI {
|
||||
output.close();
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
ConsoleLogger.logException("Could not download GeoLiteAPI", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user