Search in sources :

Example 1 with CommandException

use of com.denizenscript.denizen.utilities.command.manager.exceptions.CommandException in project Denizen-For-Bukkit by DenizenScript.

the class DenizenCommandHandler method scripts.

/*
     * DENIZEN SCRIPTS
     */
@Command(aliases = { "denizen" }, usage = "scripts (--type assignment|task|...) (--filter string)", desc = "Lists currently loaded dScripts.", modifiers = { "scripts" }, min = 1, max = 4, permission = "denizen.basic")
public void scripts(CommandContext args, CommandSender sender) throws CommandException {
    String type = null;
    if (args.hasValueFlag("type")) {
        type = args.getFlag("type");
    }
    String filter = null;
    if (args.hasValueFlag("filter")) {
        filter = args.getFlag("filter");
    }
    Set<String> scripts = ScriptRegistry.scriptContainers.keySet();
    Paginator paginator = new Paginator().header("Scripts");
    paginator.addLine("<e>Key: <a>Type  <b>Name");
    for (String script : scripts) {
        ScriptContainer scriptContainer = ScriptRegistry.getScriptContainer(script);
        if (type != null) {
            if (scriptContainer.getContainerType().equalsIgnoreCase(type)) {
                if (filter != null) {
                    if (script.contains(filter.toUpperCase())) {
                        paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + "  <b>" + script);
                    }
                } else {
                    paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + "  <b>" + script);
                }
            }
        } else if (filter != null) {
            if (script.contains(filter.toUpperCase())) {
                paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + "  <b>" + script);
            }
        } else {
            paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + "  <b>" + script);
        }
    }
    if (!paginator.sendPage(sender, args.getInteger(1, 1))) {
        throw new CommandException("The page " + args.getInteger(1, 1) + " does not exist.");
    }
}
Also used : ScriptContainer(com.denizenscript.denizencore.scripts.containers.ScriptContainer) CommandException(com.denizenscript.denizen.utilities.command.manager.exceptions.CommandException) Paginator(com.denizenscript.denizen.utilities.command.manager.Paginator) Command(com.denizenscript.denizen.utilities.command.manager.Command)

Example 2 with CommandException

use of com.denizenscript.denizen.utilities.command.manager.exceptions.CommandException in project Denizen-For-Bukkit by DenizenScript.

the class CommandContext method parseLocation.

public static Location parseLocation(Location currentLocation, String flag) throws CommandException {
    boolean denizen = flag.startsWith("l@");
    String[] parts = flag.replaceFirst("l@", "").split("[,]|[:]");
    if (parts.length > 0) {
        String worldName = currentLocation != null ? currentLocation.getWorld().getName() : "";
        double x, y, z;
        float yaw = 0F, pitch = 0F;
        switch(parts.length) {
            case 6:
                if (denizen) {
                    worldName = parts[5].replaceFirst("w@", "");
                } else {
                    pitch = Float.parseFloat(parts[5]);
                }
            case 5:
                if (denizen) {
                    pitch = Float.parseFloat(parts[4]);
                } else {
                    yaw = Float.parseFloat(parts[4]);
                }
            case 4:
                if (denizen && parts.length > 4) {
                    yaw = Float.parseFloat(parts[3]);
                } else {
                    worldName = parts[3].replaceFirst("w@", "");
                }
            case 3:
                x = Double.parseDouble(parts[0]);
                y = Double.parseDouble(parts[1]);
                z = Double.parseDouble(parts[2]);
                break;
            default:
                throw new CommandException("Location could not be parsed or was not found.");
        }
        World world = Bukkit.getWorld(worldName);
        if (world == null) {
            throw new CommandException("Location could not be parsed or was not found.");
        }
        return new Location(world, x, y, z, yaw, pitch);
    } else {
        Player search = Bukkit.getPlayerExact(flag);
        if (search == null) {
            throw new CommandException("No player could be found by that name.");
        }
        return search.getLocation();
    }
}
Also used : Player(org.bukkit.entity.Player) CommandException(com.denizenscript.denizen.utilities.command.manager.exceptions.CommandException) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

CommandException (com.denizenscript.denizen.utilities.command.manager.exceptions.CommandException)2 Command (com.denizenscript.denizen.utilities.command.manager.Command)1 Paginator (com.denizenscript.denizen.utilities.command.manager.Paginator)1 ScriptContainer (com.denizenscript.denizencore.scripts.containers.ScriptContainer)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1