Search in sources :

Example 1 with TranslatedParserException

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;
}
Also used : Locale(java.util.Locale) Announcement(org.cubeengine.module.shout.announce.Announcement) TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException) Text(org.spongepowered.api.text.Text)

Example 2 with TranslatedParserException

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));
        }
    }
}
Also used : Locale(java.util.Locale) TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException) ParseException(java.text.ParseException)

Example 3 with TranslatedParserException

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;
}
Also used : Locale(java.util.Locale) TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 4 with TranslatedParserException

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;
}
Also used : ItemType(org.spongepowered.api.item.ItemType) TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException)

Example 5 with TranslatedParserException

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;
}
Also used : TranslatedParserException(org.cubeengine.libcube.service.command.TranslatedParserException) LogLevel(org.cubeengine.logscribe.LogLevel)

Aggregations

TranslatedParserException (org.cubeengine.libcube.service.command.TranslatedParserException)9 Locale (java.util.Locale)4 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 Collectors.toList (java.util.stream.Collectors.toList)1 LogLevel (org.cubeengine.logscribe.LogLevel)1 Announcement (org.cubeengine.module.shout.announce.Announcement)1 LookupData (org.cubeengine.module.vigil.data.LookupData)1 BlockType (org.spongepowered.api.block.BlockType)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemType (org.spongepowered.api.item.ItemType)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Text (org.spongepowered.api.text.Text)1 Difficulty (org.spongepowered.api.world.difficulty.Difficulty)1