Skip to content

Commit

Permalink
Version 3.2.0
Browse files Browse the repository at this point in the history
- Add Metrics for bStats
  • Loading branch information
Andre601 committed Feb 15, 2021
1 parent 183b920 commit 65bcabc
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 4 deletions.
12 changes: 11 additions & 1 deletion bungeecord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<artifactId>configurate-yaml</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -95,7 +101,11 @@
<relocations>
<relocation>
<pattern>ninja.leaping.configurate</pattern>
<shadedPattern>com.andre601.oneversionremake.dependencies.configurate</shadedPattern>
<shadedPattern>com.andre601.oneversionremake.bungeecord.dependencies.configurate</shadedPattern>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.andre601.oneversionremake.bungeecord.dependencies.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand Down Expand Up @@ -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<String, Map<String, Integer>> map = new HashMap<>();
Map<String, Integer> entry = new HashMap<>();

List<Integer> 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();
Expand Down Expand Up @@ -96,4 +135,6 @@ public ConfigHandler getConfigHandler(){
public String getVersion(){
return core.getVersion();
}

// 10340
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static String getFriendlyNames(List<Integer> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface PluginCore{

void setConfigHandler(ConfigHandler configHandler);

void loadMetrics();

boolean reloadConfig();

Path getPath();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.version>3.1.1</plugin.version>
<plugin.version>3.2.0</plugin.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Expand Down
12 changes: 12 additions & 0 deletions velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<version>4.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-velocity</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -84,6 +90,12 @@
<version>3.2.4</version>
<configuration>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.andre601.oneversionremake.velocity.dependencies.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,25 +34,34 @@
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{

private final ProxyLogger logger;
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
Expand Down Expand Up @@ -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<String, Map<String, Integer>> map = new HashMap<>();
Map<String, Integer> entry = new HashMap<>();

List<Integer> 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();
Expand Down

0 comments on commit 65bcabc

Please sign in to comment.