Search in sources :

Example 1 with TooFewArgumentsException

use of org.cubeengine.butler.parameter.TooFewArgumentsException in project modules-extra by CubeEngine.

the class AuthCommands method clearPassword.

@Command(alias = "clearpw", desc = "Clears your password.")
public void clearPassword(CommandSource context, @Optional @Desc("* or a list of Players delimited by ,") PlayerList players) {
    if (players == null) {
        if (!(context instanceof Player)) {
            throw new TooFewArgumentsException();
        }
        module.resetPassword(((Player) context).getUniqueId());
        i18n.send(context, POSITIVE, "Your password has been reset!");
        return;
    }
    if (players.isAll()) {
        if (!context.hasPermission(module.perms().COMMAND_CLEARPASSWORD_ALL.getId())) {
            throw new PermissionDeniedException(module.perms().COMMAND_CLEARPASSWORD_ALL);
        }
        module.resetAllPasswords();
        i18n.send(context, POSITIVE, "All passwords reset!");
        return;
    }
    if (!context.hasPermission(module.perms().COMMAND_CLEARPASSWORD_OTHER.getId())) {
        throw new PermissionDeniedException(module.perms().COMMAND_CLEARPASSWORD_OTHER);
    }
    for (Player user : players.list()) {
        module.resetPassword(user.getUniqueId());
        i18n.send(context, POSITIVE, "{user}'s password has been reset!", user.getName());
    }
}
Also used : TooFewArgumentsException(org.cubeengine.butler.parameter.TooFewArgumentsException) Player(org.spongepowered.api.entity.living.player.Player) PermissionDeniedException(org.cubeengine.libcube.service.command.exception.PermissionDeniedException) Command(org.cubeengine.butler.parametric.Command)

Example 2 with TooFewArgumentsException

use of org.cubeengine.butler.parameter.TooFewArgumentsException in project core by CubeEngine.

the class EnchantmentParser method provide.

@Override
public EnchantmentType provide(CommandInvocation invocation) {
    CommandSource sender = (CommandSource) invocation.getCommandSource();
    i18n.send(sender, POSITIVE, "Following Enchantments are availiable:");
    sender.sendMessage(getPossibleEnchantments(null));
    throw new TooFewArgumentsException();
}
Also used : TooFewArgumentsException(org.cubeengine.butler.parameter.TooFewArgumentsException) CommandSource(org.spongepowered.api.command.CommandSource)

Example 3 with TooFewArgumentsException

use of org.cubeengine.butler.parameter.TooFewArgumentsException in project core by CubeEngine.

the class CommandExceptionHandler method handleException.

@Override
public boolean handleException(Throwable t, CommandBase command, CommandInvocation invocation) {
    if (t instanceof InvocationTargetException || t instanceof ExecutionException) {
        t = t.getCause();
    }
    CommandSource sender = (CommandSource) invocation.getCommandSource();
    if (!(t instanceof CommandException)) {
        return false;
    }
    logger.debug("Command failed: {}: {}", t.getClass(), t.getMessage());
    if (t instanceof PermissionDeniedException) {
        PermissionDeniedException e = (PermissionDeniedException) t;
        if (e.getMessage() != null) {
            i18n.send(sender, NEGATIVE, e.getMessage(), e.getArgs());
        } else {
            i18n.send(sender, NEGATIVE, "You're not allowed to do this!");
            i18n.send(sender, NEGATIVE, "Contact an administrator if you think this is a mistake!");
        }
        i18n.send(sender, NEGATIVE, "Missing permission: {name}", e.getPermission().getName());
    } else if (t instanceof TooFewArgumentsException) {
        i18n.send(sender, NEGATIVE, "You've given too few arguments.");
        i18n.send(sender, NEUTRAL, "Proper usage: {input#usage}", command.getDescriptor().getUsage(invocation));
    } else if (t instanceof TooManyArgumentsException) {
        i18n.send(sender, NEGATIVE, "You've given too many arguments.");
        i18n.send(sender, NEUTRAL, "Proper usage: {input#usage}", command.getDescriptor().getUsage(invocation));
    } else if (t instanceof ParserException) {
        i18n.send(sender, NEGATIVE, t.getMessage(), ((ParserException) t).getArgs());
    } else if (t instanceof RestrictedSourceException) {
        // TODO handle Restriction when its not for CommandSource (maybe programming error)
        i18n.send(sender, NEGATIVE, "You cannot execute this command!");
        if (t.getMessage() != null) {
            i18n.send(sender, NEUTRAL, t.getMessage());
        }
    } else if (t instanceof SilentException) {
    // do nothing
    } else // Unknown cmd exception. Handle later
    {
        return false;
    }
    return true;
}
Also used : TooFewArgumentsException(org.cubeengine.butler.parameter.TooFewArgumentsException) ParserException(org.cubeengine.butler.parameter.argument.ParserException) RestrictedSourceException(org.cubeengine.butler.filter.RestrictedSourceException) TooManyArgumentsException(org.cubeengine.butler.parameter.TooManyArgumentsException) CommandException(org.cubeengine.butler.exception.CommandException) ExecutionException(java.util.concurrent.ExecutionException) CommandSource(org.spongepowered.api.command.CommandSource) SilentException(org.cubeengine.butler.exception.SilentException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TooFewArgumentsException (org.cubeengine.butler.parameter.TooFewArgumentsException)3 CommandSource (org.spongepowered.api.command.CommandSource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (java.util.concurrent.ExecutionException)1 CommandException (org.cubeengine.butler.exception.CommandException)1 SilentException (org.cubeengine.butler.exception.SilentException)1 RestrictedSourceException (org.cubeengine.butler.filter.RestrictedSourceException)1 TooManyArgumentsException (org.cubeengine.butler.parameter.TooManyArgumentsException)1 ParserException (org.cubeengine.butler.parameter.argument.ParserException)1 Command (org.cubeengine.butler.parametric.Command)1 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)1 Player (org.spongepowered.api.entity.living.player.Player)1