use of org.cubeengine.butler.exception.SilentException in project core by CubeEngine.
the class EnchantmentParser method parse.
@Override
public EnchantmentType parse(Class type, CommandInvocation invocation) throws ParserException {
String token = invocation.consume(1);
EnchantmentType enchantment = enchantMatcher.enchantment(token);
if (enchantment == null) {
CommandSource sender = (CommandSource) invocation.getCommandSource();
Text possibleEnchs = getPossibleEnchantments(sender instanceof Player ? ((Player) sender).getItemInHand(HandTypes.MAIN_HAND).orElse(null) : null);
i18n.send(sender, NEGATIVE, "Enchantment {input#enchantment} not found!", token);
if (possibleEnchs != null) {
i18n.send(sender, NEUTRAL, "Try one of those instead:");
sender.sendMessage(possibleEnchs);
} else {
i18n.send(sender, NEGATIVE, "You can not enchant this item!");
}
throw new SilentException();
}
return enchantment;
}
use of org.cubeengine.butler.exception.SilentException 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;
}
Aggregations