Search in sources :

Example 26 with GameProfile

use of org.spongepowered.api.profile.GameProfile 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)

Example 27 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project Skree by Skelril.

the class HighScoreCommand method createScoreLine.

private Text createScoreLine(int rank, Clause<Optional<GameProfile>, Integer> clause, ScoreType scoreType) {
    String playerName = "Unknown";
    Optional<GameProfile> optOwningProfile = clause.getKey();
    if (optOwningProfile.isPresent()) {
        GameProfile owningProfile = optOwningProfile.get();
        Optional<String> optName = owningProfile.getName();
        if (optName.isPresent()) {
            playerName = optName.get();
        }
    }
    return Text.of(TextColors.YELLOW, '#', rank, ' ', TextColors.BLUE, StringUtils.rightPad(playerName, ChatConstants.MAX_PLAYER_NAME_LENGTH), "   ", (rank == 1 ? TextColors.GOLD : TextColors.WHITE), scoreType.format(clause.getValue()));
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile)

Example 28 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project Skree by Skelril.

the class HighScoreDatabaseUtil method getTop.

public static List<Clause<Optional<GameProfile>, Integer>> getTop(ScoreType scoreType, int count) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        Result<Record2<String, Integer>> results = create.select(PLAYERS.UUID, HIGH_SCORES.VALUE).from(HIGH_SCORES).join(PLAYERS).on(PLAYERS.ID.equal(HIGH_SCORES.PLAYER_ID)).where(HIGH_SCORES.SCORE_TYPE_ID.equal(scoreType.getId())).orderBy(scoreType.getOrder() == ScoreType.Order.ASC ? HIGH_SCORES.VALUE.asc() : HIGH_SCORES.VALUE.desc()).limit(count).fetch();
        return results.stream().map(record -> new Clause<>(getProfile(record.getValue(PLAYERS.UUID)), record.getValue(HIGH_SCORES.VALUE))).collect(Collectors.toList());
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return Lists.newArrayList();
}
Also used : DSL(org.jooq.impl.DSL) Connection(java.sql.Connection) Sponge(org.spongepowered.api.Sponge) PLAYERS(com.skelril.skree.db.schema.Tables.PLAYERS) UUID(java.util.UUID) Result(org.jooq.Result) Collectors(java.util.stream.Collectors) HIGH_SCORES(com.skelril.skree.db.schema.tables.HighScores.HIGH_SCORES) SQLHandle(com.skelril.skree.db.SQLHandle) ExecutionException(java.util.concurrent.ExecutionException) Record2(org.jooq.Record2) SQLException(java.sql.SQLException) List(java.util.List) Lists(com.google.common.collect.Lists) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) Clause(com.skelril.nitro.Clause) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) Clause(com.skelril.nitro.Clause) Record2(org.jooq.Record2)

Example 29 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project LuckPerms by lucko.

the class SpongeConnectionListener method onClientLogin.

@Listener(order = Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLogin(ClientConnectionEvent.Login e) {
    /* Called when the player starts logging into the server.
           At this point, the users data should be present and loaded.
           Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */
    final GameProfile profile = e.getProfile();
    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing login event for " + profile.getUniqueId() + " - " + profile.getName());
    }
    final User user = this.plugin.getUserManager().getIfLoaded(profile.getUniqueId());
    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(profile.getUniqueId());
        this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() + " doesn't have data pre-loaded. - denying login.");
        e.setCancelled(true);
        e.setMessageCancelled(false);
        // noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
Also used : User(me.lucko.luckperms.common.model.User) GameProfile(org.spongepowered.api.profile.GameProfile) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Example 30 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project modules-extra by CubeEngine.

the class HideListener method onServerPingList.

@Listener
public void onServerPingList(ClientPingServerEvent event) {
    GameProfileManager gpm = Sponge.getServer().getGameProfileManager();
    event.getResponse().getPlayers().ifPresent(l -> {
        for (UUID uuid : module.getHiddenUsers()) {
            GameProfile gp = gpm.get(uuid).join();
            l.getProfiles().remove(gp);
        }
    });
}
Also used : GameProfileManager(org.spongepowered.api.profile.GameProfileManager) GameProfile(org.spongepowered.api.profile.GameProfile) UUID(java.util.UUID) Listener(org.spongepowered.api.event.Listener)

Aggregations

GameProfile (org.spongepowered.api.profile.GameProfile)44 Optional (java.util.Optional)12 UUID (java.util.UUID)12 Text (org.spongepowered.api.text.Text)9 User (org.spongepowered.api.entity.living.player.User)8 IOException (java.io.IOException)7 List (java.util.List)6 Sponge (org.spongepowered.api.Sponge)6 Cause (org.spongepowered.api.event.cause.Cause)6 World (org.spongepowered.api.world.World)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 Collectors (java.util.stream.Collectors)5 Keys (org.spongepowered.api.data.key.Keys)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 ImmutableList (com.google.common.collect.ImmutableList)4 Lists (com.google.common.collect.Lists)4 Collection (java.util.Collection)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4