PluginBridge R0.5: Removed Protocol enum

Special thanks to @Vankka !
This commit is contained in:
Rsl1122 2019-06-22 09:50:37 +03:00
parent ec1ace0419
commit 2e66ab1676
5 changed files with 42 additions and 106 deletions

View File

@ -47,7 +47,7 @@ subprojects {
ext.daggerCompilerVersion = "2.23.2"
ext.abstractPluginFrameworkVersion = "3.4.1"
ext.planPluginBridgeVersion = "4.8.2-R0.4"
ext.planPluginBridgeVersion = "4.8.2-R0.5"
ext.bukkitVersion = "1.12.2-R0.1-SNAPSHOT"
ext.spigotVersion = "1.12.2-R0.1-SNAPSHOT"

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.djrapitops</groupId>
<artifactId>PlanPluginBridge</artifactId>
<version>4.8.2-R0.4</version>
<version>4.8.2-R0.5</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>

View File

@ -25,8 +25,8 @@ import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.utilities.html.icon.Color;
import com.djrapitops.plan.utilities.html.icon.Icon;
import com.djrapitops.pluginbridge.plan.viaversion.Protocol;
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
import protocolsupport.api.ProtocolVersion;
import java.util.Collection;
import java.util.HashMap;
@ -55,7 +55,7 @@ class ProtocolSupportData extends PluginData {
int protocolVersion = database.query(ProtocolTable.getProtocolVersion(uuid));
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.CYAN)),
protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known");
getProtocolVersionString(protocolVersion));
} catch (DBOpException ex) {
inspectContainer.addValue("Error", ex.toString());
}
@ -63,6 +63,23 @@ class ProtocolSupportData extends PluginData {
return inspectContainer;
}
private String getProtocolVersionString(int number) {
if (number == -1) {
return "Not Yet Known";
}
ProtocolVersion[] versions = ProtocolVersion.getAllSupported();
for (ProtocolVersion version : versions) {
if (version.getId() == number) {
String name = version.getName();
if (name == null) {
break; // Unknown name for the version
}
return name;
}
}
return "Unknown (" + number + ')';
}
@Override
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
Map<UUID, Integer> versions;
@ -75,7 +92,7 @@ class ProtocolSupportData extends PluginData {
}
Map<UUID, String> userVersions = versions.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Protocol.getMCVersion(entry.getValue())));
.collect(Collectors.toMap(Map.Entry::getKey, entry -> getProtocolVersionString(entry.getValue())));
analysisContainer.addPlayerTableValues(getWithIcon("Last Version", Icon.called("signal")), userVersions);
@ -83,7 +100,7 @@ class ProtocolSupportData extends PluginData {
String membersS = getWithIcon("Users", Icon.called("users"));
TableContainer versionTable = new TableContainer(versionS, membersS);
versionTable.setColor("cyan");
Map<String, Integer> usersPerVersion = getUsersPerVersion(versions);
Map<String, Integer> usersPerVersion = getUsersPerVersion(userVersions);
for (Map.Entry<String, Integer> entry : usersPerVersion.entrySet()) {
versionTable.addRow(entry.getKey(), entry.getValue());
}
@ -92,15 +109,14 @@ class ProtocolSupportData extends PluginData {
return analysisContainer;
}
private Map<String, Integer> getUsersPerVersion(Map<UUID, Integer> versions) {
private Map<String, Integer> getUsersPerVersion(Map<UUID, String> userVersions) {
Map<String, Integer> usersPerVersion = new HashMap<>();
for (int protocolVersion : versions.values()) {
String mcVer = Protocol.getMCVersion(protocolVersion);
if (!usersPerVersion.containsKey(mcVer)) {
usersPerVersion.put(mcVer, 0);
for (String version : userVersions.values()) {
if (!usersPerVersion.containsKey(version)) {
usersPerVersion.put(version, 0);
}
usersPerVersion.replace(mcVer, usersPerVersion.get(mcVer) + 1);
usersPerVersion.replace(version, usersPerVersion.get(version) + 1);
}
return usersPerVersion;
}

View File

@ -1,84 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.pluginbridge.plan.viaversion;
/**
* Contains static method for formatting protocol version into readable form.
*
* @author Rsl1122
*/
public class Protocol {
private Protocol() {
throw new IllegalStateException("Utility class");
}
/**
* http://wiki.vg/Protocol_version_numbers
*
* @param protocolVersion ProtocolVersion
* @return Minecraft Version (estimate)
*/
public static String getMCVersion(int protocolVersion) {
switch (protocolVersion) {
case 492:
case 491:
case 490:
case 489:
return "1.14.3";
case 485:
return "1.14.2";
case 480:
return "1.14.1";
case 477:
return "1.14";
case 404:
return "1.13.2";
case 401:
return "1.13.1";
case 393:
return "1.13";
case 340:
return "1.12.2";
case 338:
return "1.12.1";
case 335:
return "1.12";
case 316:
return "1.11.2";
case 315:
return "1.11";
case 210:
return "1.10.2";
case 110:
return "1.9.4";
case 109:
return "1.9.2";
case 107:
return "1.9";
case 47:
return "1.8.9";
case 5:
return "1.7.10";
case 4:
return "1.7.5";
default:
return "Newer than 1.14.2 (" + protocolVersion + ")";
}
}
}

View File

@ -25,6 +25,7 @@ import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.utilities.html.icon.Color;
import com.djrapitops.plan.utilities.html.icon.Icon;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import java.util.Collection;
import java.util.HashMap;
@ -50,10 +51,10 @@ class ViaVersionData extends PluginData {
@Override
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) {
try {
int protocolVersion = database.query(ProtocolTable.getProtocolVersion(uuid));
int version = database.query(ProtocolTable.getProtocolVersion(uuid));
inspectContainer.addValue(getWithIcon("Last Join Version", Icon.called("signal").of(Color.LIGHT_GREEN)),
protocolVersion != -1 ? Protocol.getMCVersion(protocolVersion) : "Not Yet Known");
getProtocolVersionString(version));
} catch (DBOpException ex) {
inspectContainer.addValue("Error", ex.toString());
}
@ -61,6 +62,10 @@ class ViaVersionData extends PluginData {
return inspectContainer;
}
private String getProtocolVersionString(int version) {
return version != -1 ? ProtocolVersion.getProtocol(version).getName() : "Not Yet Known";
}
@Override
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) {
Map<UUID, Integer> versions;
@ -73,7 +78,7 @@ class ViaVersionData extends PluginData {
}
Map<UUID, String> userVersions = versions.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Protocol.getMCVersion(entry.getValue())));
.collect(Collectors.toMap(Map.Entry::getKey, entry -> getProtocolVersionString(entry.getValue())));
analysisContainer.addPlayerTableValues(getWithIcon("Last Version", Icon.called("signal")), userVersions);
@ -81,7 +86,7 @@ class ViaVersionData extends PluginData {
String membersS = getWithIcon("Users", Icon.called("users"));
TableContainer versionTable = new TableContainer(versionS, membersS);
versionTable.setColor("light-green");
Map<String, Integer> usersPerVersion = getUsersPerVersion(versions);
Map<String, Integer> usersPerVersion = getUsersPerVersion(userVersions);
for (Map.Entry<String, Integer> entry : usersPerVersion.entrySet()) {
versionTable.addRow(entry.getKey(), entry.getValue());
}
@ -90,15 +95,14 @@ class ViaVersionData extends PluginData {
return analysisContainer;
}
private Map<String, Integer> getUsersPerVersion(Map<UUID, Integer> versions) {
private Map<String, Integer> getUsersPerVersion(Map<UUID, String> userVersions) {
Map<String, Integer> usersPerVersion = new HashMap<>();
for (int protocolVersion : versions.values()) {
String mcVer = Protocol.getMCVersion(protocolVersion);
if (!usersPerVersion.containsKey(mcVer)) {
usersPerVersion.put(mcVer, 0);
for (String version : userVersions.values()) {
if (!usersPerVersion.containsKey(version)) {
usersPerVersion.put(version, 0);
}
usersPerVersion.replace(mcVer, usersPerVersion.get(mcVer) + 1);
usersPerVersion.replace(version, usersPerVersion.get(version) + 1);
}
return usersPerVersion;
}