Search in sources :

Example 1 with SQLDriver

use of com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver in project WorldGuard by EngineHub.

the class WorldGuardPlugin method setupCustomCharts.

private void setupCustomCharts(Metrics metrics) {
    metrics.addCustomChart(new SingleLineChart("region_count", () -> platform.getRegionContainer().getLoaded().stream().mapToInt(RegionManager::size).sum()));
    metrics.addCustomChart(new SimplePie("region_driver", () -> {
        RegionDriver driver = platform.getGlobalStateManager().selectedRegionStoreDriver;
        return driver instanceof DirectoryYamlDriver ? "yaml" : driver instanceof SQLDriver ? "sql" : "unknown";
    }));
    metrics.addCustomChart(new DrilldownPie("blacklist", () -> {
        int empty = 0;
        Map<String, Integer> blacklistMap = new HashMap<>();
        Map<String, Integer> whitelistMap = new HashMap<>();
        for (BukkitWorldConfiguration worldConfig : platform.getGlobalStateManager().getWorldConfigs()) {
            Blacklist blacklist = worldConfig.getBlacklist();
            if (blacklist != null && !blacklist.isEmpty()) {
                Map<String, Integer> target = blacklist.isWhitelist() ? whitelistMap : blacklistMap;
                int floor = ((blacklist.getItemCount() - 1) / 10) * 10;
                String range = floor >= 100 ? "101+" : (floor + 1) + " - " + (floor + 10);
                target.merge(range, 1, Integer::sum);
            } else {
                empty++;
            }
        }
        Map<String, Map<String, Integer>> blacklistCounts = new HashMap<>();
        Map<String, Integer> emptyMap = new HashMap<>();
        emptyMap.put("empty", empty);
        blacklistCounts.put("empty", emptyMap);
        blacklistCounts.put("blacklist", blacklistMap);
        blacklistCounts.put("whitelist", whitelistMap);
        return blacklistCounts;
    }));
    metrics.addCustomChart(new SimplePie("chest_protection", () -> "" + platform.getGlobalStateManager().getWorldConfigs().stream().anyMatch(cfg -> cfg.signChestProtection)));
    metrics.addCustomChart(new SimplePie("build_permissions", () -> "" + platform.getGlobalStateManager().getWorldConfigs().stream().anyMatch(cfg -> cfg.buildPermissions)));
    metrics.addCustomChart(new SimplePie("custom_flags", () -> "" + (WorldGuard.getInstance().getFlagRegistry().size() > Flags.INBUILT_FLAGS.size())));
    metrics.addCustomChart(new SimplePie("custom_handlers", () -> "" + (WorldGuard.getInstance().getPlatform().getSessionManager().customHandlersRegistered())));
}
Also used : CommandsManagerRegistration(com.sk89q.bukkit.util.CommandsManagerRegistration) Plugin(org.bukkit.plugin.Plugin) ProtectionCommands(com.sk89q.worldguard.commands.ProtectionCommands) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GeneralCommands(com.sk89q.worldguard.commands.GeneralCommands) PlayerModesListener(com.sk89q.worldguard.bukkit.listener.PlayerModesListener) Player(org.bukkit.entity.Player) SimplePie(org.bstats.charts.SimplePie) WorldRulesListener(com.sk89q.worldguard.bukkit.listener.WorldRulesListener) ProcessPlayerEvent(com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent) WorldGuardBlockListener(com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener) World(org.bukkit.World) WorldGuard(com.sk89q.worldguard.WorldGuard) Map(java.util.Map) PermissionsResolverManager(com.sk89q.wepif.PermissionsResolverManager) WorldGuardPlayerListener(com.sk89q.worldguard.bukkit.listener.WorldGuardPlayerListener) ClassSourceValidator(com.sk89q.worldguard.bukkit.util.ClassSourceValidator) Bukkit(org.bukkit.Bukkit) RecordMessagePrefixer(com.sk89q.worldguard.util.logging.RecordMessagePrefixer) CommandSender(org.bukkit.command.CommandSender) DebuggingListener(com.sk89q.worldguard.bukkit.listener.DebuggingListener) SimpleFlagRegistry(com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) BlockedPotionsListener(com.sk89q.worldguard.bukkit.listener.BlockedPotionsListener) Flags(com.sk89q.worldguard.protection.flags.Flags) SQLDriver(com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver) Events(com.sk89q.worldguard.bukkit.util.Events) Metrics(org.bstats.bukkit.Metrics) SingleLineChart(org.bstats.charts.SingleLineChart) Logger(java.util.logging.Logger) FileNotFoundException(java.io.FileNotFoundException) SimpleInjector(com.sk89q.minecraft.util.commands.SimpleInjector) BuildPermissionListener(com.sk89q.worldguard.bukkit.listener.BuildPermissionListener) OfflinePlayer(org.bukkit.OfflinePlayer) RegionProtectionListener(com.sk89q.worldguard.bukkit.listener.RegionProtectionListener) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) WorldEditPlugin(com.sk89q.worldedit.bukkit.WorldEditPlugin) WorldGuardWeatherListener(com.sk89q.worldguard.bukkit.listener.WorldGuardWeatherListener) RegionFlagsListener(com.sk89q.worldguard.bukkit.listener.RegionFlagsListener) WorldGuardHangingListener(com.sk89q.worldguard.bukkit.listener.WorldGuardHangingListener) BukkitAdapter(com.sk89q.worldedit.bukkit.BukkitAdapter) ToggleCommands(com.sk89q.worldguard.commands.ToggleCommands) Command(org.bukkit.command.Command) WorldGuardVehicleListener(com.sk89q.worldguard.bukkit.listener.WorldGuardVehicleListener) ChestProtectionListener(com.sk89q.worldguard.bukkit.listener.ChestProtectionListener) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) WorldGuardWorldListener(com.sk89q.worldguard.bukkit.listener.WorldGuardWorldListener) HashMap(java.util.HashMap) BukkitCommandSender(com.sk89q.worldedit.bukkit.BukkitCommandSender) Level(java.util.logging.Level) CommandException(com.sk89q.minecraft.util.commands.CommandException) ImmutableList(com.google.common.collect.ImmutableList) DrilldownPie(org.bstats.charts.DrilldownPie) WorldGuardServerListener(com.sk89q.worldguard.bukkit.listener.WorldGuardServerListener) WrappedCommandException(com.sk89q.minecraft.util.commands.WrappedCommandException) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) BukkitSessionManager(com.sk89q.worldguard.bukkit.session.BukkitSessionManager) DirectoryYamlDriver(com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver) InvincibilityListener(com.sk89q.worldguard.bukkit.listener.InvincibilityListener) BlacklistListener(com.sk89q.worldguard.bukkit.listener.BlacklistListener) FileOutputStream(java.io.FileOutputStream) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Flag(com.sk89q.worldguard.protection.flags.Flag) IOException(java.io.IOException) EventAbstractionListener(com.sk89q.worldguard.bukkit.listener.EventAbstractionListener) WorldGuardEntityListener(com.sk89q.worldguard.bukkit.listener.WorldGuardEntityListener) File(java.io.File) MissingNestedCommandException(com.sk89q.minecraft.util.commands.MissingNestedCommandException) Actor(com.sk89q.worldedit.extension.platform.Actor) PlayerMoveListener(com.sk89q.worldguard.bukkit.listener.PlayerMoveListener) WorldGuardCommandBookListener(com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener) CommandUsageException(com.sk89q.minecraft.util.commands.CommandUsageException) ChatColor(org.bukkit.ChatColor) CommandsManager(com.sk89q.minecraft.util.commands.CommandsManager) Blacklist(com.sk89q.worldguard.blacklist.Blacklist) InputStream(java.io.InputStream) DirectoryYamlDriver(com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver) SingleLineChart(org.bstats.charts.SingleLineChart) SimplePie(org.bstats.charts.SimplePie) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) DrilldownPie(org.bstats.charts.DrilldownPie) Blacklist(com.sk89q.worldguard.blacklist.Blacklist) SQLDriver(com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with SQLDriver

use of com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver in project WorldGuard by EngineHub.

the class YamlConfigurationManager method load.

@Override
public void load() {
    copyDefaults();
    config = new YAMLProcessor(new File(getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
    try {
        config.load();
    } catch (IOException e) {
        log.severe("Error reading configuration for global config: ");
        e.printStackTrace();
    }
    config.removeProperty("suppress-tick-sync-warnings");
    migrateRegionsToUuid = config.getBoolean("regions.uuid-migration.perform-on-next-start", true);
    keepUnresolvedNames = config.getBoolean("regions.uuid-migration.keep-names-that-lack-uuids", true);
    useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
    disableDefaultBypass = config.getBoolean("regions.disable-bypass-by-default", false);
    announceBypassStatus = config.getBoolean("regions.announce-bypass-status", false);
    useGodPermission = config.getBoolean("auto-invincible", config.getBoolean("auto-invincible-permission", false));
    useGodGroup = config.getBoolean("auto-invincible-group", false);
    useAmphibiousGroup = config.getBoolean("auto-no-drowning-group", false);
    config.removeProperty("auto-invincible-permission");
    usePlayerMove = config.getBoolean("use-player-move-event", true);
    usePlayerTeleports = config.getBoolean("use-player-teleports", true);
    particleEffects = config.getBoolean("use-particle-effects", true);
    disablePermissionCache = config.getBoolean("disable-permission-cache", false);
    deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
    blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);
    hostKeys = new HashMap<>();
    Object hostKeysRaw = config.getProperty("host-keys");
    if (!(hostKeysRaw instanceof Map)) {
        config.setProperty("host-keys", new HashMap<String, String>());
    } else {
        for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
            String key = String.valueOf(entry.getKey());
            String value = String.valueOf(entry.getValue());
            hostKeys.put(key.toLowerCase(), value);
        }
    }
    hostKeysAllowFMLClients = config.getBoolean("security.host-keys-allow-forge-clients", false);
    // ====================================================================
    // Region store drivers
    // ====================================================================
    boolean useSqlDatabase = config.getBoolean("regions.sql.use", false);
    String sqlDsn = config.getString("regions.sql.dsn", "jdbc:mysql://localhost/worldguard");
    String sqlUsername = config.getString("regions.sql.username", "worldguard");
    String sqlPassword = config.getString("regions.sql.password", "worldguard");
    String sqlTablePrefix = config.getString("regions.sql.table-prefix", "");
    if (!useSqlDatabase) {
        config.removeProperty("regions.sql");
    } else {
        log.warning("SQL support for WorldGuard region storage is deprecated for removal in a future version. Please migrate to YAML storage.");
        log.warning("For details, see https://worldguard.enginehub.org/en/latest/regions/storage/");
    }
    DataSourceConfig dataSourceConfig = new DataSourceConfig(sqlDsn, sqlUsername, sqlPassword, sqlTablePrefix);
    SQLDriver sqlDriver = new SQLDriver(dataSourceConfig);
    DirectoryYamlDriver yamlDriver = new DirectoryYamlDriver(getWorldsDataFolder(), "regions.yml");
    this.regionStoreDriverMap = ImmutableMap.<DriverType, RegionDriver>builder().put(DriverType.MYSQL, sqlDriver).put(DriverType.YAML, yamlDriver).build();
    this.selectedRegionStoreDriver = useSqlDatabase ? sqlDriver : yamlDriver;
    postLoad();
    config.setHeader(CONFIG_HEADER);
}
Also used : DirectoryYamlDriver(com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver) DataSourceConfig(com.sk89q.worldguard.util.sql.DataSourceConfig) IOException(java.io.IOException) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) YAMLProcessor(com.sk89q.util.yaml.YAMLProcessor) SQLDriver(com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver) DriverType(com.sk89q.worldguard.protection.managers.storage.DriverType) File(java.io.File) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)2 DirectoryYamlDriver (com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver)2 SQLDriver (com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CommandsManagerRegistration (com.sk89q.bukkit.util.CommandsManagerRegistration)1 CommandException (com.sk89q.minecraft.util.commands.CommandException)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 CommandUsageException (com.sk89q.minecraft.util.commands.CommandUsageException)1 CommandsManager (com.sk89q.minecraft.util.commands.CommandsManager)1 MissingNestedCommandException (com.sk89q.minecraft.util.commands.MissingNestedCommandException)1 SimpleInjector (com.sk89q.minecraft.util.commands.SimpleInjector)1 WrappedCommandException (com.sk89q.minecraft.util.commands.WrappedCommandException)1 YAMLProcessor (com.sk89q.util.yaml.YAMLProcessor)1 PermissionsResolverManager (com.sk89q.wepif.PermissionsResolverManager)1 BukkitAdapter (com.sk89q.worldedit.bukkit.BukkitAdapter)1