mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-07-07 12:04:45 +02:00
ProtocolSupport Support #230
This commit is contained in:
parent
580daf9796
commit
0dc3e134b4
|
@ -111,6 +111,36 @@
|
|||
<version>1.1.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.kingdoms</groupId>
|
||||
<artifactId>kingdoms_demo</artifactId>
|
||||
<version>13.3.40</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.confuser</groupId>
|
||||
<artifactId>banmanager</artifactId>
|
||||
<version>5.15.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.github.MCE-Plugins</groupId>-->
|
||||
<!--<artifactId>MinigamesLib-parent</artifactId>-->
|
||||
<!--<version>1.14.18</version>-->
|
||||
<!--<scope>provided</scope>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.github.ProtocolSupport</groupId>
|
||||
<artifactId>ProtocolSupport</artifactId>
|
||||
<version>4.28</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12.RedProtect</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.djrapitops.pluginbridge.plan.griefprevention.GriefPreventionHook;
|
|||
import com.djrapitops.pluginbridge.plan.jobs.JobsHook;
|
||||
import com.djrapitops.pluginbridge.plan.litebans.LiteBansHook;
|
||||
import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook;
|
||||
import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook;
|
||||
import com.djrapitops.pluginbridge.plan.superbvote.SuperbVoteHook;
|
||||
import com.djrapitops.pluginbridge.plan.towny.TownyHook;
|
||||
import com.djrapitops.pluginbridge.plan.vault.VaultHook;
|
||||
|
@ -26,6 +27,7 @@ import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
|||
* @see LiteBansHook
|
||||
* @see McmmoHook
|
||||
* @see SuperbVoteHook
|
||||
* @see ProtocolSupportHook
|
||||
* @see TownyHook
|
||||
* @see VaultHook
|
||||
* @see ViaVersionHook
|
||||
|
@ -48,6 +50,7 @@ public class Bridge {
|
|||
new LiteBansHook(h),
|
||||
new McmmoHook(h),
|
||||
new SuperbVoteHook(h),
|
||||
new ProtocolSupportHook(h),
|
||||
new TownyHook(h),
|
||||
new VaultHook(h),
|
||||
new ViaVersionHook(h)
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.protocolsupport;
|
||||
|
||||
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
import main.java.com.djrapitops.plan.systems.processing.Processor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
import protocolsupport.api.ProtocolVersion;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Class responsible for listening join events for Version protocol.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public class PlayerVersionListener implements Listener {
|
||||
|
||||
public PlayerVersionListener() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
ProtocolVersion protocolVersion = ProtocolSupportAPI.getProtocolVersion(player);
|
||||
int playerVersion = protocolVersion.getId();
|
||||
Plan plan = Plan.getInstance();
|
||||
plan.addToProcessQueue(new Processor<UUID>(uuid) {
|
||||
@Override
|
||||
public void process() {
|
||||
try {
|
||||
new ProtocolTable((SQLDB) plan.getDB()).saveProtocolVersion(uuid, playerVersion);
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName() + ":PlanViaVersionJoinListener", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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.protocolsupport;
|
||||
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.Protocol;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
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 ProtocolSupport plugin.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ProtocolSupportData extends PluginData {
|
||||
|
||||
private final ProtocolTable table;
|
||||
|
||||
public ProtocolSupportData(ProtocolTable table) {
|
||||
super(ContainerSize.THIRD, "ProtocolSupport");
|
||||
super.setPluginIcon("gamepad");
|
||||
super.setIconColor("cyan");
|
||||
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("cyan");
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.protocolsupport;
|
||||
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import com.djrapitops.pluginbridge.plan.viaversion.ProtocolTable;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||
|
||||
/**
|
||||
* Hook for ProtocolSupport plugin.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ProtocolSupportHook extends Hook {
|
||||
|
||||
private static PlayerVersionListener listener;
|
||||
|
||||
public ProtocolSupportHook(HookHandler hookHandler) {
|
||||
super("protocolsupport.ProtocolSupport", hookHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hook() throws NoClassDefFoundError {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
Plan plan = Plan.getInstance();
|
||||
ProtocolTable table = new ProtocolTable((SQLDB) plan.getDB());
|
||||
try {
|
||||
table.createTable();
|
||||
} catch (DBCreateTableException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
return;
|
||||
}
|
||||
if (listener == null) {
|
||||
listener = new PlayerVersionListener();
|
||||
plan.registerListener(listener);
|
||||
}
|
||||
addPluginDataSource(new ProtocolSupportData(table));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user