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();
}
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()));
}
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();
}
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())));
}
}
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);
}
});
}
Aggregations