mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-03 15:08:02 +01:00
Add some custom charts to bStats.
Should give a good view of feature usage, especially some badly supported features like SQL and chest protection.
This commit is contained in:
parent
26477406f1
commit
2c14acc28c
@ -35,6 +35,7 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {
|
||||
@Unreported private ConcurrentMap<String, BukkitWorldConfiguration> worlds = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean hasCommandBookGodMode;
|
||||
boolean extraStats;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
@ -46,6 +47,16 @@ public BukkitConfigurationManager(WorldGuardPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Iterable<BukkitWorldConfiguration> 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();
|
||||
|
@ -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<String, Integer> 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
|
||||
|
@ -68,6 +68,7 @@ public abstract class AbstractSessionManager implements SessionManager {
|
||||
.build(CacheLoader.from(key ->
|
||||
createSession(key.playerRef.get())));
|
||||
|
||||
private boolean hasCustom = false;
|
||||
private List<Handler.Factory<? extends Handler>> handlers = new LinkedList<>();
|
||||
|
||||
private static final List<Handler.Factory<? extends Handler>> defaultHandlers = new LinkedList<>();
|
||||
@ -96,12 +97,17 @@ protected AbstractSessionManager() {
|
||||
handlers.addAll(defaultHandlers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean customHandlersRegistered() {
|
||||
return hasCustom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerHandler(Handler.Factory<? extends Handler> factory, @Nullable Handler.Factory<? extends Handler> 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 {
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user