Search in sources :

Example 1 with RegionDriver

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

the class RegionContainer method autoMigrate.

/**
 * Execute auto-migration.
 */
protected void autoMigrate() {
    ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    if (config.migrateRegionsToUuid) {
        RegionDriver driver = getDriver();
        UUIDMigration migrator = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
        migrator.setKeepUnresolvedNames(config.keepUnresolvedNames);
        try {
            migrate(migrator);
            WorldGuard.logger.info("Regions saved after UUID migration! This won't happen again unless " + "you change the relevant configuration option in WorldGuard's config.");
            config.disableUuidMigration();
        } catch (MigrationException e) {
            WorldGuard.logger.log(Level.WARNING, "Failed to execute the migration", e);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) UUIDMigration(com.sk89q.worldguard.protection.managers.migration.UUIDMigration)

Example 2 with RegionDriver

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

the class RegionCommands method migrateHeights.

/**
 * Migrate regions that went from 0-255 to new world heights.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migrateheights" }, usage = "[world]", max = 1, flags = "yw:", desc = "Migrate regions from old height limits to new height limits")
public void migrateHeights(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionHeights()) {
        throw new CommandPermissionsException();
    }
    if (!args.hasFlag('y')) {
        throw new CommandException("This command is potentially dangerous.\n" + "Please ensure you have made a backup of your data, and then re-enter the command with -y tacked on at the end to proceed.");
    }
    World world = null;
    try {
        world = checkWorld(args, sender, 'w');
    } catch (CommandException ignored) {
    }
    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;
    if (sender instanceof LocalPlayer) {
        handler = new LoggerToChatHandler(sender);
        handler.setLevel(Level.ALL);
        minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
        minecraftLogger.addHandler(handler);
    }
    try {
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionDriver driver = container.getDriver();
        WorldHeightMigration migration = new WorldHeightMigration(driver, WorldGuard.getInstance().getFlagRegistry(), world);
        container.migrate(migration);
        sender.print("Migration complete!");
    } catch (MigrationException e) {
        log.log(Level.WARNING, "Failed to migrate", e);
        throw new CommandException("Error encountered while migrating: " + e.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) WorldHeightMigration(com.sk89q.worldguard.protection.managers.migration.WorldHeightMigration) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Logger(java.util.logging.Logger) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) Command(com.sk89q.minecraft.util.commands.Command)

Example 3 with RegionDriver

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

the class RegionCommands method migrateDB.

/**
 * Migrate the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migratedb" }, usage = "<from> <to>", flags = "y", desc = "Migrate from one Protection Database to another.", min = 2, max = 2)
public void migrateDB(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionStore()) {
        throw new CommandPermissionsException();
    }
    DriverType from = Enums.findFuzzyByValue(DriverType.class, args.getString(0));
    DriverType to = Enums.findFuzzyByValue(DriverType.class, args.getString(1));
    if (from == null) {
        throw new CommandException("The value of 'from' is not a recognized type of region data database.");
    }
    if (to == null) {
        throw new CommandException("The value of 'to' is not a recognized type of region region data database.");
    }
    if (from == to) {
        throw new CommandException("It is not possible to migrate between the same types of region data databases.");
    }
    if (!args.hasFlag('y')) {
        throw new CommandException("This command is potentially dangerous.\n" + "Please ensure you have made a backup of your data, and then re-enter the command with -y tacked on at the end to proceed.");
    }
    ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    RegionDriver fromDriver = config.regionStoreDriverMap.get(from);
    RegionDriver toDriver = config.regionStoreDriverMap.get(to);
    if (fromDriver == null) {
        throw new CommandException("The driver specified as 'from' does not seem to be supported in your version of WorldGuard.");
    }
    if (toDriver == null) {
        throw new CommandException("The driver specified as 'to' does not seem to be supported in your version of WorldGuard.");
    }
    DriverMigration migration = new DriverMigration(fromDriver, toDriver, WorldGuard.getInstance().getFlagRegistry());
    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;
    if (sender instanceof LocalPlayer) {
        handler = new LoggerToChatHandler(sender);
        handler.setLevel(Level.ALL);
        minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
        minecraftLogger.addHandler(handler);
    }
    try {
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        sender.print("Now performing migration... this may take a while.");
        container.migrate(migration);
        sender.print("Migration complete! This only migrated the data. If you already changed your settings to use " + "the target driver, then WorldGuard is now using the new data. If not, you have to adjust your " + "configuration to use the new driver and then restart your server.");
    } catch (MigrationException e) {
        log.log(Level.WARNING, "Failed to migrate", e);
        throw new CommandException("Error encountered while migrating: " + e.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) DriverMigration(com.sk89q.worldguard.protection.managers.migration.DriverMigration) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) DriverType(com.sk89q.worldguard.protection.managers.storage.DriverType) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) Logger(java.util.logging.Logger) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command)

Example 4 with RegionDriver

use of com.sk89q.worldguard.protection.managers.storage.RegionDriver 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 5 with RegionDriver

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

the class RegionCommands method migrateUuid.

/**
 * Migrate the region databases to use UUIDs rather than name.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "migrateuuid" }, desc = "Migrate loaded databases to use UUIDs", max = 0)
public void migrateUuid(CommandContext args, Actor sender) throws CommandException {
    // Check permissions
    if (!getPermissionModel(sender).mayMigrateRegionNames()) {
        throw new CommandPermissionsException();
    }
    LoggerToChatHandler handler = null;
    Logger minecraftLogger = null;
    if (sender instanceof LocalPlayer) {
        handler = new LoggerToChatHandler(sender);
        handler.setLevel(Level.ALL);
        minecraftLogger = Logger.getLogger("com.sk89q.worldguard");
        minecraftLogger.addHandler(handler);
    }
    try {
        ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
        RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
        RegionDriver driver = container.getDriver();
        UUIDMigration migration = new UUIDMigration(driver, WorldGuard.getInstance().getProfileService(), WorldGuard.getInstance().getFlagRegistry());
        migration.setKeepUnresolvedNames(config.keepUnresolvedNames);
        sender.print("Now performing migration... this may take a while.");
        container.migrate(migration);
        sender.print("Migration complete!");
    } catch (MigrationException e) {
        log.log(Level.WARNING, "Failed to migrate", e);
        throw new CommandException("Error encountered while migrating: " + e.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : MigrationException(com.sk89q.worldguard.protection.managers.migration.MigrationException) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Logger(java.util.logging.Logger) RegionDriver(com.sk89q.worldguard.protection.managers.storage.RegionDriver) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) UUIDMigration(com.sk89q.worldguard.protection.managers.migration.UUIDMigration) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)6 CommandException (com.sk89q.minecraft.util.commands.CommandException)4 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)4 LocalPlayer (com.sk89q.worldguard.LocalPlayer)4 Logger (java.util.logging.Logger)4 Command (com.sk89q.minecraft.util.commands.Command)3 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)3 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)2 DirectoryYamlDriver (com.sk89q.worldguard.protection.managers.storage.file.DirectoryYamlDriver)2 SQLDriver (com.sk89q.worldguard.protection.managers.storage.sql.SQLDriver)2 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)2 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)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 CommandUsageException (com.sk89q.minecraft.util.commands.CommandUsageException)1