mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-17 17:21:00 +02:00
ViaVersion Data
This commit is contained in:
parent
87377b2586
commit
91c2a3850a
@ -50,7 +50,7 @@ public class Protocol {
|
||||
case 4:
|
||||
return "1.7.5";
|
||||
default:
|
||||
return "Unknown ProtocolVersion: " + protocolVersion;
|
||||
return "Unknown (" + protocolVersion + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
|
||||
Map<UUID, Integer> versions;
|
||||
|
||||
try {
|
||||
versions = table.getProtocolVersions();
|
||||
} catch (SQLException ex) {
|
||||
Log.toLog(this.getClass().getName(), ex);
|
||||
return analysisContainer;
|
||||
}
|
||||
|
||||
Map<UUID, String> 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<String, Integer> usersPerVersion = getUsersPerVersion(versions);
|
||||
for (Map.Entry<String, Integer> entry : usersPerVersion.entrySet()) {
|
||||
versionTable.addRow(entry.getKey(), entry.getValue());
|
||||
}
|
||||
analysisContainer.addTable("versionTable", versionTable);
|
||||
|
||||
return analysisContainer;
|
||||
}
|
||||
|
||||
private Map<String, Integer> getUsersPerVersion(Map<UUID, Integer> versions) {
|
||||
Map<String, Integer> 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;
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String, Integer> 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<String, Integer> getUsersPerVersion(StringBuilder html) {
|
||||
Map<String, Integer> usersPerVersion = new HashMap<>();
|
||||
try {
|
||||
Map<UUID, Integer> 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user