Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0cc98a839c
69
pom.xml
69
pom.xml
@ -13,6 +13,11 @@
|
|||||||
<url>http://dev.bukkit.org/bukkit-plugins/authme-reloaded/</url>
|
<url>http://dev.bukkit.org/bukkit-plugins/authme-reloaded/</url>
|
||||||
<!-- See also: https://www.spigotmc.org/resources/authme-reloaded.6269/ -->
|
<!-- See also: https://www.spigotmc.org/resources/authme-reloaded.6269/ -->
|
||||||
|
|
||||||
|
<organization>
|
||||||
|
<name>AuthMe-Team</name>
|
||||||
|
<url>https://github.com/AuthMe-Team</url>
|
||||||
|
</organization>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:https://github.com/Xephi/AuthMeReloaded.git</connection>
|
<connection>scm:git:https://github.com/Xephi/AuthMeReloaded.git</connection>
|
||||||
<developerConnection>scm:git:git@github.com:Xephi/AuthMeReloaded.git</developerConnection>
|
<developerConnection>scm:git:git@github.com:Xephi/AuthMeReloaded.git</developerConnection>
|
||||||
@ -56,6 +61,14 @@
|
|||||||
<include>*.yml</include>
|
<include>*.yml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<targetPath>./messages/</targetPath>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<directory>${basedir}/src/main/resources/messages/</directory>
|
||||||
|
<includes>
|
||||||
|
<include>*.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -74,13 +87,12 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<artifactSet>
|
<artifactSet>
|
||||||
<includes>
|
<includes>
|
||||||
<include>com.maxmind.geoip:*</include>
|
<include>com.zaxxer:HikariCP</include>
|
||||||
<include>javax.mail:*</include>
|
<include>org.slf4j:slf4j-simple</include>
|
||||||
<include>com.sun.mail:*</include>
|
<include>com.maxmind.geoip:geoip-api</include>
|
||||||
<include>com.comphenix.attribute:*</include>
|
<include>com.sun.mail:javax.mail</include>
|
||||||
<include>org.mcstats.*:*</include>
|
<include>com.comphenix.attribute:AttributeStorage</include>
|
||||||
<include>com.zaxxer:*</include>
|
<include>org.mcstats.bukkit:metrics</include>
|
||||||
<include>org.slf4j:*</include>
|
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
@ -164,42 +176,27 @@
|
|||||||
<url>http://repo.mcstats.org/content/repositories/snapshots/</url>
|
<url>http://repo.mcstats.org/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<!-- sgdc3 HikariCP Log4J Repo -->
|
||||||
|
<repository>
|
||||||
|
<id>hikaricp-log4j-releases</id>
|
||||||
|
<url>http://nexus-sgdc3.rhcloud.com/nexus/content/repositories/hikaricp-log4j-releases/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Maven Dependencies -->
|
<!-- Maven Dependencies -->
|
||||||
|
|
||||||
<!-- MySql Connection Pool -->
|
<!-- Database Connection Pool -->
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>5.1.36</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>1.7.12</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
<artifactId>HikariCP</artifactId>
|
<artifactId>HikariCP</artifactId>
|
||||||
<version>2.4.1</version>
|
<version>2.4.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SQLite Library -->
|
<!-- SQLite Connector -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.xerial</groupId>
|
<groupId>org.xerial</groupId>
|
||||||
<artifactId>sqlite-jdbc</artifactId>
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
@ -207,7 +204,13 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Java Email API -->
|
<!-- Java Email API and Implementation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.mail</groupId>
|
||||||
|
<artifactId>javax.mail-api</artifactId>
|
||||||
|
<version>1.5.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>com.sun.mail</groupId>
|
||||||
<artifactId>javax.mail</artifactId>
|
<artifactId>javax.mail</artifactId>
|
||||||
@ -557,9 +560,7 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>simplechestlock</artifactId>
|
<artifactId>simplechestlock</artifactId>
|
||||||
<groupId>
|
<groupId>com.webkonsept.bukkit.simplechestlock</groupId>
|
||||||
com.webkonsept.bukkit.simplechestlock
|
|
||||||
</groupId>
|
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>commandbook</artifactId>
|
<artifactId>commandbook</artifactId>
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import java.io.OutputStream;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -34,6 +35,7 @@ import org.mcstats.Metrics;
|
|||||||
import com.earth2me.essentials.Essentials;
|
import com.earth2me.essentials.Essentials;
|
||||||
import com.maxmind.geoip.LookupService;
|
import com.maxmind.geoip.LookupService;
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
|
import com.zaxxer.hikari.pool.PoolInitializationException;
|
||||||
|
|
||||||
import fr.xephi.authme.api.API;
|
import fr.xephi.authme.api.API;
|
||||||
import fr.xephi.authme.api.NewAPI;
|
import fr.xephi.authme.api.NewAPI;
|
||||||
@ -214,7 +216,18 @@ public class AuthMe extends JavaPlugin {
|
|||||||
else ConsoleLogger.showError("Error while performing the backup!");
|
else ConsoleLogger.showError("Error while performing the backup!");
|
||||||
}
|
}
|
||||||
|
|
||||||
setupDatabase();
|
try {
|
||||||
|
setupDatabase();
|
||||||
|
} catch (ClassNotFoundException nfe) {
|
||||||
|
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!");
|
||||||
|
return;
|
||||||
|
} catch (SQLException sqle) {
|
||||||
|
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!");
|
||||||
|
return;
|
||||||
|
} catch (PoolInitializationException pie) {
|
||||||
|
ConsoleLogger.showError("Fatal error occurred! Authme initialization ABORTED!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dataManager = new DataManager(this);
|
dataManager = new DataManager(this);
|
||||||
|
|
||||||
@ -800,7 +813,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return realIP;
|
return realIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setupDatabase() {
|
public void setupDatabase() throws ClassNotFoundException, PoolInitializationException, SQLException {
|
||||||
/*
|
/*
|
||||||
* Backend MYSQL - FILE - SQLITE
|
* Backend MYSQL - FILE - SQLITE
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -134,10 +134,13 @@ public class DataManager {
|
|||||||
playerFile.delete();
|
playerFile.delete();
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + Bukkit.getOfflinePlayer(name).getUniqueId() + ".yml");
|
try {
|
||||||
if (playerFile.exists()) {
|
playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + Bukkit.getOfflinePlayer(name).getUniqueId() + ".yml");
|
||||||
playerFile.delete();
|
if (playerFile.exists()) {
|
||||||
i++;
|
playerFile.delete();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
} catch (Exception e) { // Don't do nothing if the method getUniqueId() isn't avariable ( MC version < 1.7.5 )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -505,8 +505,12 @@ public class FileCache {
|
|||||||
else armours[i] = item;
|
else armours[i] = item;
|
||||||
}
|
}
|
||||||
} catch (final RuntimeException e) {
|
} catch (final RuntimeException e) {
|
||||||
|
//verbose
|
||||||
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
//verbose
|
||||||
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
||||||
} finally {
|
} finally {
|
||||||
if (reader != null)
|
if (reader != null)
|
||||||
@ -515,9 +519,13 @@ public class FileCache {
|
|||||||
return new DataFileCache(inv, armours, group, op, flying);
|
return new DataFileCache(inv, armours, group, op, flying);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
// Verbose
|
||||||
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// Verbose
|
||||||
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
ConsoleLogger.showError("Error while reading file for " + player.getName() + ", some wipe inventory incoming...");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
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;
|
||||||
@ -22,6 +23,8 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
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;
|
||||||
@ -143,7 +146,38 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
Settings.reloadConfigOptions(newConfig);
|
Settings.reloadConfigOptions(newConfig);
|
||||||
m.reloadMessages();
|
m.reloadMessages();
|
||||||
plugin.database.close();
|
plugin.database.close();
|
||||||
plugin.setupDatabase();
|
|
||||||
|
try {
|
||||||
|
plugin.setupDatabase();
|
||||||
|
} catch (ClassNotFoundException nfe) {
|
||||||
|
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 (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;
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
@ -45,7 +44,7 @@ public class MySQL implements DataSource {
|
|||||||
private HikariDataSource ds;
|
private HikariDataSource ds;
|
||||||
private String columnRealName;
|
private String columnRealName;
|
||||||
|
|
||||||
public MySQL() {
|
public MySQL() throws ClassNotFoundException, SQLException, PoolInitializationException {
|
||||||
this.host = Settings.getMySQLHost;
|
this.host = Settings.getMySQLHost;
|
||||||
this.port = Settings.getMySQLPort;
|
this.port = Settings.getMySQLPort;
|
||||||
this.username = Settings.getMySQLUsername;
|
this.username = Settings.getMySQLUsername;
|
||||||
@ -67,73 +66,112 @@ public class MySQL implements DataSource {
|
|||||||
this.columnID = Settings.getMySQLColumnId;
|
this.columnID = Settings.getMySQLColumnId;
|
||||||
this.columnLogged = Settings.getMySQLColumnLogged;
|
this.columnLogged = Settings.getMySQLColumnLogged;
|
||||||
this.columnRealName = Settings.getMySQLColumnRealName;
|
this.columnRealName = Settings.getMySQLColumnRealName;
|
||||||
|
|
||||||
|
// Set the connection arguments (and check if connection is ok)
|
||||||
try {
|
try {
|
||||||
this.connect();
|
this.setConnectionArguments();
|
||||||
this.setup();
|
} catch (ClassNotFoundException ne) {
|
||||||
} catch (ClassNotFoundException e) {
|
ConsoleLogger.showError(ne.getMessage());
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
if (Settings.isStopEnabled) {
|
if (Settings.isStopEnabled) {
|
||||||
ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new ClassNotFoundException(ne.getMessage());
|
||||||
|
} catch (IllegalArgumentException ae) { // This means that there are problems with the hikaricp pool arguments!
|
||||||
|
ConsoleLogger.showError(ae.getMessage());
|
||||||
|
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(ae);
|
||||||
|
} catch (PoolInitializationException ie) { // Can't initialize the connection pool!
|
||||||
|
ConsoleLogger.showError(ie.getMessage());
|
||||||
|
ConsoleLogger.showError("Can't connect to the MySql database! Please check your configuration!");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new PoolInitializationException(ie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the database
|
||||||
|
try {
|
||||||
|
this.setupConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN...");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
if (Settings.isStopEnabled) {
|
if (Settings.isStopEnabled) {
|
||||||
ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
} else {
|
||||||
} catch (TimeoutException e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
|
||||||
} catch (PoolInitializationException e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
}
|
||||||
if (!Settings.isStopEnabled)
|
throw new SQLException(e);
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void connect()
|
private synchronized void setConnectionArguments()
|
||||||
throws ClassNotFoundException, SQLException, TimeoutException,
|
throws ClassNotFoundException, IllegalArgumentException {
|
||||||
NumberFormatException, PoolInitializationException {
|
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
config.setDriverClassName("com.mysql.jdbc.Driver");
|
config.setPoolName("AuthMeMYSQLPool");
|
||||||
|
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||||
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||||
config.setUsername(this.username);
|
config.setUsername(this.username);
|
||||||
config.setPassword(this.password);
|
config.setPassword(this.password);
|
||||||
config.setPoolName("AuthMeMYSQLPool");
|
|
||||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
config.addDataSourceProperty("autoReconnect", true);
|
config.addDataSourceProperty("autoReconnect", false);
|
||||||
config.setMaxLifetime(30000);
|
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavariable
|
||||||
config.setInitializationFailFast(false);
|
config.setMaxLifetime(180000); // 3 Min
|
||||||
|
config.setIdleTimeout(60000); // 1 Min
|
||||||
|
config.setMaximumPoolSize(50); // 50 (including idle connections)
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
ConsoleLogger.info("Connection pool ready");
|
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setup() throws SQLException {
|
private synchronized void reloadArguments()
|
||||||
|
throws ClassNotFoundException, IllegalArgumentException {
|
||||||
|
if (ds != null){
|
||||||
|
ds.close();
|
||||||
|
}
|
||||||
|
setConnectionArguments();
|
||||||
|
ConsoleLogger.info("Hikari ConnectionPool arguments reloaded!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized Connection getConnection() {
|
||||||
|
Connection con = null;
|
||||||
|
while(con == null){
|
||||||
|
try {
|
||||||
|
con = ds.getConnection();
|
||||||
|
} catch (SQLException ce) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setupConnection() throws SQLException {
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
Statement st = null;
|
Statement st = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
st = con.createStatement();
|
st = con.createStatement();
|
||||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + columnLastLogin + " BIGINT NOT NULL DEFAULT '" + System.currentTimeMillis() + "'," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + columnLogged + " SMALLINT NOT NULL DEFAULT '0'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||||
@ -185,6 +223,7 @@ public class MySQL implements DataSource {
|
|||||||
close(st);
|
close(st);
|
||||||
close(con);
|
close(con);
|
||||||
}
|
}
|
||||||
|
ConsoleLogger.info("MySQL Setup finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -193,7 +232,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -217,7 +256,7 @@ public class MySQL implements DataSource {
|
|||||||
PlayerAuth pAuth = null;
|
PlayerAuth pAuth = null;
|
||||||
int id = -1;
|
int id = -1;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -264,7 +303,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) {
|
if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) {
|
||||||
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
|
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
|
||||||
pst.setString(1, auth.getNickname());
|
pst.setString(1, auth.getNickname());
|
||||||
@ -473,7 +512,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getHash());
|
pst.setString(1, auth.getHash());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
@ -518,7 +557,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getIp());
|
pst.setString(1, auth.getIp());
|
||||||
pst.setLong(2, auth.getLastLogin());
|
pst.setLong(2, auth.getLastLogin());
|
||||||
@ -540,7 +579,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
@ -560,7 +599,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> list = new ArrayList<String>();
|
List<String> list = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -587,7 +626,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
|
||||||
int id;
|
int id;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -623,7 +662,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + " =?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setDouble(1, auth.getQuitLocX());
|
pst.setDouble(1, auth.getQuitLocX());
|
||||||
pst.setDouble(2, auth.getQuitLocY());
|
pst.setDouble(2, auth.getQuitLocY());
|
||||||
@ -648,7 +687,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
int countIp = 0;
|
int countIp = 0;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -671,7 +710,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + " =? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getEmail());
|
pst.setString(1, auth.getEmail());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
@ -694,7 +733,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + " =? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, auth.getSalt());
|
pst.setString(1, auth.getSalt());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
@ -709,6 +748,21 @@ public class MySQL implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
try {
|
||||||
|
reloadArguments();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN...");
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
}
|
||||||
|
if (!Settings.isStopEnabled)
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
try {
|
try {
|
||||||
@ -718,21 +772,6 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
try {
|
|
||||||
reconnect(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void close(Statement st) {
|
private void close(Statement st) {
|
||||||
if (st != null) {
|
if (st != null) {
|
||||||
try {
|
try {
|
||||||
@ -770,7 +809,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countIp = new ArrayList<String>();
|
List<String> countIp = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, auth.getIp());
|
pst.setString(1, auth.getIp());
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -795,7 +834,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countIp = new ArrayList<String>();
|
List<String> countIp = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -820,7 +859,7 @@ public class MySQL implements DataSource {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countEmail = new ArrayList<String>();
|
List<String> countEmail = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
pst.setString(1, email);
|
pst.setString(1, email);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -844,7 +883,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
for (String name : banned) {
|
for (String name : banned) {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, name);
|
pst.setString(1, name);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
@ -857,75 +896,6 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized Connection makeSureConnectionIsReady() {
|
|
||||||
Connection con = null;
|
|
||||||
try {
|
|
||||||
con = ds.getConnection();
|
|
||||||
} catch (Exception te) {
|
|
||||||
try {
|
|
||||||
con = null;
|
|
||||||
reconnect(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
} catch (AssertionError ae) {
|
|
||||||
// Make sure assertionerror is caused by the connectionpoolmanager,
|
|
||||||
// else re-throw it
|
|
||||||
if (!ae.getMessage().equalsIgnoreCase("AuthMeDatabaseError"))
|
|
||||||
throw new AssertionError(ae.getMessage());
|
|
||||||
try {
|
|
||||||
con = null;
|
|
||||||
reconnect(false);
|
|
||||||
} catch (Exception e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL informations ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (con == null)
|
|
||||||
try {
|
|
||||||
con = ds.getConnection();
|
|
||||||
} catch (Exception e) {
|
|
||||||
try {
|
|
||||||
reconnect(false);
|
|
||||||
con = ds.getConnection();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return con;
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void reconnect(boolean reload)
|
|
||||||
throws ClassNotFoundException, SQLException, TimeoutException,
|
|
||||||
PoolInitializationException {
|
|
||||||
if (ds != null)
|
|
||||||
ds.close();
|
|
||||||
HikariConfig config = new HikariConfig();
|
|
||||||
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
|
||||||
config.setUsername(this.username);
|
|
||||||
config.setPassword(this.password);
|
|
||||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
|
||||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
||||||
config.addDataSourceProperty("autoReconnect", true);
|
|
||||||
config.setInitializationFailFast(false);
|
|
||||||
config.setMaxLifetime(12000);
|
|
||||||
config.setPoolName("AuthMeMYSQLPool");
|
|
||||||
ds = new HikariDataSource(config);
|
|
||||||
if (!reload)
|
|
||||||
ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSourceType getType() {
|
public DataSourceType getType() {
|
||||||
return DataSourceType.MYSQL;
|
return DataSourceType.MYSQL;
|
||||||
@ -937,7 +907,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -959,7 +929,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setInt(1, 1);
|
pst.setInt(1, 1);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
@ -980,7 +950,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
if (user != null)
|
if (user != null)
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
@ -1000,7 +970,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setInt(2, 1);
|
pst.setInt(2, 1);
|
||||||
@ -1022,7 +992,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
@ -1043,7 +1013,7 @@ public class MySQL implements DataSource {
|
|||||||
Connection con = null;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, newone);
|
pst.setString(1, newone);
|
||||||
pst.setString(2, oldone);
|
pst.setString(2, oldone);
|
||||||
@ -1065,7 +1035,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -1116,7 +1086,7 @@ public class MySQL implements DataSource {
|
|||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = makeSureConnectionIsReady();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -8,10 +7,10 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
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;
|
||||||
@ -38,7 +37,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
private String columnLogged;
|
private String columnLogged;
|
||||||
private String columnRealName;
|
private String columnRealName;
|
||||||
|
|
||||||
public SQLite_HIKARI() {
|
public SQLite_HIKARI() throws ClassNotFoundException, SQLException, PoolInitializationException {
|
||||||
this.database = Settings.getMySQLDatabase;
|
this.database = Settings.getMySQLDatabase;
|
||||||
this.tableName = Settings.getMySQLTablename;
|
this.tableName = Settings.getMySQLTablename;
|
||||||
this.columnName = Settings.getMySQLColumnName;
|
this.columnName = Settings.getMySQLColumnName;
|
||||||
@ -56,65 +55,127 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
this.columnLogged = Settings.getMySQLColumnLogged;
|
this.columnLogged = Settings.getMySQLColumnLogged;
|
||||||
this.columnRealName = Settings.getMySQLColumnRealName;
|
this.columnRealName = Settings.getMySQLColumnRealName;
|
||||||
|
|
||||||
|
// Set the connection arguments (and check if connection is ok)
|
||||||
try {
|
try {
|
||||||
this.connect();
|
this.setConnectionArguments();
|
||||||
this.setup();
|
} catch (ClassNotFoundException ne) {
|
||||||
} catch (ClassNotFoundException e) {
|
ConsoleLogger.showError(ne.getMessage());
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError("Can't use the Hikari Connection Pool! Please, report this error to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
if (Settings.isStopEnabled) {
|
if (Settings.isStopEnabled) {
|
||||||
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new ClassNotFoundException(ne.getMessage());
|
||||||
|
} catch (IllegalArgumentException ae) { // This means that there are problems with the hikaricp pool arguments!
|
||||||
|
ConsoleLogger.showError(ae.getMessage());
|
||||||
|
ConsoleLogger.showError("Invalid database arguments! Please check your configuration!");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException(ae);
|
||||||
|
} catch (PoolInitializationException ie) { // Can't initialize the connection pool!
|
||||||
|
ConsoleLogger.showError(ie.getMessage());
|
||||||
|
ConsoleLogger.showError("Can't connect to the SQLite database! Please check your configuration!");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
throw new PoolInitializationException(ie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the database
|
||||||
|
try {
|
||||||
|
this.setupConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN...");
|
||||||
|
ConsoleLogger.showError("If this error persists, please report it to the developer! SHUTDOWN...");
|
||||||
|
this.close();
|
||||||
if (Settings.isStopEnabled) {
|
if (Settings.isStopEnabled) {
|
||||||
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
} else {
|
||||||
} catch (EOFException e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
return;
|
}
|
||||||
|
throw new SQLException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() throws SQLException, EOFException {
|
@Override
|
||||||
return this.ds.getConnection();
|
public DataSourceType getType() {
|
||||||
|
return DataSourceType.SQLITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void connect()
|
private synchronized void setConnectionArguments()
|
||||||
throws ClassNotFoundException, SQLException, EOFException {
|
throws ClassNotFoundException, IllegalArgumentException {
|
||||||
/*
|
HikariConfig config = new HikariConfig();
|
||||||
* Class.forName("org.sqlite.JDBC"); ConsoleLogger.info(
|
config.setPoolName("AuthMeSQLitePool");
|
||||||
* "SQLite driver loaded"); this.con =
|
config.setDataSourceClassName("org.sqlite.SQLiteDataSource");
|
||||||
* DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database
|
config.setJdbcUrl("jdbc:sqlite:plugins/AuthMe/" + database + ".db");
|
||||||
* + ".db");
|
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavariable
|
||||||
*/
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
Properties props = new Properties();
|
config.setMaxLifetime(180000); // 3 Min
|
||||||
props.setProperty("dataSourceClassName", "org.sqlite.SQLiteDataSource");
|
config.setIdleTimeout(60000); // 1 Min
|
||||||
HikariConfig config = new HikariConfig(props);
|
config.setMaximumPoolSize(50); // 50 (including idle connections)
|
||||||
config.setPoolName("AuthMeSQLiteLPool");
|
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
ConsoleLogger.info("Connection pool ready");
|
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setup() throws SQLException, EOFException {
|
private synchronized Connection getRawConnection() {
|
||||||
|
Connection con = null;
|
||||||
|
while(con == null){
|
||||||
|
try {
|
||||||
|
con = ds.getConnection();
|
||||||
|
} catch (SQLException ce) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized Connection getConnection() {
|
||||||
|
Connection con;
|
||||||
|
con = getRawConnection();
|
||||||
|
if(con == null){
|
||||||
|
ds.close();
|
||||||
|
ConsoleLogger.showError("Database connection is LOST! SHUTDOWN...");
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setupConnection() throws SQLException {
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
Statement st = null;
|
Statement st = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getRawConnection();
|
||||||
|
if(con == null){
|
||||||
|
ds.close();
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
ConsoleLogger.showError("Can't connect to the SQLite database... Please check your database settings in the config.yml file! SHUTDOWN...");
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
} else {
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
st = con.createStatement();
|
st = con.createStatement();
|
||||||
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||||
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||||
@ -166,14 +227,6 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
ConsoleLogger.info("SQLite Setup finished");
|
ConsoleLogger.info("SQLite Setup finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close(Connection con) {
|
|
||||||
try {
|
|
||||||
if (con != null)
|
|
||||||
con.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean isAuthAvailable(String user) {
|
public synchronized boolean isAuthAvailable(String user) {
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
@ -185,7 +238,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
return rs.next();
|
return rs.next();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -218,7 +271,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
@ -230,8 +283,8 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean saveAuth(PlayerAuth auth) {
|
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) {
|
if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) {
|
||||||
@ -252,7 +305,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(6, auth.getRealName());
|
pst.setString(6, auth.getRealName());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -272,7 +325,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(1, auth.getHash());
|
pst.setString(1, auth.getHash());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -294,7 +347,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(3, auth.getRealName());
|
pst.setString(3, auth.getRealName());
|
||||||
pst.setString(4, auth.getNickname());
|
pst.setString(4, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -313,7 +366,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
@ -337,7 +390,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
list.add(rs.getString(columnName));
|
list.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
@ -349,14 +402,14 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean removeAuth(String user) {
|
public synchronized boolean removeAuth(String user) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -368,8 +421,8 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateQuitLoc(PlayerAuth auth) {
|
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;");
|
||||||
@ -379,7 +432,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(4, auth.getWorld());
|
pst.setString(4, auth.getWorld());
|
||||||
pst.setString(5, auth.getNickname());
|
pst.setString(5, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -391,9 +444,9 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIps(String ip) {
|
public int getIps(String ip) {
|
||||||
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
|
||||||
int countIp = 0;
|
int countIp = 0;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
@ -404,7 +457,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countIp++;
|
countIp++;
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
@ -416,15 +469,15 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateEmail(PlayerAuth auth) {
|
public boolean updateEmail(PlayerAuth auth) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;");
|
||||||
pst.setString(1, auth.getEmail());
|
pst.setString(1, auth.getEmail());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -447,7 +500,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(1, auth.getSalt());
|
pst.setString(1, auth.getSalt());
|
||||||
pst.setString(2, auth.getNickname());
|
pst.setString(2, auth.getNickname());
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -457,56 +510,11 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void close() {
|
|
||||||
try {
|
|
||||||
if (ds != null)
|
|
||||||
ds.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() {
|
|
||||||
try {
|
|
||||||
connect();
|
|
||||||
setup();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
if (Settings.isStopEnabled) {
|
|
||||||
ConsoleLogger.showError("Can't reconnect to SQLite database... SHUTDOWN...");
|
|
||||||
AuthMe.getInstance().getServer().shutdown();
|
|
||||||
}
|
|
||||||
if (!Settings.isStopEnabled)
|
|
||||||
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void close(Statement st) {
|
|
||||||
if (st != null) {
|
|
||||||
try {
|
|
||||||
st.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void close(ResultSet rs) {
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||||
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
|
||||||
List<String> countIp = new ArrayList<String>();
|
List<String> countIp = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
@ -517,11 +525,11 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (NullPointerException ex) {
|
} catch (SQLException ex) {
|
||||||
return new ArrayList<String>();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -531,9 +539,9 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByIp(String ip) {
|
public List<String> getAllAuthsByIp(String ip) {
|
||||||
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
|
||||||
List<String> countIp = new ArrayList<String>();
|
List<String> countIp = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
@ -544,11 +552,11 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (NullPointerException ex) {
|
} catch (SQLException ex) {
|
||||||
return new ArrayList<String>();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -558,9 +566,9 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByEmail(String email) {
|
public List<String> getAllAuthsByEmail(String email) {
|
||||||
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
|
||||||
List<String> countEmail = new ArrayList<String>();
|
List<String> countEmail = new ArrayList<String>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
@ -571,11 +579,11 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (NullPointerException ex) {
|
} catch (SQLException ex) {
|
||||||
return new ArrayList<String>();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -585,8 +593,8 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void purgeBanned(List<String> banned) {
|
public void purgeBanned(List<String> banned) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
for (String name : banned) {
|
for (String name : banned) {
|
||||||
@ -594,7 +602,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setString(1, name);
|
pst.setString(1, name);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -602,16 +610,11 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DataSourceType getType() {
|
|
||||||
return DataSourceType.SQLITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLogged(String user) {
|
public boolean isLogged(String user) {
|
||||||
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
@ -619,7 +622,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
return (rs.getInt(columnLogged) == 1);
|
return (rs.getInt(columnLogged) == 1);
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -632,15 +635,15 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLogged(String user) {
|
public void setLogged(String user) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setInt(1, 1);
|
pst.setInt(1, 1);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -652,8 +655,8 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUnlogged(String user) {
|
public void setUnlogged(String user) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
if (user != null)
|
if (user != null)
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
@ -661,7 +664,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -673,15 +676,15 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void purgeLogged() {
|
public void purgeLogged() {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setInt(2, 1);
|
pst.setInt(2, 1);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -693,10 +696,10 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAccountsRegistered() {
|
public int getAccountsRegistered() {
|
||||||
int result = 0;
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
int result = 0;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||||
@ -704,7 +707,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
result = rs.getInt(1);
|
result = rs.getInt(1);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
@ -716,15 +719,15 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateName(String oldone, String newone) {
|
public void updateName(String oldone, String newone) {
|
||||||
PreparedStatement pst = null;
|
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
|
||||||
pst.setString(1, newone);
|
pst.setString(1, newone);
|
||||||
pst.setString(2, oldone);
|
pst.setString(2, oldone);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -736,10 +739,10 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PlayerAuth> getAllAuths() {
|
public List<PlayerAuth> getAllAuths() {
|
||||||
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||||
@ -758,7 +761,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
if (pAuth != null)
|
if (pAuth != null)
|
||||||
auths.add(pAuth);
|
auths.add(pAuth);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return auths;
|
return auths;
|
||||||
} finally {
|
} finally {
|
||||||
@ -770,10 +773,10 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PlayerAuth> getLoggedPlayers() {
|
public List<PlayerAuth> getLoggedPlayers() {
|
||||||
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
Connection con = null;
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
Connection con = null;
|
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
con = getConnection();
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||||
@ -792,7 +795,7 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
if (pAuth != null)
|
if (pAuth != null)
|
||||||
auths.add(pAuth);
|
auths.add(pAuth);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (SQLException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return auths;
|
return auths;
|
||||||
} finally {
|
} finally {
|
||||||
@ -801,4 +804,47 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
return auths;
|
return auths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void close() {
|
||||||
|
try {
|
||||||
|
if (ds != null)
|
||||||
|
ds.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(Statement st) {
|
||||||
|
if (st != null) {
|
||||||
|
try {
|
||||||
|
st.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(ResultSet rs) {
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(Connection con) {
|
||||||
|
if (con != null) {
|
||||||
|
try {
|
||||||
|
con.close();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,9 +48,11 @@ public class ModuleManager implements Module {
|
|||||||
@Override
|
@Override
|
||||||
public boolean load() {
|
public boolean load() {
|
||||||
File dir = new File(plugin.getDataFolder() + File.separator + "modules");
|
File dir = new File(plugin.getDataFolder() + File.separator + "modules");
|
||||||
if (dir == null || !dir.exists() || !dir.isDirectory() || dir.listFiles() == null || dir.listFiles().length <= 0)
|
String[] files = dir.list();
|
||||||
|
if (files == null || files.length == 0){
|
||||||
return false;
|
return false;
|
||||||
for (File pathToJar : dir.listFiles()) {
|
}
|
||||||
|
for (File pathToJar : dir.listFiles()) { // FindBugs: "possible null pointers" O_o ?
|
||||||
JarFile jarFile = null;
|
JarFile jarFile = null;
|
||||||
try {
|
try {
|
||||||
jarFile = new JarFile(pathToJar);
|
jarFile = new JarFile(pathToJar);
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
package fr.xephi.authme.settings;
|
package fr.xephi.authme.settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
|
||||||
public class Messages extends CustomConfiguration {
|
public class Messages extends CustomConfiguration {
|
||||||
@ -29,13 +26,11 @@ public class Messages extends CustomConfiguration {
|
|||||||
* @param filename
|
* @param filename
|
||||||
* The filename to open
|
* The filename to open
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public final void loadDefaults(File file) {
|
public final void loadDefaults(File file) {
|
||||||
InputStream stream = AuthMe.getInstance().getResource(file.getName());
|
if(file.isFile()){
|
||||||
if (stream == null)
|
setDefaults(YamlConfiguration.loadConfiguration(file));
|
||||||
return;
|
}
|
||||||
|
return;
|
||||||
setDefaults(YamlConfiguration.loadConfiguration(stream));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public final class Settings extends YamlConfiguration {
|
|||||||
public static String PLUGIN_FOLDER = "." + File.separator + "plugins" + File.separator + "AuthMe";
|
public static String PLUGIN_FOLDER = "." + File.separator + "plugins" + File.separator + "AuthMe";
|
||||||
public static final String CACHE_FOLDER = Settings.PLUGIN_FOLDER + File.separator + "cache";
|
public static final String CACHE_FOLDER = Settings.PLUGIN_FOLDER + File.separator + "cache";
|
||||||
public static final String AUTH_FILE = Settings.PLUGIN_FOLDER + File.separator + "auths.db";
|
public static final String AUTH_FILE = Settings.PLUGIN_FOLDER + File.separator + "auths.db";
|
||||||
public static final String MESSAGE_FILE = Settings.PLUGIN_FOLDER + File.separator + "messages";
|
public static final String MESSAGE_FILE = Settings.PLUGIN_FOLDER + File.separator + "messages" + File.separator + "messages";
|
||||||
public static final String SETTINGS_FILE = Settings.PLUGIN_FOLDER + File.separator + "config.yml";
|
public static final String SETTINGS_FILE = Settings.PLUGIN_FOLDER + File.separator + "config.yml";
|
||||||
public static List<String> allowCommands = null;
|
public static List<String> allowCommands = null;
|
||||||
public static List<String> getJoinPermissions = null;
|
public static List<String> getJoinPermissions = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user