mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-09 20:31:38 +01:00
Merge branch '3.7.0' into master
This commit is contained in:
commit
982a094dd5
@ -43,7 +43,7 @@ public class WebCheckCommand extends SubCommand {
|
||||
if (!Check.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
|
||||
return;
|
||||
}
|
||||
WebUser info = table.getSecurityInfo(user);
|
||||
WebUser info = table.getWebUser(user);
|
||||
sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel());
|
||||
} catch (Exception ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
|
@ -30,6 +30,7 @@ import java.util.stream.Collectors;
|
||||
public abstract class SQLDB extends Database {
|
||||
|
||||
private final boolean supportsModification;
|
||||
private final boolean usingMySQL;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
@ -40,7 +41,7 @@ public abstract class SQLDB extends Database {
|
||||
public SQLDB(Plan plugin, boolean supportsModification) {
|
||||
super(plugin);
|
||||
this.supportsModification = supportsModification;
|
||||
boolean usingMySQL = getName().equals("MySQL");
|
||||
usingMySQL = getName().equals("MySQL");
|
||||
|
||||
usersTable = new UsersTable(this, usingMySQL);
|
||||
gmTimesTable = new GMTimesTable(this, usingMySQL);
|
||||
@ -153,7 +154,6 @@ public abstract class SQLDB extends Database {
|
||||
Log.error("Failed to create table: " + securityTable.getTableName());
|
||||
return false;
|
||||
}
|
||||
|
||||
Benchmark.stop("Database: Create tables");
|
||||
|
||||
if (!newDatabase && getVersion() < 8) {
|
||||
@ -250,6 +250,7 @@ public abstract class SQLDB extends Database {
|
||||
@Override
|
||||
public void setVersion(int version) throws SQLException {
|
||||
versionTable.setVersion(version);
|
||||
commit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -293,7 +294,7 @@ public abstract class SQLDB extends Database {
|
||||
return false;
|
||||
}
|
||||
int userId = usersTable.getUserId(uuid);
|
||||
return userId != -1
|
||||
boolean success = userId != -1
|
||||
&& locationsTable.removeUserLocations(userId)
|
||||
&& ipsTable.removeUserIps(userId)
|
||||
&& nicknamesTable.removeUserNicknames(userId)
|
||||
@ -302,6 +303,12 @@ public abstract class SQLDB extends Database {
|
||||
&& killsTable.removeUserKillsAndVictims(userId)
|
||||
&& worldTimesTable.removeUserWorldTimes(userId)
|
||||
&& usersTable.removeUser(uuid);
|
||||
if (success) {
|
||||
commit();
|
||||
} else {
|
||||
rollback();
|
||||
}
|
||||
return success;
|
||||
} finally {
|
||||
Benchmark.stop("Database: Remove Account");
|
||||
setAvailable();
|
||||
@ -488,6 +495,7 @@ public abstract class SQLDB extends Database {
|
||||
gmTimesTable.saveGMTimes(gmTimes);
|
||||
worldTable.saveWorlds(worldNames);
|
||||
worldTimesTable.saveWorldTimes(worldTimes);
|
||||
commit();
|
||||
userDatas.values().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(UserData::isAccessed)
|
||||
@ -523,6 +531,7 @@ public abstract class SQLDB extends Database {
|
||||
worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
||||
worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
||||
data.stopAccessing();
|
||||
commit();
|
||||
setAvailable();
|
||||
}
|
||||
|
||||
@ -547,14 +556,25 @@ public abstract class SQLDB extends Database {
|
||||
*/
|
||||
@Override
|
||||
public boolean removeAllData() {
|
||||
boolean success = true;
|
||||
setStatus("Clearing all data");
|
||||
for (Table table : getAllTablesInRemoveOrder()) {
|
||||
if (!table.removeAllData()) {
|
||||
return false;
|
||||
try {
|
||||
for (Table table : getAllTablesInRemoveOrder()) {
|
||||
if (!table.removeAllData()) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
commit();
|
||||
} else {
|
||||
rollback();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
setAvailable();
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -578,4 +598,26 @@ public abstract class SQLDB extends Database {
|
||||
private void setAvailable() {
|
||||
setStatus("Running");
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits changes to the .db file when using SQLite Database.
|
||||
* <p>
|
||||
* MySQL has Auto Commit enabled.
|
||||
*/
|
||||
public void commit() throws SQLException {
|
||||
if (!usingMySQL) {
|
||||
getConnection().commit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts transaction when using SQLite Database.
|
||||
* <p>
|
||||
* MySQL has Auto Commit enabled.
|
||||
*/
|
||||
public void rollback() throws SQLException {
|
||||
if (!usingMySQL) {
|
||||
connection.rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class CommandUseTable extends Table {
|
||||
}
|
||||
|
||||
updateCommands(updateData);
|
||||
commit();
|
||||
Benchmark.stop("Database: Save Commanduse");
|
||||
}
|
||||
|
||||
|
@ -77,16 +77,17 @@ public class SecurityTable extends Table {
|
||||
statement.setString(2, saltPassHash);
|
||||
statement.setInt(3, permLevel);
|
||||
statement.execute();
|
||||
commit();
|
||||
} finally {
|
||||
close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean userExists(String user) throws SQLException {
|
||||
return getSecurityInfo(user) != null;
|
||||
return getWebUser(user) != null;
|
||||
}
|
||||
|
||||
public WebUser getSecurityInfo(String user) throws SQLException {
|
||||
public WebUser getWebUser(String user) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
|
@ -172,4 +172,14 @@ public abstract class Table {
|
||||
public String toString() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commits changes to .db file when using SQLite databse.
|
||||
*
|
||||
* Auto Commit enabled when using MySQL
|
||||
* @throws SQLException If commit fails or there is nothing to commit.
|
||||
*/
|
||||
protected void commit() throws SQLException {
|
||||
db.commit();
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class WebServer {
|
||||
throw new IllegalArgumentException("User Doesn't exist");
|
||||
}
|
||||
|
||||
WebUser webUser = securityTable.getSecurityInfo(user);
|
||||
WebUser webUser = securityTable.getWebUser(user);
|
||||
|
||||
boolean correctPass = PassEncryptUtil.verifyPassword(passwordRaw, webUser.getSaltedPassHash());
|
||||
if (!correctPass) {
|
||||
|
@ -3,9 +3,11 @@ package test.java.main.java.com.djrapitops.plan.database;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.TPS;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -125,4 +127,15 @@ public class DatabaseCommitTest {
|
||||
db.init();
|
||||
assertTrue(!db.getUserDataForUUIDS(uuids).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommitToDBFile5() throws SQLException, PassEncryptUtil.CannotPerformOperationException {
|
||||
db.init();
|
||||
List<UserData> data = RandomData.randomUserData();
|
||||
WebUser webUser = new WebUser("Test", PassEncryptUtil.createHash("surprise"), 0);
|
||||
db.getSecurityTable().addNewUser(webUser);
|
||||
db.close();
|
||||
db.init();
|
||||
assertTrue(webUser.equals(db.getSecurityTable().getWebUser("Test")));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user