Skip to content

Commit

Permalink
Change code to instead just return custom HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Mar 16, 2021
1 parent b555059 commit 3eb9226
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;

Expand Down Expand Up @@ -62,7 +63,7 @@ public void loadEventListeners(){
public void loadMetrics(){
Metrics metrics = new Metrics(this, 10340);

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

@Override
Expand Down
6 changes: 0 additions & 6 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
<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,7 +23,6 @@
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;
Expand Down Expand Up @@ -68,37 +67,36 @@ public CommandHandler getCommandHandler(){
return commandHandler;
}

public DrilldownPie getPie(){
return new DrilldownPie("allowed_protocols", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
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);

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;
}
Map<String, Integer> entry = new HashMap<>();

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);
}
}
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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;

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

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

@Override
Expand Down

0 comments on commit 3eb9226

Please sign in to comment.