Fixed issues in Litebans extension

- Fixed softdepend on Spigot
- Fixed #1355, did not prevent further mistakes like this.
This commit is contained in:
Risto Lahtela 2020-05-07 10:58:45 +03:00
parent 048fa559ff
commit 6b4db32244
4 changed files with 93 additions and 3 deletions

View File

@ -172,7 +172,8 @@ public abstract class SQLDB extends AbstractDatabase {
new RegisterDateMinimizationPatch(),
new BadNukkitRegisterValuePatch(),
new LinkedToSecurityTablePatch(),
new LinkUsersToPlayersSecurityTablePatch()
new LinkUsersToPlayersSecurityTablePatch(),
new LitebansTableHeaderPatch()
};
}

View File

@ -0,0 +1,89 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.storage.database.transactions.patches;
import com.djrapitops.plan.storage.database.queries.QueryStatement;
import com.djrapitops.plan.storage.database.sql.tables.ExtensionPluginTable;
import com.djrapitops.plan.storage.database.sql.tables.ExtensionServerTableValueTable;
import com.djrapitops.plan.storage.database.sql.tables.ExtensionTableProviderTable;
import com.djrapitops.plan.storage.database.transactions.ExecBatchStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
/**
* Removes invalid data caused by https://github.com/plan-player-analytics/Plan/issues/1355.
*
* @author Rsl1122
*/
public class LitebansTableHeaderPatch extends Patch {
private Set<Integer> found;
@Override
public boolean hasBeenApplied() {
String sql = SELECT + DISTINCT + "pr." + ExtensionTableProviderTable.ID + " as id" +
FROM + ExtensionServerTableValueTable.TABLE_NAME + " v" +
INNER_JOIN + ExtensionTableProviderTable.TABLE_NAME + " pr on pr." + ExtensionTableProviderTable.ID + "=v." + ExtensionServerTableValueTable.TABLE_ID +
INNER_JOIN + ExtensionPluginTable.TABLE_NAME + " p on p." + ExtensionPluginTable.ID + "=pr." + ExtensionTableProviderTable.PLUGIN_ID +
WHERE + "p." + ExtensionPluginTable.PLUGIN_NAME + "=?" +
AND + "(pr." + ExtensionTableProviderTable.PROVIDER_NAME + "=?" +
OR + "pr." + ExtensionTableProviderTable.PROVIDER_NAME + "=?" +
OR + "pr." + ExtensionTableProviderTable.PROVIDER_NAME + "=?" +
OR + "pr." + ExtensionTableProviderTable.PROVIDER_NAME + "=?)";
found = query(new QueryStatement<Set<Integer>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, "Litebans");
statement.setString(2, "bans");
statement.setString(3, "warns");
statement.setString(4, "kicks");
statement.setString(5, "mutes");
}
@Override
public Set<Integer> processResults(ResultSet set) throws SQLException {
Set<Integer> ids = new HashSet<>();
while (set.next()) {
ids.add(set.getInt("id"));
}
return ids;
}
});
return found.isEmpty();
}
@Override
protected void applyPatch() {
String sql = DELETE_FROM + ExtensionServerTableValueTable.TABLE_NAME +
WHERE + ExtensionServerTableValueTable.TABLE_ID + "=?";
execute(new ExecBatchStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Integer id : found) {
statement.setInt(1, id);
statement.addBatch();
}
}
});
}
}

View File

@ -18,7 +18,7 @@ softdepend:
- GriefPrevention
- GriefPreventionPlus
- Jobs
- Litebans
- LiteBans
- LuckPerms
- mcMMO
- MinigamesLib

View File

@ -17,7 +17,7 @@ dependencies {
compile 'com.djrapitops:Extension-GriefPrevention-Sponge:4.0.1-R0.2'
compile 'com.djrapitops:Extension-GriefPreventionPlus:13.3-R0.2'
compile 'com.djrapitops:Extension-Jobs:4.13.1-R0.1'
compile 'com.djrapitops:Extension-Litebans:0.3-R0.1'
compile 'com.djrapitops:Extension-Litebans:0.3.2-R0.1'
compile 'com.djrapitops:Extension-LuckPerms:5.0-R0.2'
compile 'com.djrapitops:Extension-McMMO:2.1.44-R0.2'
compile 'com.djrapitops:Extension-MinigamesLib:1.14.17-R0.2'