From 5b145601bf70cbce998d863a9620628a57b73ecb Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 26 Nov 2017 14:31:19 +0200 Subject: [PATCH] Litebans Data --- .../plan/data/additional/HookHandler.java | 2 + .../plan/litebans/LiteBansBansTable.java | 74 --------------- .../plan/litebans/LiteBansData.java | 94 +++++++++++++++++++ .../plan/litebans/LiteBansHook.java | 3 +- .../litebans/LiteBansInspectBansTable.java | 71 -------------- 5 files changed, 97 insertions(+), 147 deletions(-) delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBansTable.java create mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java delete mode 100644 PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansInspectBansTable.java diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java index b9c5e4793..0b6d5c2a3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java @@ -1,5 +1,6 @@ package main.java.com.djrapitops.plan.data.additional; +import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.pluginbridge.plan.Bridge; import main.java.com.djrapitops.plan.Plan; @@ -50,6 +51,7 @@ public class HookHandler { return; } try { + StaticHolder.saveInstance(dataSource.getClass(), Plan.class); if (!configHandler.hasSection(dataSource)) { configHandler.createSection(dataSource); } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBansTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBansTable.java deleted file mode 100644 index e83944a85..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansBansTable.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.djrapitops.pluginbridge.plan.litebans; - -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.additional.AnalysisType; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.FormatUtils; -import main.java.com.djrapitops.plan.utilities.html.Html; - -import java.io.Serializable; -import java.sql.SQLException; -import java.util.List; -import java.util.UUID; - -/** - * PluginData class for LiteBans-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class LiteBansBansTable extends PluginData { - - private final LiteBansDatabaseQueries db; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param database Database class for queries - */ - public LiteBansBansTable(LiteBansDatabaseQueries database) { - super("LiteBans", "ban_table", AnalysisType.HTML); - db = database; - String banned = Html.FONT_AWESOME_ICON.parse("ban") + " Banned"; - String by = Html.FONT_AWESOME_ICON.parse("gavel") + " Banned By"; - String reason = Html.FONT_AWESOME_ICON.parse("balance-scale") + " Reason"; - String date = Html.FONT_AWESOME_ICON.parse("calendar-times-o") + " Expires"; - super.setPrefix(Html.TABLELINE_4.parse(banned, by, reason, date)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - return parseContainer("", getTableLines()); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } - - private String getTableLines() { - StringBuilder html = new StringBuilder(); - try { - List bans = db.getBans(); - for (BanObject ban : bans) { - UUID uuid = ban.getUuid(); - String name = getNameOf(uuid); - String tableLine = "REPLACE0REPLACE1REPLACE2REPLACE4"; - long expiry = ban.getExpiry(); - String expires = expiry <= 0 ? "Never" : FormatUtils.formatTimeStampSecond(expiry); - html.append(tableLine - .replace("REPLACE0", Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(name), name)) - .replace("REPLACE1", Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(ban.getBannedBy()), ban.getBannedBy())) - .replace("REPLACE2", ban.getReason()) - .replace("REPLACE3", expiry <= 0 ? "0" : Long.toString(expiry)) - .replace("REPLACE4", expires - ) - ); - } - } catch (SQLException ex) { - html.append(Html.TABLELINE_4.parse(ex.toString(), "", "", "")); - } - return html.toString(); - } -} 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 new file mode 100644 index 000000000..29bacb72d --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansData.java @@ -0,0 +1,94 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package com.djrapitops.pluginbridge.plan.litebans; + +import com.djrapitops.plugin.api.utility.log.Log; +import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.data.additional.*; +import main.java.com.djrapitops.plan.utilities.FormatUtils; +import main.java.com.djrapitops.plan.utilities.html.Html; + +import java.sql.SQLException; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +/** + * PluginData for LiteBans plugin. + * + * @author Rsl1122 + */ +public class LiteBansData extends PluginData { + + private final LiteBansDatabaseQueries db; + + public LiteBansData(LiteBansDatabaseQueries db) { + super(ContainerSize.TWO_THIRDS, "LiteBans"); + super.setIconColor("red"); + super.setPluginIcon("ban"); + this.db = db; + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + + String by = getWithIcon("Banned By", "gavel"); + String reason = getWithIcon("Reason", "balance-scale"); + String date = getWithIcon("Expires", "calendar-times-o"); + TableContainer banTable = new TableContainer(date, by, reason); + banTable.setColor("red"); + + try { + List bans = db.getBans(uuid); + if (bans.isEmpty()) { + banTable.addRow("Not LiteBanned"); + } else { + for (BanObject ban : bans) { + long expiry = ban.getExpiry(); + String expires = expiry <= 0 ? "Never" : FormatUtils.formatTimeStampSecond(expiry); + banTable.addRow( + expires, + Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(ban.getBannedBy()), ban.getBannedBy()), + ban.getReason() + ); + } + } + } catch (SQLException ex) { + Log.toLog(this.getClass().getName(), ex); + banTable.addRow("Error: " + ex); + } + inspectContainer.addTable("banTable", banTable); + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection collection, AnalysisContainer analysisContainer) throws Exception { + String banned = Html.FONT_AWESOME_ICON.parse("ban") + " Banned"; + String by = Html.FONT_AWESOME_ICON.parse("gavel") + " Banned By"; + String reason = Html.FONT_AWESOME_ICON.parse("balance-scale") + " Reason"; + String date = Html.FONT_AWESOME_ICON.parse("calendar-times-o") + " Expires"; + TableContainer banTable = new TableContainer(banned, by, reason, date); + banTable.setColor("red"); + + List bans = db.getBans(); + for (BanObject ban : bans) { + UUID uuid = ban.getUuid(); + String name = Plan.getInstance().getDataCache().getName(uuid); + long expiry = ban.getExpiry(); + String expires = expiry <= 0 ? "Never" : FormatUtils.formatTimeStampSecond(expiry); + + banTable.addRow( + Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(name), name), + Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(ban.getBannedBy()), ban.getBannedBy()), + ban.getReason(), + expires + ); + } + analysisContainer.addTable("banTable", banTable); + + return analysisContainer; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansHook.java index 8d59d1b36..a1998ad5f 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansHook.java @@ -37,8 +37,7 @@ public class LiteBansHook extends Hook { public void hook() throws NoClassDefFoundError { if (enabled) { LiteBansDatabaseQueries db = new LiteBansDatabaseQueries(); - addPluginDataSource(new LiteBansBansTable(db)); - addPluginDataSource(new LiteBansInspectBansTable(db)); + addPluginDataSource(new LiteBansData(db)); } } } diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansInspectBansTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansInspectBansTable.java deleted file mode 100644 index 843c65422..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/litebans/LiteBansInspectBansTable.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.djrapitops.pluginbridge.plan.litebans; - -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.additional.PluginData; -import main.java.com.djrapitops.plan.utilities.FormatUtils; -import main.java.com.djrapitops.plan.utilities.html.Html; - -import java.io.Serializable; -import java.sql.SQLException; -import java.util.List; -import java.util.UUID; - -/** - * PluginData class for LiteBans-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class LiteBansInspectBansTable extends PluginData { - - private final LiteBansDatabaseQueries db; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param database Database class for queries - */ - public LiteBansInspectBansTable(LiteBansDatabaseQueries database) { - super("LiteBans", "inspect_banned"); - db = database; - String by = Html.FONT_AWESOME_ICON.parse("gavel") + " Banned By"; - String reason = Html.FONT_AWESOME_ICON.parse("balance-scale") + " Reason"; - String date = Html.FONT_AWESOME_ICON.parse("calendar-times-o") + " Expires"; - super.setPrefix(Html.TABLELINE_3.parse(date, by, reason)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - return parseContainer("", getTableLines(uuid)); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } - - private String getTableLines(UUID uuid) { - StringBuilder html = new StringBuilder(); - try { - List bans = db.getBans(uuid); - if (bans.isEmpty()) { - html.append(Html.TABLELINE_3.parse("Not LiteBanned", "", "")); - } else { - for (BanObject ban : bans) { - long expiry = ban.getExpiry(); - String expires = expiry <= 0 ? "Never" : FormatUtils.formatTimeStampSecond(expiry); - html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse( - expiry <= 0 ? "0" : Long.toString(expiry), - expires, - Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(ban.getBannedBy()), ban.getBannedBy()), - ban.getReason()) - ); - } - } - } catch (SQLException ex) { - html.append(Html.TABLELINE_3.parse(ex.toString(), "", "")); - } - return html.toString(); - } -}