use of org.cubeengine.libcube.service.command.TranslatedParserException in project modules-extra by CubeEngine.
the class AnnouncementParser method parse.
@Override
public Announcement parse(Class clazz, CommandInvocation invocation) throws ParserException {
String name = invocation.consume(1);
Announcement announcement = manager.getAnnouncement(name);
if (announcement == null) {
Text trans = i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "{input#announcement} was not found!", name);
throw new TranslatedParserException(trans);
}
return announcement;
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class DoubleParser method parse.
@Override
public Double parse(Class type, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
Locale locale = invocation.getContext(Locale.class);
try {
return NumberFormat.getInstance(locale).parse(arg).doubleValue();
} catch (ParseException e) {
try {
// Try parsing with default locale
return NumberFormat.getInstance().parse(arg).doubleValue();
} catch (ParseException e1) {
throw new TranslatedParserException(i18n.translate(locale, MessageType.NEGATIVE, "Could not parse {input} to double!", arg));
}
}
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class ItemStackParser method parse.
@Override
public ItemStack parse(Class type, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
ItemStack item = materialMatcher.itemStack(arg, invocation.getContext(Locale.class));
if (item == null) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "Item {input#item} not found!", arg));
}
return item;
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class ItemTypeParser method parse.
@Override
public ItemType parse(Class aClass, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
ItemType item = Sponge.getRegistry().getType(ItemType.class, arg.toLowerCase()).orElse(null);
if (item == null) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "ItemType {input#block} not found!", arg));
}
return item;
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class LogLevelParser method parse.
@Override
public LogLevel parse(Class type, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
LogLevel logLevel = LogLevel.toLevel(arg);
if (logLevel == null) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), MessageType.NEGATIVE, "The given log level is unknown."));
}
return logLevel;
}
Aggregations