diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/Protocol.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/Protocol.java index e5f047cf4..5f292a59d 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/Protocol.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/Protocol.java @@ -50,7 +50,7 @@ public class Protocol { case 4: return "1.7.5"; default: - return "Unknown ProtocolVersion: " + protocolVersion; + return "Unknown (" + protocolVersion + ")"; } } } 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 new file mode 100644 index 000000000..6cf8d83a3 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionData.java @@ -0,0 +1,88 @@ +/* + * 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.viaversion; + +import com.djrapitops.plugin.api.utility.log.Log; +import main.java.com.djrapitops.plan.data.additional.*; + +import java.sql.SQLException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * PluginData for ViaVersion plugin. + * + * @author Rsl1122 + */ +public class ViaVersionData extends PluginData { + + private final ProtocolTable table; + + public ViaVersionData(ProtocolTable table) { + super(ContainerSize.THIRD, "ViaVersion"); + super.setPluginIcon("gamepad"); + super.setIconColor("light-green"); + this.table = table; + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception { + try { + int protocolVersion = table.getProtocolVersion(uuid); + + 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); + } + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection collection, AnalysisContainer analysisContainer) throws Exception { + Map versions; + + try { + versions = table.getProtocolVersions(); + } catch (SQLException ex) { + Log.toLog(this.getClass().getName(), ex); + return analysisContainer; + } + + Map userVersions = versions.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> Protocol.getMCVersion(entry.getValue()))); + + analysisContainer.addPlayerTableValues(getWithIcon("Last Version", "signal"), userVersions); + + String versionS = getWithIcon("Version", "signal"); + String membersS = getWithIcon("Users", "users"); + TableContainer versionTable = new TableContainer(versionS, membersS); + versionTable.setColor("green"); + Map usersPerVersion = getUsersPerVersion(versions); + for (Map.Entry entry : usersPerVersion.entrySet()) { + versionTable.addRow(entry.getKey(), entry.getValue()); + } + analysisContainer.addTable("versionTable", versionTable); + + return analysisContainer; + } + + private Map getUsersPerVersion(Map versions) { + Map usersPerVersion = new HashMap<>(); + + for (int protocolVersion : versions.values()) { + String mcVer = Protocol.getMCVersion(protocolVersion); + if (!usersPerVersion.containsKey(mcVer)) { + usersPerVersion.put(mcVer, 0); + } + usersPerVersion.replace(mcVer, usersPerVersion.get(mcVer) + 1); + } + return usersPerVersion; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionHook.java index 41ed35da0..d6e5fcd35 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionHook.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionHook.java @@ -49,7 +49,6 @@ public class ViaVersionHook extends Hook { listener = new PlayerVersionListener(api); plan.registerListener(listener); } - addPluginDataSource(new ViaVersionVersionTable(table)); - addPluginDataSource(new ViaVersionVersion(table)); + addPluginDataSource(new ViaVersionData(table)); } } \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersion.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersion.java deleted file mode 100644 index 2e7b27b50..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersion.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.djrapitops.pluginbridge.plan.viaversion; - -import com.djrapitops.plugin.api.utility.log.Log; -import com.djrapitops.pluginbridge.plan.vault.VaultHook; -import main.java.com.djrapitops.plan.data.additional.PluginData; - -import java.io.Serializable; -import java.sql.SQLException; -import java.util.UUID; - -/** - * PluginData class for Vault-plugin. - * - * Registered to the plugin by VaultHook - * - * Gives Total Balance Double as value. - * - * @author Rsl1122 - * @since 3.1.0 - * @see VaultHook - */ -public class ViaVersionVersion extends PluginData { - - private final ProtocolTable table; - - /** - * Class Constructor, sets the parameters of the PluginData object. - * - * @param table ProtocolTable where protocol versions are stored. - */ - public ViaVersionVersion(ProtocolTable table) { - super("ViaVersion", "version"); - this.table = table; - super.setAnalysisOnly(false); - super.setIcon("signal"); - super.setPrefix("Last Join Version: "); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - try { - int protocolVersion = table.getProtocolVersion(uuid); - if (protocolVersion == -1) { - return parseContainer(modifierPrefix, "Not Yet Known"); - } - return parseContainer(modifierPrefix, Protocol.getMCVersion(protocolVersion)); - } catch (SQLException ex) { - Log.toLog(this.getClass().getName(), ex); - return parseContainer(modifierPrefix, ex.toString()); - } - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } - -} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersionTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersionTable.java deleted file mode 100644 index 7e9061765..000000000 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/viaversion/ViaVersionVersionTable.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package com.djrapitops.pluginbridge.plan.viaversion; - -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.html.Html; - -import java.io.Serializable; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** - * PluginData class for Vault-plugin. - * - * @author Rsl1122 - * @since 3.5.0 - */ -public class ViaVersionVersionTable extends PluginData { - - private final ProtocolTable table; - - public ViaVersionVersionTable(ProtocolTable table) { - super("ViaVersion", "version_table", AnalysisType.HTML); - this.table = table; - String version = Html.FONT_AWESOME_ICON.parse("signal") + " Version"; - String members = Html.FONT_AWESOME_ICON.parse("users") + " Users"; - super.setPrefix(Html.TABLE_START_2.parse(version, members)); - super.setSuffix(Html.TABLE_END.parse()); - } - - @Override - public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { - String tableLines = getTableLines(); - return parseContainer("", tableLines); - } - - @Override - public Serializable getValue(UUID uuid) { - return -1; - } - - private String getTableLines() { - StringBuilder html = new StringBuilder(); - - Map usersPerVersion = getUsersPerVersion(html); - if (usersPerVersion.isEmpty()) { - html.append(Html.TABLELINE_2.parse("No joins after installation", "")); - } else { - usersPerVersion.entrySet().stream().map(e -> Html.TABLELINE_2.parse(e.getKey(), e.getValue() + "")).forEach(html::append); - } - return html.toString(); - } - - private Map getUsersPerVersion(StringBuilder html) { - Map usersPerVersion = new HashMap<>(); - try { - Map versions = table.getProtocolVersions(); - for (int protocolVersion : versions.values()) { - String mcVer = Protocol.getMCVersion(protocolVersion); - if (!usersPerVersion.containsKey(mcVer)) { - usersPerVersion.put(mcVer, 0); - } - usersPerVersion.replace(mcVer, usersPerVersion.get(mcVer) + 1); - } - } catch (SQLException ex) { - html.append(Html.TABLELINE_2.parse(ex.toString(), "")); - return new HashMap<>(); - } - return usersPerVersion; - } - -}