diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitConfigurationManager.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitConfigurationManager.java index fed6c4a8..9f54750b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitConfigurationManager.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitConfigurationManager.java @@ -35,6 +35,7 @@ public class BukkitConfigurationManager extends YamlConfigurationManager { @Unreported private ConcurrentMap worlds = new ConcurrentHashMap<>(); private boolean hasCommandBookGodMode; + boolean extraStats; /** * Construct the object. @@ -46,6 +47,16 @@ public BukkitConfigurationManager(WorldGuardPlugin plugin) { this.plugin = plugin; } + public Iterable getWorldConfigs() { + return worlds.values(); + } + + @Override + public void load() { + super.load(); + this.extraStats = getConfig().getBoolean("custom-metrics-charts", true); + } + @Override public File getDataFolder() { return plugin.getDataFolder(); diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index fbac9418..a2efa57b 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -20,6 +20,7 @@ package com.sk89q.worldguard.bukkit; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Streams; import com.sk89q.bukkit.util.CommandsManagerRegistration; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissionsException; @@ -35,6 +36,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.blacklist.Blacklist; import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent; import com.sk89q.worldguard.bukkit.listener.BlacklistListener; import com.sk89q.worldguard.bukkit.listener.BlockedPotionsListener; @@ -64,7 +66,12 @@ import com.sk89q.worldguard.commands.ProtectionCommands; import com.sk89q.worldguard.commands.ToggleCommands; import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.Flags; import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.managers.storage.RegionDriver; +import com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver; +import com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.util.logging.RecordMessagePrefixer; @@ -84,6 +91,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; import java.util.jar.JarFile; import java.util.logging.Logger; import java.util.zip.ZipEntry; @@ -205,7 +214,48 @@ public void onEnable() { ((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true); // Enable metrics - new Metrics(this); + final Metrics metrics = new Metrics(this); + if (metrics.isEnabled() && platform.getGlobalStateManager().extraStats) { + setupCustomCharts(metrics); + } + } + + private void setupCustomCharts(Metrics metrics) { + metrics.addCustomChart(new Metrics.SingleLineChart("region_count", () -> + platform.getRegionContainer().getLoaded().stream().mapToInt(RegionManager::size).sum())); + metrics.addCustomChart(new Metrics.SimplePie("region_driver", () -> { + RegionDriver driver = platform.getGlobalStateManager().selectedRegionStoreDriver; + return driver instanceof DirectoryYamlDriver ? "yaml" : driver instanceof SQLDriver ? "sql" : "unknown"; + })); + metrics.addCustomChart(new Metrics.SimpleBarChart("blacklist", () -> { + int unused = 0; + int standard = 0; + int whitelist = 0; + for (BukkitWorldConfiguration worldConfig : platform.getGlobalStateManager().getWorldConfigs()) { + Blacklist blacklist = worldConfig.getBlacklist(); + if (blacklist == null || blacklist.isEmpty()) { + unused++; + } else if (blacklist.isWhitelist()) { + whitelist++; + } else { + standard++; + } + } + Map blacklistCounts = new HashMap<>(); + blacklistCounts.put("unused", unused); + blacklistCounts.put("blacklist", standard); + blacklistCounts.put("whitelist", whitelist); + return blacklistCounts; + })); + metrics.addCustomChart(new Metrics.SimplePie("chest_protection", () -> + "" + Streams.stream(platform.getGlobalStateManager().getWorldConfigs()).anyMatch(cfg -> cfg.signChestProtection))); + metrics.addCustomChart(new Metrics.SimplePie("build_permissions", () -> + "" + Streams.stream(platform.getGlobalStateManager().getWorldConfigs()).anyMatch(cfg -> cfg.buildPermissions))); + + metrics.addCustomChart(new Metrics.SimplePie("custom_flags", () -> + "" + (WorldGuard.getInstance().getFlagRegistry().size() > Flags.INBUILT_FLAGS.size()))); + metrics.addCustomChart(new Metrics.SimplePie("custom_handlers", () -> + "" + (WorldGuard.getInstance().getPlatform().getSessionManager().customHandlersRegistered()))); } @Override diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java index 4838d731..99767904 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java @@ -68,6 +68,7 @@ public abstract class AbstractSessionManager implements SessionManager { .build(CacheLoader.from(key -> createSession(key.playerRef.get()))); + private boolean hasCustom = false; private List> handlers = new LinkedList<>(); private static final List> defaultHandlers = new LinkedList<>(); @@ -96,12 +97,17 @@ protected AbstractSessionManager() { handlers.addAll(defaultHandlers); } + @Override + public boolean customHandlersRegistered() { + return hasCustom; + } @Override public boolean registerHandler(Handler.Factory factory, @Nullable Handler.Factory after) { if (factory == null) return false; WorldGuard.logger.log(Level.INFO, "Registering session handler " + factory.getClass().getEnclosingClass().getName()); + hasCustom = true; if (after == null) { handlers.add(factory); } else { diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java b/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java index 4ffc80a5..bd34f7ec 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/session/SessionManager.java @@ -54,6 +54,11 @@ public interface SessionManager { */ void resetState(LocalPlayer player); + /** + * @return true if custom handlers are or were at some point registered, false otherwise + */ + boolean customHandlersRegistered(); + /** * Register a handler with the BukkitSessionManager. *