From 6b4db3224405f7dda64c38bd51630c8cb8d02394 Mon Sep 17 00:00:00 2001
From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com>
Date: Thu, 7 May 2020 10:58:45 +0300
Subject: [PATCH] Fixed issues in Litebans extension
- Fixed softdepend on Spigot
- Fixed #1355, did not prevent further mistakes like this.
---
.../plan/storage/database/SQLDB.java | 3 +-
.../patches/LitebansTableHeaderPatch.java | 89 +++++++++++++++++++
Plan/common/src/main/resources/plugin.yml | 2 +-
Plan/extensions/build.gradle | 2 +-
4 files changed, 93 insertions(+), 3 deletions(-)
create mode 100644 Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/LitebansTableHeaderPatch.java
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/SQLDB.java
index 91fe165bf..c8834c3bc 100644
--- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/SQLDB.java
+++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/SQLDB.java
@@ -172,7 +172,8 @@ public abstract class SQLDB extends AbstractDatabase {
new RegisterDateMinimizationPatch(),
new BadNukkitRegisterValuePatch(),
new LinkedToSecurityTablePatch(),
- new LinkUsersToPlayersSecurityTablePatch()
+ new LinkUsersToPlayersSecurityTablePatch(),
+ new LitebansTableHeaderPatch()
};
}
diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/LitebansTableHeaderPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/LitebansTableHeaderPatch.java
new file mode 100644
index 000000000..44e3ab25a
--- /dev/null
+++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/patches/LitebansTableHeaderPatch.java
@@ -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 .
+ */
+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 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>(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 processResults(ResultSet set) throws SQLException {
+ Set 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();
+ }
+ }
+ });
+ }
+}
diff --git a/Plan/common/src/main/resources/plugin.yml b/Plan/common/src/main/resources/plugin.yml
index 460068dd8..e0e22c36a 100644
--- a/Plan/common/src/main/resources/plugin.yml
+++ b/Plan/common/src/main/resources/plugin.yml
@@ -18,7 +18,7 @@ softdepend:
- GriefPrevention
- GriefPreventionPlus
- Jobs
- - Litebans
+ - LiteBans
- LuckPerms
- mcMMO
- MinigamesLib
diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle
index 29ba91cf5..500487934 100644
--- a/Plan/extensions/build.gradle
+++ b/Plan/extensions/build.gradle
@@ -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'