mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Actually make use of the checkConnected calls.
This commit is contained in:
parent
73d0b377ae
commit
c98d298cf1
@ -51,12 +51,14 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private int reconnectAttempt = 0;
|
||||
|
||||
protected SQLDatabaseManager() {
|
||||
checkConnected();
|
||||
checkStructure();
|
||||
}
|
||||
|
||||
public void purgePowerlessUsers() {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||
|
||||
Collection<ArrayList<String>> usernames = read("SELECT u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0").values();
|
||||
@ -73,7 +75,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public void purgeOldUsers() {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
mcMMO.p.getLogger().info("Purging old users...");
|
||||
@ -92,7 +97,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = update("DELETE FROM u, e, h, s, c " +
|
||||
"USING " + tablePrefix + "users u " +
|
||||
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
|
||||
@ -107,7 +115,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public void saveUser(PlayerProfile profile) {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int userId = readId(profile.getPlayerName());
|
||||
if (userId == -1) {
|
||||
newUser(profile.getPlayerName());
|
||||
@ -303,7 +314,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public void newUser(String playerName) {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
|
||||
try {
|
||||
@ -331,7 +345,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public PlayerProfile loadPlayerProfile(String playerName, boolean create) {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return loadPlayerProfile(playerName, false); //Retry if not connected
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
|
||||
try {
|
||||
@ -396,7 +413,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public void convertUsers(DatabaseManager destination) {
|
||||
checkConnected();
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement statement = null;
|
||||
|
||||
try {
|
||||
@ -532,8 +552,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
public List<String> getStoredUsers() {
|
||||
checkConnected();
|
||||
ArrayList<String> users = new ArrayList<String>();
|
||||
|
||||
if (checkConnected()) {
|
||||
Statement stmt = null;
|
||||
try {
|
||||
stmt = connection.createStatement();
|
||||
@ -555,6 +576,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
@ -599,6 +622,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
* Checks that the database structure is present and correct
|
||||
*/
|
||||
private void checkStructure() {
|
||||
if (!checkConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` ("
|
||||
+ "`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
|
||||
+ "`user` varchar(40) NOT NULL,"
|
||||
|
Loading…
Reference in New Issue
Block a user