From 65bcabc1a55d29cf56a2f7fed7008b2b8bf83f9c Mon Sep 17 00:00:00 2001
From: Andre601 <11576465+Andre601@users.noreply.github.com>
Date: Mon, 15 Feb 2021 18:24:07 +0100
Subject: [PATCH] Version 3.2.0 - Add Metrics for bStats
---
bungeecord/pom.xml | 12 ++++-
.../bungeecord/BungeeCore.java | 41 +++++++++++++++++
.../core/OneVersionRemake.java | 4 ++
.../core/enums/ProtocolVersion.java | 2 +-
.../core/interfaces/PluginCore.java | 2 +
pom.xml | 2 +-
velocity/pom.xml | 12 +++++
.../velocity/VelocityCore.java | 45 ++++++++++++++++++-
8 files changed, 116 insertions(+), 4 deletions(-)
diff --git a/bungeecord/pom.xml b/bungeecord/pom.xml
index db48e83..8785c84 100644
--- a/bungeecord/pom.xml
+++ b/bungeecord/pom.xml
@@ -70,6 +70,12 @@
configurate-yaml
3.7.2
+
+ org.bstats
+ bstats-bungeecord
+ 2.2.1
+ compile
+
@@ -95,7 +101,11 @@
ninja.leaping.configurate
- com.andre601.oneversionremake.dependencies.configurate
+ com.andre601.oneversionremake.bungeecord.dependencies.configurate
+
+
+ org.bstats
+ com.andre601.oneversionremake.bungeecord.dependencies.bstats
diff --git a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java
index a02041c..70a1ef1 100644
--- a/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java
+++ b/bungeecord/src/main/java/com/andre601/oneversionremake/bungeecord/BungeeCore.java
@@ -23,14 +23,20 @@
import com.andre601.oneversionremake.bungeecord.listener.BungeePingListener;
import com.andre601.oneversionremake.bungeecord.logging.BungeeLogger;
import com.andre601.oneversionremake.core.OneVersionRemake;
+import com.andre601.oneversionremake.core.enums.ProtocolVersion;
import com.andre601.oneversionremake.core.enums.ProxyPlatform;
import com.andre601.oneversionremake.core.files.ConfigHandler;
import com.andre601.oneversionremake.core.interfaces.PluginCore;
import com.andre601.oneversionremake.core.interfaces.ProxyLogger;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.plugin.Plugin;
+import org.bstats.bungeecord.Metrics;
+import org.bstats.charts.DrilldownPie;
import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class BungeeCore extends Plugin implements PluginCore{
@@ -63,6 +69,39 @@ public void setConfigHandler(ConfigHandler configHandler){
this.configHandler = configHandler;
}
+ @Override
+ public void loadMetrics(){
+ Metrics metrics = new Metrics(this, 10340);
+
+ metrics.addCustomChart(new DrilldownPie("allowed_versions", () -> {
+ Map> map = new HashMap<>();
+ Map entry = new HashMap<>();
+
+ List protocolVersions = getConfigHandler().getIntList("Protocol", "Versions");
+ if(protocolVersions.isEmpty()){
+ String unknown = ProtocolVersion.getFriendlyName(0);
+ entry.put(unknown, 1);
+ map.put("other", entry);
+
+ return map;
+ }
+
+ for(int version : protocolVersions){
+ String major = ProtocolVersion.getMajor(version);
+ String name = ProtocolVersion.getFriendlyName(version);
+
+ entry.put(name, 1);
+ if(major.equalsIgnoreCase("?")){
+ map.put("other", entry);
+ }else{
+ map.put(major, entry);
+ }
+ }
+
+ return map;
+ }));
+ }
+
@Override
public boolean reloadConfig(){
return core.reloadConfig();
@@ -96,4 +135,6 @@ public ConfigHandler getConfigHandler(){
public String getVersion(){
return core.getVersion();
}
+
+ // 10340
}
diff --git a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java
index 8443bb5..05b4a35 100644
--- a/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java
+++ b/core/src/main/java/com/andre601/oneversionremake/core/OneVersionRemake.java
@@ -90,6 +90,10 @@ private void start(){
pluginCore.loadEventListeners();
logger.info("Event Listeners loaded!");
+ logger.info("Loading Metrics...");
+ pluginCore.loadMetrics();
+ logger.info("Metrics loaded!");
+
logger.info("OneVersionRemake is ready!");
}
diff --git a/core/src/main/java/com/andre601/oneversionremake/core/enums/ProtocolVersion.java b/core/src/main/java/com/andre601/oneversionremake/core/enums/ProtocolVersion.java
index 5ca9f0a..31e3b6b 100644
--- a/core/src/main/java/com/andre601/oneversionremake/core/enums/ProtocolVersion.java
+++ b/core/src/main/java/com/andre601/oneversionremake/core/enums/ProtocolVersion.java
@@ -88,7 +88,7 @@ public static String getFriendlyNames(List protocols, boolean majorOnly
.collect(Collectors.joining(", "));
}
- private static String getMajor(int protocol){
+ public static String getMajor(int protocol){
for(ProtocolVersion version : values()){
if(version.getProtocol() == protocol)
return version.getMajor();
diff --git a/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java b/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java
index fa53e69..21f2fcf 100644
--- a/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java
+++ b/core/src/main/java/com/andre601/oneversionremake/core/interfaces/PluginCore.java
@@ -31,6 +31,8 @@ public interface PluginCore{
void setConfigHandler(ConfigHandler configHandler);
+ void loadMetrics();
+
boolean reloadConfig();
Path getPath();
diff --git a/pom.xml b/pom.xml
index bb9ed05..7155558 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
UTF-8
- 3.1.1
+ 3.2.0
1.8
1.8
diff --git a/velocity/pom.xml b/velocity/pom.xml
index cbeaba3..c064b92 100644
--- a/velocity/pom.xml
+++ b/velocity/pom.xml
@@ -62,6 +62,12 @@
4.0.0-SNAPSHOT
compile
+
+ org.bstats
+ bstats-velocity
+ 2.2.1
+ compile
+
@@ -84,6 +90,12 @@
3.2.4
true
+
+
+ org.bstats
+ com.andre601.oneversionremake.velocity.dependencies.bstats
+
+
diff --git a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
index 5b951f0..af6482d 100644
--- a/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
+++ b/velocity/src/main/java/com/andre601/oneversionremake/velocity/VelocityCore.java
@@ -19,6 +19,7 @@
package com.andre601.oneversionremake.velocity;
import com.andre601.oneversionremake.core.OneVersionRemake;
+import com.andre601.oneversionremake.core.enums.ProtocolVersion;
import com.andre601.oneversionremake.core.enums.ProxyPlatform;
import com.andre601.oneversionremake.core.files.ConfigHandler;
import com.andre601.oneversionremake.core.interfaces.PluginCore;
@@ -33,9 +34,14 @@
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
+import org.bstats.charts.DrilldownPie;
+import org.bstats.velocity.Metrics;
import org.slf4j.LoggerFactory;
import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class VelocityCore implements PluginCore{
@@ -43,15 +49,19 @@ public class VelocityCore implements PluginCore{
private final ProxyServer proxy;
private final Path path;
+ private final Metrics.Factory factory;
+
private OneVersionRemake core;
private ConfigHandler configHandler = null;
@Inject
- public VelocityCore(ProxyServer proxy, @DataDirectory Path path){
+ public VelocityCore(ProxyServer proxy, @DataDirectory Path path, Metrics.Factory factory){
this.logger = new VelocityLogger(LoggerFactory.getLogger("OneVersionRemake"));
this.proxy = proxy;
this.path = path;
+
+ this.factory = factory;
}
@Subscribe
@@ -81,6 +91,39 @@ public void setConfigHandler(ConfigHandler configHandler){
this.configHandler = configHandler;
}
+ @Override
+ public void loadMetrics(){
+ Metrics metrics = factory.make(this, 10341);
+
+ metrics.addCustomChart(new DrilldownPie("allowed_versions", () -> {
+ Map> map = new HashMap<>();
+ Map entry = new HashMap<>();
+
+ List protocolVersions = getConfigHandler().getIntList("Protocol", "Versions");
+ if(protocolVersions.isEmpty()){
+ String unknown = ProtocolVersion.getFriendlyName(0);
+ entry.put(unknown, 1);
+ map.put("other", entry);
+
+ return map;
+ }
+
+ for(int version : protocolVersions){
+ String major = ProtocolVersion.getMajor(version);
+ String name = ProtocolVersion.getFriendlyName(version);
+
+ entry.put(name, 1);
+ if(major.equalsIgnoreCase("?")){
+ map.put("other", entry);
+ }else{
+ map.put(major, entry);
+ }
+ }
+
+ return map;
+ }));
+ }
+
@Override
public boolean reloadConfig(){
return core.reloadConfig();