Added islands created count metrics

Made BStats class public
Added BentoBox#getMetrics()
This commit is contained in:
Florian CUNY 2019-01-18 15:12:06 +01:00
parent 7153378f5e
commit 755433e108
3 changed files with 48 additions and 6 deletions

View File

@ -5,11 +5,18 @@ import org.bstats.bukkit.Metrics;
/** /**
* @author Poslovitch * @author Poslovitch
*/ */
class BStats { public class BStats {
private final BentoBox plugin; private final BentoBox plugin;
private Metrics metrics; private Metrics metrics;
/**
* Counts of the islands that got created.
* It is reset to 0 when BStats gets the data.
* @since 1.1
*/
private int islandsCreatedCount = 0;
BStats(BentoBox plugin) { BStats(BentoBox plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@ -28,6 +35,7 @@ class BStats {
// Single Line charts // Single Line charts
registerIslandsCountChart(); registerIslandsCountChart();
registerIslandsCreatedChart();
} }
private void registerDefaultLanguageChart() { private void registerDefaultLanguageChart() {
@ -41,4 +49,23 @@ class BStats {
private void registerIslandsCountChart() { private void registerIslandsCountChart() {
metrics.addCustomChart(new Metrics.SingleLineChart("islands", () -> plugin.getIslands().getIslandCount())); metrics.addCustomChart(new Metrics.SingleLineChart("islands", () -> plugin.getIslands().getIslandCount()));
} }
/**
* @since 1.1
*/
private void registerIslandsCreatedChart() {
metrics.addCustomChart(new Metrics.SingleLineChart("islandsCreated", () -> {
int value = islandsCreatedCount;
islandsCreatedCount = 0;
return value;
}));
}
/**
* Increases the count of islands that got create since the last "data get" request from BStats.
* @since 1.1
*/
public void increaseIslandsCreatedCount() {
islandsCreatedCount++;
}
} }

View File

@ -6,6 +6,8 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
@ -57,6 +59,7 @@ public class BentoBox extends JavaPlugin {
private SchemsManager schemsManager; private SchemsManager schemsManager;
private HooksManager hooksManager; private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager; private PlaceholdersManager placeholdersManager;
private IslandDeletionManager islandDeletionManager;
// Settings // Settings
private Settings settings; private Settings settings;
@ -68,7 +71,9 @@ public class BentoBox extends JavaPlugin {
private boolean isLoaded; private boolean isLoaded;
private IslandDeletionManager islandDeletionManager; // Metrics
@Nullable
private BStats metrics;
@Override @Override
public void onEnable(){ public void onEnable(){
@ -156,8 +161,8 @@ public class BentoBox extends JavaPlugin {
// Load metrics // Load metrics
if (settings.isMetrics()) { if (settings.isMetrics()) {
BStats bStats = new BStats(this); metrics = new BStats(this);
bStats.registerMetrics(); metrics.registerMetrics();
} }
// Load hooks // Load hooks
@ -180,7 +185,6 @@ public class BentoBox extends JavaPlugin {
// Fire plugin ready event - this should go last after everything else // Fire plugin ready event - this should go last after everything else
isLoaded = true; isLoaded = true;
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent()); Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
}); });
} }
@ -367,8 +371,18 @@ public class BentoBox extends JavaPlugin {
/** /**
* @return the islandDeletionManager * @return the islandDeletionManager
* @since 1.1
*/ */
public IslandDeletionManager getIslandDeletionManager() { public IslandDeletionManager getIslandDeletionManager() {
return islandDeletionManager; return islandDeletionManager;
} }
/**
* @return an optional of the Bstats instance
* @since 1.1
*/
@NonNull
public Optional<BStats> getMetrics() {
return Optional.ofNullable(metrics);
}
} }

View File

@ -11,6 +11,7 @@ import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import world.bentobox.bentobox.BStats;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent; import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -221,7 +222,7 @@ public class NewIsland {
} }
// Set default settings // Set default settings
island.setFlagsDefaults(); island.setFlagsDefaults();
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
} }
/** /**