Search in sources :

Example 11 with CommandException

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

the class WorldGuardCommands method reload.

@Command(aliases = { "reload" }, desc = "Reload WorldGuard configuration", max = 0)
@CommandPermissions({ "worldguard.reload" })
public void reload(CommandContext args, Actor sender) throws CommandException {
    // TODO: This is subject to a race condition, but at least other commands are not being processed concurrently
    List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
    if (!tasks.isEmpty()) {
        throw new CommandException("There are currently pending tasks. Use /wg running to monitor these tasks first.");
    }
    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();
        config.unload();
        config.load();
        for (World world : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
            config.get(world);
        }
        WorldGuard.getInstance().getPlatform().getRegionContainer().reload();
        // WGBukkit.cleanCache();
        sender.print("WorldGuard configuration reloaded.");
    } catch (Throwable t) {
        sender.printError("Error while reloading: " + t.getMessage());
    } finally {
        if (minecraftLogger != null) {
            minecraftLogger.removeHandler(handler);
        }
    }
}
Also used : FutureForwardingTask(com.sk89q.worldedit.util.task.FutureForwardingTask) Task(com.sk89q.worldedit.util.task.Task) LoggerToChatHandler(com.sk89q.worldguard.util.logging.LoggerToChatHandler) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Logger(java.util.logging.Logger) World(com.sk89q.worldedit.world.World) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) NestedCommand(com.sk89q.minecraft.util.commands.NestedCommand) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 12 with CommandException

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

the class RegionCommandsBase method setPlayerSelection.

/**
 * Set an actor's selection to a given region.
 *
 * @param actor the actor
 * @param region the region
 * @throws CommandException thrown on a command error
 */
protected static void setPlayerSelection(Actor actor, ProtectedRegion region, World world) throws CommandException {
    LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
    RegionSelector selector = WorldEditRegionConverter.convertToSelector(region);
    if (selector != null) {
        selector.setWorld(world);
        session.setRegionSelector(world, selector);
        selector.explainRegionAdjust(actor, session);
        actor.print("Region selected as " + region.getType().getName());
    } else {
        throw new CommandException("Can't select that region! " + "The region type '" + region.getType().getName() + "' can't be selected.");
    }
}
Also used : CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) Polygonal2DRegionSelector(com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector) RegionSelector(com.sk89q.worldedit.regions.RegionSelector) LocalSession(com.sk89q.worldedit.LocalSession) CommandException(com.sk89q.minecraft.util.commands.CommandException)

Example 13 with CommandException

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

the class RegionCommandsBase method checkRegionStandingIn.

/**
 * Get the region at the player's location, if possible.
 *
 * <p>If the player is standing in several regions, an error will be raised
 * and a list of regions will be provided.</p>
 *
 * <p>If the player is not standing in any regions, the global region will
 * returned if allowGlobal is true and it exists.</p>
 *
 * @param regionManager the region manager
 * @param player the player
 * @param allowGlobal whether to search for a global region if no others are found
 * @return a region
 * @throws CommandException thrown if no region was found
 */
protected static ProtectedRegion checkRegionStandingIn(RegionManager regionManager, LocalPlayer player, boolean allowGlobal, String rgCmd) throws CommandException {
    ApplicableRegionSet set = regionManager.getApplicableRegions(player.getLocation().toVector().toBlockPoint(), QueryOption.SORT);
    if (set.size() == 0) {
        if (allowGlobal) {
            ProtectedRegion global = checkExistingRegion(regionManager, "__global__", true);
            player.printDebug("You're not standing in any " + "regions. Using the global region for this world instead.");
            return global;
        }
        throw new CommandException("You're not standing in a region. " + "Specify an ID if you want to select a specific region.");
    } else if (set.size() > 1) {
        boolean first = true;
        final TextComponent.Builder builder = TextComponent.builder("");
        builder.append(TextComponent.of("Current regions: ", TextColor.GOLD));
        for (ProtectedRegion region : set) {
            if (!first) {
                builder.append(TextComponent.of(", "));
            }
            first = false;
            TextComponent regionComp = TextComponent.of(region.getId(), TextColor.AQUA);
            if (rgCmd != null && rgCmd.contains("%id%")) {
                regionComp = regionComp.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to pick this region"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, rgCmd.replace("%id%", region.getId())));
            }
            builder.append(regionComp);
        }
        player.print(builder.build());
        throw new CommandException("You're standing in several regions (please pick one).");
    }
    return set.iterator().next();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) CommandException(com.sk89q.minecraft.util.commands.CommandException) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 14 with CommandException

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

the class RegionCommandsBase method checkRegionFromSelection.

/**
 * Create a {@link ProtectedRegion} from the actor's selection.
 *
 * @param actor the actor
 * @param id the ID of the new region
 * @return a new region
 * @throws CommandException thrown on an error
 */
protected static ProtectedRegion checkRegionFromSelection(Actor actor, String id) throws CommandException {
    Region selection = checkSelection(actor);
    // Detect the type of region from WorldEdit
    if (selection instanceof Polygonal2DRegion) {
        Polygonal2DRegion polySel = (Polygonal2DRegion) selection;
        int minY = polySel.getMinimumPoint().getBlockY();
        int maxY = polySel.getMaximumPoint().getBlockY();
        return new ProtectedPolygonalRegion(id, polySel.getPoints(), minY, maxY);
    } else if (selection instanceof CuboidRegion) {
        BlockVector3 min = selection.getMinimumPoint();
        BlockVector3 max = selection.getMaximumPoint();
        return new ProtectedCuboidRegion(id, min, max);
    } else {
        throw new CommandException("Sorry, you can only use cuboids and polygons for WorldGuard regions.");
    }
}
Also used : Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Polygonal2DRegion(com.sk89q.worldedit.regions.Polygonal2DRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) CommandException(com.sk89q.minecraft.util.commands.CommandException) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 15 with CommandException

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

the class BukkitDebugHandler method traceBlock.

/**
 * Find the first non-air block in a ray trace.
 *
 * @param sender The sender
 * @param target The target
 * @param fromTarget Whether the trace should originate from the target
 * @return The block found
 * @throws CommandException Throw on an incorrect parameter
 */
private Block traceBlock(CommandSender sender, Player target, boolean fromTarget) throws CommandException {
    Player source = getSource(sender, target, fromTarget);
    BlockIterator it = new BlockIterator(source);
    int i = 0;
    while (it.hasNext() && i < MAX_TRACE_DISTANCE) {
        Block block = it.next();
        if (block.getType() != Material.AIR) {
            return block;
        }
        i++;
    }
    throw new CommandException("Not currently looking at a block that is close enough.");
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) LocalPlayer(com.sk89q.worldguard.LocalPlayer) Block(org.bukkit.block.Block) CommandException(com.sk89q.minecraft.util.commands.CommandException)

Aggregations

CommandException (com.sk89q.minecraft.util.commands.CommandException)26 Command (com.sk89q.minecraft.util.commands.Command)18 LocalPlayer (com.sk89q.worldguard.LocalPlayer)16 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)15 World (com.sk89q.worldedit.world.World)14 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)12 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)11 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)10 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)4 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)3 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)3 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3 WorldEdit (com.sk89q.worldedit.WorldEdit)2 Actor (com.sk89q.worldedit.extension.platform.Actor)2 Capability (com.sk89q.worldedit.extension.platform.Capability)2