Last active
May 13, 2021 17:43
-
-
Save Bastian/b47279b4ff792153480b50ad0945c963 to your computer and use it in GitHub Desktop.
Advanced Pie example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onEnable() { | |
Metrics metrics = new Metrics(this); | |
metrics.addCustomChart(new AdvancedPie("most_famous_foods", new Callable<Map<String, Integer>>() { | |
@Override | |
public Map<String, Integer> call() throws Exception { | |
Map<String, Integer> valueMap = new HashMap<>(); | |
valueMap.put("Apple", getPlayersWithFood(Material.APPLE)); | |
valueMap.put("Bread", getPlayersWithFood(Material.BREAD)); | |
return valueMap; | |
} | |
private int getPlayersWithFood(Material food) { | |
int counter = 0; | |
for (Player player : Bukkit.getOnlinePlayers()) { | |
if (player.getInventory().contains(food)) { | |
counter++; | |
} | |
} | |
return counter; | |
} | |
})); | |
} | |
// If you use the Copy & Paste Metrics classes, use `Metrics.AdvancedPie` instead |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This could be simplified to my knowledge by using anonymous lambda (Or what you call those)
Example: