mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-04 22:41:27 +01:00
Added islands created count metrics
Made BStats class public Added BentoBox#getMetrics()
This commit is contained in:
parent
7153378f5e
commit
755433e108
@ -5,11 +5,18 @@ import org.bstats.bukkit.Metrics;
|
||||
/**
|
||||
* @author Poslovitch
|
||||
*/
|
||||
class BStats {
|
||||
public class BStats {
|
||||
|
||||
private final BentoBox plugin;
|
||||
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) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -28,6 +35,7 @@ class BStats {
|
||||
|
||||
// Single Line charts
|
||||
registerIslandsCountChart();
|
||||
registerIslandsCreatedChart();
|
||||
}
|
||||
|
||||
private void registerDefaultLanguageChart() {
|
||||
@ -41,4 +49,23 @@ class BStats {
|
||||
private void registerIslandsCountChart() {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
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.events.BentoBoxReadyEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -57,6 +59,7 @@ public class BentoBox extends JavaPlugin {
|
||||
private SchemsManager schemsManager;
|
||||
private HooksManager hooksManager;
|
||||
private PlaceholdersManager placeholdersManager;
|
||||
private IslandDeletionManager islandDeletionManager;
|
||||
|
||||
// Settings
|
||||
private Settings settings;
|
||||
@ -68,7 +71,9 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
private boolean isLoaded;
|
||||
|
||||
private IslandDeletionManager islandDeletionManager;
|
||||
// Metrics
|
||||
@Nullable
|
||||
private BStats metrics;
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
@ -156,8 +161,8 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
// Load metrics
|
||||
if (settings.isMetrics()) {
|
||||
BStats bStats = new BStats(this);
|
||||
bStats.registerMetrics();
|
||||
metrics = new BStats(this);
|
||||
metrics.registerMetrics();
|
||||
}
|
||||
|
||||
// Load hooks
|
||||
@ -180,7 +185,6 @@ public class BentoBox extends JavaPlugin {
|
||||
// Fire plugin ready event - this should go last after everything else
|
||||
isLoaded = true;
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -367,8 +371,18 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* @return the islandDeletionManager
|
||||
* @since 1.1
|
||||
*/
|
||||
public IslandDeletionManager getIslandDeletionManager() {
|
||||
return islandDeletionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an optional of the Bstats instance
|
||||
* @since 1.1
|
||||
*/
|
||||
@NonNull
|
||||
public Optional<BStats> getMetrics() {
|
||||
return Optional.ofNullable(metrics);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import world.bentobox.bentobox.BStats;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
@ -221,7 +222,7 @@ public class NewIsland {
|
||||
}
|
||||
// Set default settings
|
||||
island.setFlagsDefaults();
|
||||
|
||||
plugin.getMetrics().ifPresent(BStats::increaseIslandsCreatedCount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user