From d677fb816e077f75a7616f27dc0aa6e9374bf343 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 2 Jun 2018 08:07:06 +0300 Subject: [PATCH] Fixed compile issues in PluginBridge --- .../plan/litebans/LiteBansData.java | 20 +++++++-------- .../litebans/LiteBansDatabaseQueries.java | 25 +++++++++++-------- .../protocolsupport/ProtocolSupportData.java | 6 ++--- .../plan/viaversion/ProtocolTable.java | 12 ++++----- .../plan/viaversion/ViaVersionData.java | 10 ++++---- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java index 23713012e..0d75e7c4f 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java @@ -5,6 +5,7 @@ package com.djrapitops.pluginbridge.plan.litebans; import com.djrapitops.plan.api.PlanAPI; +import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.element.TableContainer; @@ -17,7 +18,6 @@ import com.djrapitops.plan.utilities.html.Html; import com.djrapitops.plan.utilities.html.structure.TabsElement; import com.djrapitops.plugin.api.utility.log.Log; -import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; @@ -96,7 +96,7 @@ public class LiteBansData extends PluginData implements BanData { ); } } - } catch (SQLException ex) { + } catch (DBOpException ex) { Log.toLog(this.getClass().getName(), ex); table.addRow("Error: " + ex); } @@ -124,7 +124,7 @@ public class LiteBansData extends PluginData implements BanData { return analysisContainer; } - private TableContainer getBanTable() throws SQLException { + private TableContainer getBanTable() { String banned = getWithIcon("Banned", "ban"); String by = getWithIcon("Banned By", "gavel"); String reason = getWithIcon("Reason", "balance-scale"); @@ -137,7 +137,7 @@ public class LiteBansData extends PluginData implements BanData { return banTable; } - private TableContainer getMuteTable() throws SQLException { + private TableContainer getMuteTable() { String muted = getWithIcon("Muted", "bell-slash-o"); String by = getWithIcon("Muted By", "gavel"); String reason = getWithIcon("Reason", "balance-scale"); @@ -150,7 +150,7 @@ public class LiteBansData extends PluginData implements BanData { return muteTable; } - private TableContainer getWarningTable() throws SQLException { + private TableContainer getWarningTable() { String warned = getWithIcon("Warned", "exclamation-triangle"); String by = getWithIcon("Warned By", "gavel"); String reason = getWithIcon("Reason", "balance-scale"); @@ -163,7 +163,7 @@ public class LiteBansData extends PluginData implements BanData { return warnTable; } - private TableContainer getKickTable() throws SQLException { + private TableContainer getKickTable() { String kicked = getWithIcon("Kicked", "user-times"); String by = getWithIcon("Kicked By", "gavel"); String reason = getWithIcon("Reason", "balance-scale"); @@ -201,8 +201,8 @@ public class LiteBansData extends PluginData implements BanData { public boolean isBanned(UUID uuid) { try { return !db.getBans(uuid).isEmpty(); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); + } catch (DBOpException e) { + Log.toLog(this.getClass(), e); } return false; } @@ -217,8 +217,8 @@ public class LiteBansData extends PluginData implements BanData { } return collection.stream().filter(banned::contains).collect(Collectors.toSet()); - } catch (SQLException e) { - Log.toLog(this.getClass().getName(), e); + } catch (DBOpException e) { + Log.toLog(this.getClass(), e); } return new HashSet<>(); } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java index 9463d8c6c..ef1fb183a 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansDatabaseQueries.java @@ -1,5 +1,6 @@ package com.djrapitops.pluginbridge.plan.litebans; +import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement; import com.djrapitops.plan.system.database.databases.sql.tables.Table; @@ -41,13 +42,15 @@ public class LiteBansDatabaseQueries extends Table { } @Override - protected T query(QueryStatement statement) throws SQLException { + protected T query(QueryStatement statement) { try (PreparedStatement preparedStatement = database.prepareStatement(statement.getSql())) { return statement.executeQuery(preparedStatement); + } catch (SQLException e) { + throw DBOpException.forCause(statement.getSql(), e); } } - private List getObjs(String table) throws SQLException { + private List getObjs(String table) { String sql = selectSQL + table + " LIMIT 5000"; return query(new QueryAllStatement>(sql, 2000) { @@ -58,19 +61,19 @@ public class LiteBansDatabaseQueries extends Table { }); } - public List getBans() throws SQLException { + public List getBans() { return getObjs(banTable); } - public List getMutes() throws SQLException { + public List getMutes() { return getObjs(mutesTable); } - public List getWarnings() throws SQLException { + public List getWarnings() { return getObjs(warningsTable); } - public List getKicks() throws SQLException { + public List getKicks() { return getObjs(kicksTable); } @@ -93,23 +96,23 @@ public class LiteBansDatabaseQueries extends Table { return objs; } - public List getBans(UUID playerUUID) throws SQLException { + public List getBans(UUID playerUUID) { return getObjs(playerUUID, banTable); } - public List getMutes(UUID playerUUID) throws SQLException { + public List getMutes(UUID playerUUID) { return getObjs(playerUUID, mutesTable); } - public List getWarnings(UUID playerUUID) throws SQLException { + public List getWarnings(UUID playerUUID) { return getObjs(playerUUID, warningsTable); } - public List getKicks(UUID playerUUID) throws SQLException { + public List getKicks(UUID playerUUID) { return getObjs(playerUUID, kicksTable); } - private List getObjs(UUID playerUUID, String table) throws SQLException { + private List getObjs(UUID playerUUID, String table) { String sql = selectSQL + table + " WHERE uuid=?"; return query(new QueryStatement>(sql, 2000) { diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/protocolsupport/ProtocolSupportData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/protocolsupport/ProtocolSupportData.java index 6d64bb3d4..585bc0298 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/protocolsupport/ProtocolSupportData.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/protocolsupport/ProtocolSupportData.java @@ -4,6 +4,7 @@ */ package com.djrapitops.pluginbridge.plan.protocolsupport; +import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.element.TableContainer; @@ -13,7 +14,6 @@ import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.pluginbridge.plan.viaversion.Protocol; import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable; -import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -43,7 +43,7 @@ public class ProtocolSupportData extends PluginData { inspectContainer.addValue(getWithIcon("Last Join Version", "signal", "light-green"), protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known"); - } catch (SQLException ex) { + } catch (DBOpException ex) { Log.toLog(this.getClass().getName(), ex); } @@ -56,7 +56,7 @@ public class ProtocolSupportData extends PluginData { try { versions = table.getProtocolVersions(); - } catch (SQLException ex) { + } catch (DBOpException ex) { Log.toLog(this.getClass().getName(), ex); return analysisContainer; } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ProtocolTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ProtocolTable.java index 2f798fe02..edb1d31c0 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ProtocolTable.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ProtocolTable.java @@ -46,7 +46,7 @@ public class ProtocolTable extends Table { ); } - public void saveProtocolVersion(UUID uuid, int version) throws SQLException { + public void saveProtocolVersion(UUID uuid, int version) { if (exists(uuid)) { updateProtocolVersion(uuid, version); } else { @@ -54,7 +54,7 @@ public class ProtocolTable extends Table { } } - public int getProtocolVersion(UUID uuid) throws SQLException { + public int getProtocolVersion(UUID uuid) { String sql = "SELECT " + columnProtocolVersion + " FROM " + tableName + " WHERE " + columnUUID + "=?"; return query(new QueryStatement(sql) { @@ -74,7 +74,7 @@ public class ProtocolTable extends Table { }); } - public Map getProtocolVersions() throws SQLException { + public Map getProtocolVersions() { return query(new QueryAllStatement>(Select.all(tableName).toString(), 5000) { @Override public Map processResults(ResultSet set) throws SQLException { @@ -89,11 +89,11 @@ public class ProtocolTable extends Table { }); } - private boolean exists(UUID uuid) throws SQLException { + private boolean exists(UUID uuid) { return getProtocolVersion(uuid) != -1; } - private void updateProtocolVersion(UUID uuid, int version) throws SQLException { + private void updateProtocolVersion(UUID uuid, int version) { String sql = "UPDATE " + tableName + " SET " + columnProtocolVersion + "=? " + " WHERE (" + columnUUID + "=?)"; @@ -107,7 +107,7 @@ public class ProtocolTable extends Table { }); } - private void insertProtocolVersion(UUID uuid, int version) throws SQLException { + private void insertProtocolVersion(UUID uuid, int version) { String sql = "INSERT INTO " + tableName + " (" + columnUUID + ", " + columnProtocolVersion diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionData.java index d98c22171..4ee9e4182 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionData.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionData.java @@ -4,6 +4,7 @@ */ package com.djrapitops.pluginbridge.plan.viaversion; +import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.element.TableContainer; @@ -11,7 +12,6 @@ import com.djrapitops.plan.data.plugin.ContainerSize; import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plugin.api.utility.log.Log; -import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -41,8 +41,8 @@ public class ViaVersionData extends PluginData { inspectContainer.addValue(getWithIcon("Last Join Version", "signal", "light-green"), protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known"); - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); + } catch (DBOpException ex) { + Log.toLog(this.getClass(), ex); } return inspectContainer; @@ -54,8 +54,8 @@ public class ViaVersionData extends PluginData { try { versions = table.getProtocolVersions(); - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); + } catch (DBOpException ex) { + Log.toLog(this.getClass(), ex); return analysisContainer; }