use of org.cubeengine.libcube.service.command.TranslatedParserException in project modules-extra by CubeEngine.
the class LookupDataParser method parse.
@Override
public LookupData parse(Class clazz, CommandInvocation ci) throws ParserException {
String token = ci.consume(1);
if (!types.keySet().contains(token.toLowerCase())) {
throw new TranslatedParserException(i18n.translate(ci.getContext(Locale.class), NEGATIVE, "{input} is not a valid log-type. Use chest, container, player, block or kills instead!", token));
}
LookupData data = types.get(token.toLowerCase()).copy();
return data.withCreator(((Player) ci.getCommandSource()).getUniqueId());
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class DifficultyParser method parse.
@Override
public Difficulty parse(Class type, CommandInvocation invocation) throws ParserException {
String token = invocation.currentToken();
Locale locale = invocation.getContext(Locale.class);
try {
Difficulty difficulty = difficultyMap.get(Integer.valueOf(token));
if (difficulty == null) {
throw new TranslatedParserException(i18n.translate(locale, MessageType.NEGATIVE, "The given difficulty level is unknown!"));
}
invocation.consume(1);
return difficulty;
} catch (NumberFormatException e) {
return super.parse(type, invocation);
}
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class FuzzyUserParser method parse.
@Override
@SuppressWarnings("unchecked")
public List<Player> parse(Class type, CommandInvocation invocation) throws ParserException {
ArrayList<Player> users = new ArrayList<>();
if ("*".equals(invocation.currentToken())) {
invocation.consume(1);
users.addAll(game.getServer().getOnlinePlayers());
return users;
}
if (invocation.currentToken().contains(",")) {
((List<List<Player>>) invocation.providers().parsers().get(List.class).parse(FuzzyUserParser.class, invocation)).forEach(users::addAll);
return users;
}
String token = invocation.currentToken();
if (token.contains("*")) {
Pattern pattern = Pattern.compile(token.replace("*", ".*"));
users.addAll(game.getServer().getOnlinePlayers().stream().filter(user -> pattern.matcher(user.getName()).matches()).collect(toList()));
if (users.isEmpty()) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "Player {user} not found!", token));
}
invocation.consume(1);
} else {
users.add((Player) invocation.providers().read(Player.class, Player.class, invocation));
}
return users;
}
use of org.cubeengine.libcube.service.command.TranslatedParserException in project core by CubeEngine.
the class BlockTypeParser method parse.
@Override
public BlockType parse(Class aClass, CommandInvocation invocation) throws ParserException {
String arg = invocation.consume(1);
BlockType item = Sponge.getRegistry().getType(BlockType.class, arg.toLowerCase()).orElse(null);
if (item == null) {
throw new TranslatedParserException(i18n.translate(invocation.getContext(Locale.class), NEGATIVE, "ItemType {input#item} not found!", arg));
}
return item;
}
Aggregations