Skip to content

Commit

Permalink
Merge pull request #39 from Andre601/feature/move-drilldownpie-method
Browse files Browse the repository at this point in the history
Make a getPie() method for DrilldownPie Charts
  • Loading branch information
Andre601 authored Mar 16, 2021
2 parents d81e830 + 3eb9226 commit 60834f1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.andre601.oneversionremake.bungeecord.logging.BungeeLogger;
import com.andre601.oneversionremake.core.OneVersionRemake;
import com.andre601.oneversionremake.core.commands.CommandHandler;
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 @@ -35,9 +34,6 @@
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 @@ -67,37 +63,7 @@ public void loadEventListeners(){
public void loadMetrics(){
Metrics metrics = new Metrics(this, 10340);

metrics.addCustomChart(new DrilldownPie("allowed_versions", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();

List<Integer> protocolVersions = getConfigHandler().getIntList("Protocol", "Versions");
if(protocolVersions.isEmpty()){
String unknown = ProtocolVersion.getFriendlyName(0);

Map<String, Integer> entry = new HashMap<>();

entry.put(unknown, 1);
map.put("other", entry);

return map;
}

for(int version : protocolVersions){
String major = ProtocolVersion.getMajor(version);
String name = ProtocolVersion.getFriendlyName(version);

Map<String, Integer> entry = new HashMap<>();

entry.put(name, 1);
if(major.equalsIgnoreCase("?")){
map.put("other", entry);
}else{
map.put(major, entry);
}
}

return map;
}));
metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public class OneVersionRemake{
Expand Down Expand Up @@ -65,6 +67,38 @@ public CommandHandler getCommandHandler(){
return commandHandler;
}

public Map<String, Map<String, Integer>> getPieMap(){
Map<String, Map<String, Integer>> map = new HashMap<>();

List<Integer> versions = getConfigHandler().getIntList("Protocol", "Versions");
if(versions.isEmpty()){
String unknown = ProtocolVersion.getFriendlyName(0);

Map<String, Integer> entry = new HashMap<>();

entry.put(unknown, 1);
map.put("other", entry);

return map;
}

for(int version : versions){
String major = ProtocolVersion.getMajor(version);
String name = ProtocolVersion.getFriendlyName(version);

Map<String, Integer> entry = new HashMap<>();
entry.put(name, 1);

if(major.equalsIgnoreCase("?")){
map.put("other", entry);
}else{
map.put(major, entry);
}
}

return map;
}

private void start(){
loadVersion();
printBanner();
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.3.0</plugin.version>
<plugin.version>3.3.1</plugin.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.andre601.oneversionremake.core.OneVersionRemake;
import com.andre601.oneversionremake.core.commands.CommandHandler;
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 @@ -40,9 +39,6 @@
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{

Expand Down Expand Up @@ -88,38 +84,8 @@ public void loadEventListeners(){
@Override
public void loadMetrics(){
Metrics metrics = factory.make(this, 10341);

metrics.addCustomChart(new DrilldownPie("allowed_versions", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();

List<Integer> protocolVersions = getConfigHandler().getIntList("Protocol", "Versions");
if(protocolVersions.isEmpty()){
String unknown = ProtocolVersion.getFriendlyName(0);

Map<String, Integer> entry = new HashMap<>();

entry.put(unknown, 1);
map.put("other", entry);

return map;
}

for(int version : protocolVersions){
String major = ProtocolVersion.getMajor(version);
String name = ProtocolVersion.getFriendlyName(version);

Map<String, Integer> entry = new HashMap<>();

entry.put(name, 1);
if(major.equalsIgnoreCase("?")){
map.put("other", entry);
}else{
map.put(major, entry);
}
}

return map;
}));

metrics.addCustomChart(new DrilldownPie("allowed_protocols", () -> core.getPieMap()));
}

@Override
Expand Down

0 comments on commit 60834f1

Please sign in to comment.