Search in sources :

Example 1 with ScoreType

use of com.skelril.skree.service.internal.highscore.ScoreType in project Skree by Skelril.

the class HighScoreCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    HighScoreService service = Sponge.getServiceManager().provideUnchecked(HighScoreService.class);
    PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    Optional<ScoreType> optScoreType = args.getOne("score type");
    if (optScoreType.isPresent()) {
        ScoreType scoreType = optScoreType.get();
        List<Clause<Optional<GameProfile>, Integer>> scores = service.getTop(scoreType);
        List<Text> result = new ArrayList<>(scores.size());
        for (int i = 0; i < scores.size(); ++i) {
            result.add(createScoreLine(i + 1, scores.get(i), scoreType));
        }
        pagination.builder().contents(result).title(Text.of(TextColors.GOLD, getFriendlyName(reverseChoices.get(scoreType)))).padding(Text.of(" ")).sendTo(src);
    } else {
        List<Text> result = choices.keySet().stream().map(this::createScoreTypeLine).sorted().collect(Collectors.toList());
        pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "High Score Tables")).padding(Text.of(" ")).sendTo(src);
    }
    return CommandResult.success();
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ScoreType(com.skelril.skree.service.internal.highscore.ScoreType) Clause(com.skelril.nitro.Clause) HighScoreService(com.skelril.skree.service.HighScoreService)

Aggregations

Clause (com.skelril.nitro.Clause)1 HighScoreService (com.skelril.skree.service.HighScoreService)1 ScoreType (com.skelril.skree.service.internal.highscore.ScoreType)1 GameProfile (org.spongepowered.api.profile.GameProfile)1 PaginationService (org.spongepowered.api.service.pagination.PaginationService)1 Text (org.spongepowered.api.text.Text)1