Search in sources :

Example 11 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class RegionCommands method redefine.

/**
 * Re-defines a region with a new selection.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "redefine", "update", "move" }, usage = "[-w <world>] <id>", desc = "Re-defines the shape of a region", flags = "gw:", min = 1, max = 1)
public void redefine(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    String id = checkRegionId(args.getString(0), false);
    World world = checkWorld(args, sender, 'w');
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion existing = checkExistingRegion(manager, id, false);
    // Check permissions
    if (!getPermissionModel(sender).mayRedefine(existing)) {
        throw new CommandPermissionsException();
    }
    ProtectedRegion region;
    if (args.hasFlag('g')) {
        region = new GlobalProtectedRegion(id);
    } else {
        region = checkRegionFromSelection(sender, id);
    }
    region.copyFrom(existing);
    RegionAdder task = new RegionAdder(manager, region);
    final String description = String.format("Updating region '%s'", region.getId());
    AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("(Please wait... " + description + ")").onSuccess((Component) null, t -> {
        sender.print(String.format("Region '%s' has been updated with a new area.", region.getId()));
        warnAboutDimensions(sender, region);
        informNewUser(sender, manager, region);
        checkSpawnOverlap(sender, world, region);
    }).onFailure(String.format("Failed to update the region '%s'", region.getId()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
Also used : RegionAdder(com.sk89q.worldguard.commands.task.RegionAdder) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 12 with Command

use of com.sk89q.minecraft.util.commands.Command 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 13 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class RegionCommands method info.

/**
 * Get information about a region.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "info", "i" }, usage = "[id]", flags = "usw:", desc = "Get information about a region", min = 0, max = 1)
public void info(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    RegionPermissionModel permModel = getPermissionModel(sender);
    // Lookup the existing region
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion existing;
    if (args.argsLength() == 0) {
        // Get region from where the player is
        if (!(sender instanceof LocalPlayer)) {
            throw new CommandException("Please specify the region with /region info -w world_name region_name.");
        }
        existing = checkRegionStandingIn(manager, (LocalPlayer) sender, true, "/rg info -w \"" + world.getName() + "\" %id%" + (args.hasFlag('u') ? " -u" : "") + (args.hasFlag('s') ? " -s" : ""));
    } else {
        // Get region from the ID
        existing = checkExistingRegion(manager, args.getString(0), true);
    }
    // Check permissions
    if (!permModel.mayLookup(existing)) {
        throw new CommandPermissionsException();
    }
    // Let the player select the region
    if (args.hasFlag('s')) {
        // Check permissions
        if (!permModel.maySelect(existing)) {
            throw new CommandPermissionsException();
        }
        setPlayerSelection(worldGuard.checkPlayer(sender), existing, world);
    }
    // Print region information
    RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), existing, args.hasFlag('u') ? null : WorldGuard.getInstance().getProfileCache(), sender);
    AsyncCommandBuilder.wrap(printout, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Fetching region info").sendMessageAfterDelay("(Please wait... fetching region information...)").onSuccess((Component) null, component -> {
        sender.print(component);
        checkSpawnOverlap(sender, world, existing);
    }).onFailure("Failed to fetch region information", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) RegionPermissionModel(com.sk89q.worldguard.internal.permission.RegionPermissionModel) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 14 with Command

use of com.sk89q.minecraft.util.commands.Command 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 15 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class ToggleCommands method stopLag.

@Command(aliases = { "halt-activity", "stoplag", "haltactivity" }, usage = "[confirm]", desc = "Attempts to cease as much activity in order to stop lag", flags = "cis", max = 1)
@CommandPermissions({ "worldguard.halt-activity" })
public void stopLag(CommandContext args, Actor sender) throws CommandException {
    ConfigurationManager configManager = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    if (args.hasFlag('i')) {
        if (configManager.activityHaltToggle) {
            sender.print("ALL intensive server activity is not allowed.");
        } else {
            sender.print("ALL intensive server activity is allowed.");
        }
    } else {
        boolean activityHaltToggle = !args.hasFlag('c');
        if (activityHaltToggle && (args.argsLength() == 0 || !args.getString(0).equalsIgnoreCase("confirm"))) {
            String confirmCommand = "/" + args.getCommand() + " confirm";
            TextComponent message = TextComponent.builder("").append(ErrorFormat.wrap("This command will ")).append(ErrorFormat.wrap("PERMANENTLY").decoration(TextDecoration.BOLD, TextDecoration.State.TRUE)).append(ErrorFormat.wrap(" erase ALL animals in ALL loaded chunks in ALL loaded worlds. ")).append(TextComponent.newline()).append(TextComponent.of("[Click]", TextColor.GREEN).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, confirmCommand)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to confirm /" + args.getCommand())))).append(ErrorFormat.wrap(" or type ")).append(CodeFormat.wrap(confirmCommand).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, confirmCommand))).append(ErrorFormat.wrap(" to confirm.")).build();
            sender.print(message);
            return;
        }
        configManager.activityHaltToggle = activityHaltToggle;
        if (activityHaltToggle) {
            if (!(sender instanceof LocalPlayer)) {
                sender.print("ALL intensive server activity halted.");
            }
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity halted by " + sender.getDisplayName() + "."));
            } else {
                sender.print("(Silent) ALL intensive server activity halted by " + sender.getDisplayName() + ".");
            }
            for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
                int removed = 0;
                for (Entity entity : world.getEntities()) {
                    if (Entities.isIntensiveEntity(entity)) {
                        entity.remove();
                        removed++;
                    }
                }
                if (removed > 10) {
                    sender.printRaw("" + removed + " entities (>10) auto-removed from " + world.getName());
                }
            }
        } else {
            if (!args.hasFlag('s')) {
                worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity is now allowed."));
                if (!(sender instanceof LocalPlayer)) {
                    sender.print("ALL intensive server activity is now allowed.");
                }
            } else {
                sender.print("(Silent) ALL intensive server activity is now allowed.");
            }
        }
    }
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Entity(com.sk89q.worldedit.entity.Entity) LocalPlayer(com.sk89q.worldguard.LocalPlayer) World(com.sk89q.worldedit.world.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)41 LocalPlayer (com.sk89q.worldguard.LocalPlayer)24 World (com.sk89q.worldedit.world.World)23 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)22 CommandException (com.sk89q.minecraft.util.commands.CommandException)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)15 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)5 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)3 Task (com.sk89q.worldedit.util.task.Task)3 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3