Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-138 Fix leaderboards null user. #138

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.eternalcode.discordapp.leveling.Level;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
Expand Down Expand Up @@ -70,30 +71,34 @@ private void updateLeaderboard(ButtonInteractionEvent event, int currentPage) {

for (Level level : top) {
int userLevel = level.getCurrentLevel();
String effectiveName = event.getGuild().getMemberById(level.getId()).getEffectiveName();
Member memberById = event.getGuild().getMemberById(level.getId());

leaderboardContent.append(this.leaderboardService.formatLeaderboardEntry(index, effectiveName, userLevel)).append("\n");
index++;
if (memberById != null) {
String effectiveName = memberById.getEffectiveName();

leaderboardContent.append(this.leaderboardService.formatLeaderboardEntry(index, effectiveName, userLevel)).append("\n");
index++;
}
}

Button firstButton = Button.success("leaderboard_first", "First")
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(currentPage == 1);
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(currentPage == 1);

Button prevButton = Button.primary("leaderboard_prev", "Previous")
.withEmoji(Emoji.fromFormatted("U+25C0"))
.withDisabled(currentPage <= 1);
.withEmoji(Emoji.fromFormatted("U+25C0"))
.withDisabled(currentPage <= 1);

Button nextButton = Button.primary("leaderboard_next", "Next")
.withEmoji(Emoji.fromUnicode("U+25B6"))
.withDisabled(currentPage >= totalPages);
.withEmoji(Emoji.fromUnicode("U+25B6"))
.withDisabled(currentPage >= totalPages);

Button lastButton = Button.success("leaderboard_last", "Last")
.withEmoji(Emoji.fromUnicode("U+23ED"))
.withDisabled(currentPage == totalPages);
.withEmoji(Emoji.fromUnicode("U+23ED"))
.withDisabled(currentPage == totalPages);

event.editMessageEmbeds(embedBuilder.setDescription(leaderboardContent.toString()).build())
.setActionRow(firstButton, prevButton, nextButton, lastButton)
.queue();
.setActionRow(firstButton, prevButton, nextButton, lastButton)
.queue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jagrosh.jdautilities.command.SlashCommand;
import com.jagrosh.jdautilities.command.SlashCommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.entities.emoji.Emoji;

Expand Down Expand Up @@ -45,30 +46,34 @@ public void execute(SlashCommandEvent event) {

for (Level level : top) {
int userLevel = level.getCurrentLevel();
String effectiveName = event.getGuild().getMemberById(level.getId()).getEffectiveName();
Member memberById = event.getGuild().getMemberById(level.getId());

leaderboardContent.append(this.leaderboardService.formatLeaderboardEntry(index, effectiveName, userLevel)).append("\n");
index++;
if (memberById != null) {
String effectiveName = memberById.getEffectiveName();

leaderboardContent.append(this.leaderboardService.formatLeaderboardEntry(index, effectiveName, userLevel)).append("\n");
index++;
}
}

Button firstButton = Button.success("leaderboard_first", "First")
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(page == 1);
.withEmoji(Emoji.fromUnicode("U+23EE"))
.withDisabled(page == 1);

Button prevButton = Button.primary("leaderboard_prev", "Previous")
.withEmoji(Emoji.fromFormatted("U+25C0"))
.withDisabled(page <= 1);
.withEmoji(Emoji.fromFormatted("U+25C0"))
.withDisabled(page <= 1);

Button nextButton = Button.primary("leaderboard_next", "Next")
.withEmoji(Emoji.fromUnicode("U+25B6"))
.withDisabled(page >= totalPages);
.withEmoji(Emoji.fromUnicode("U+25B6"))
.withDisabled(page >= totalPages);

Button lastButton = Button.success("leaderboard_last", "Last")
.withEmoji(Emoji.fromUnicode("U+23ED"))
.withDisabled(page == totalPages);
.withEmoji(Emoji.fromUnicode("U+23ED"))
.withDisabled(page == totalPages);

event.replyEmbeds(embedBuilder.setDescription(leaderboardContent.toString()).build())
.addActionRow(firstButton, prevButton, nextButton, lastButton)
.queue();
.addActionRow(firstButton, prevButton, nextButton, lastButton)
.queue();
}
}