Skip to content

Commit

Permalink
Move creation of DrilldownPie to core
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Mar 14, 2021
1 parent 7d5fa78 commit 8cd418b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@
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;
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 @@ -67,37 +62,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(core.getPie());
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-base</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import com.andre601.oneversionremake.core.files.ConfigHandler;
import com.andre601.oneversionremake.core.interfaces.PluginCore;
import com.andre601.oneversionremake.core.interfaces.ProxyLogger;
import org.bstats.charts.DrilldownPie;

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 +68,39 @@ public CommandHandler getCommandHandler(){
return commandHandler;
}

public DrilldownPie getPie(){
return new DrilldownPie("allowed_protocols", () -> {
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 @@ -88,38 +88,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(core.getPie());
}

@Override
Expand Down

0 comments on commit 8cd418b

Please sign in to comment.