Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 3 bar charts: addons, gamemodes, hooks #1790

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/main/java/world/bentobox/bentobox/BStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.SimpleBarChart;
import org.bstats.charts.SimplePie;
import org.bstats.charts.SingleLineChart;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -53,6 +54,11 @@ private void registerCustomMetrics() {
// Single Line charts
registerIslandsCountChart();
registerIslandsCreatedChart();

// Bar Charts
registerAddonsBarChart();
registerGameModeAddonsBarChart();
registerHooksBarChart();
}

private void registerDefaultLanguageChart() {
Expand Down Expand Up @@ -164,4 +170,44 @@ private void registerFlagsDisplayModeChart() {
return values;
}));
}

/**
* Sends the enabled addons (except GameModeAddons) of this server as bar chart.
* @since 1.17.1
*/
private void registerAddonsBarChart() {
metrics.addCustomChart(new SimpleBarChart("addonsBar", () -> {
Map<String, Integer> values = new HashMap<>();
plugin.getAddonsManager().getEnabledAddons().stream()
.filter(addon -> !(addon instanceof GameModeAddon) && addon.getDescription().isMetrics())
.forEach(addon -> values.put(addon.getDescription().getName(), 1));
return values;
}));
}

/**
* Sends the enabled GameModeAddons of this server as a bar chart.
* @since 1.17.1
*/
private void registerGameModeAddonsBarChart() {
metrics.addCustomChart(new SimpleBarChart("gameModeAddonsBar", () -> {
Map<String, Integer> values = new HashMap<>();
plugin.getAddonsManager().getGameModeAddons().stream()
.filter(gameModeAddon -> gameModeAddon.getDescription().isMetrics())
.forEach(gameModeAddon -> values.put(gameModeAddon.getDescription().getName(), 1));
return values;
}));
}

/**
* Sends the enabled Hooks of this server as a bar chart.
* @since 1.17.1
*/
private void registerHooksBarChart() {
metrics.addCustomChart(new SimpleBarChart("hooksBar", () -> {
Map<String, Integer> values = new HashMap<>();
plugin.getHooks().getHooks().forEach(hook -> values.put(hook.getPluginName(), 1));
return values;
}));
}
}