Skip to content

Commit

Permalink
Fixed the TicTacToe Ordering Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Jul 4, 2024
1 parent 62b1344 commit 174a973
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.beanbeanjuice.cafebot.utility.commands.Command;
import com.beanbeanjuice.cafebot.utility.commands.CommandCategory;
import com.beanbeanjuice.cafebot.utility.commands.ICommand;
import com.beanbeanjuice.cafebot.utility.helper.Helper;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.emoji.Emoji;
Expand All @@ -12,7 +13,6 @@
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;

public class TicTacToeCommand extends Command implements ICommand {

Expand All @@ -25,6 +25,14 @@ public void handle(SlashCommandInteractionEvent event) {
// cafeBot:tictactoe:index:user1:user2
User opponent = event.getOption("opponent").getAsUser();

if (opponent.isBot()) {
event.getHook().sendMessageEmbeds(Helper.errorEmbed(
"Cannot Play Against Bot",
"What do you think you're even doing?"
)).queue();
return;
}

String playerID = event.getUser().getId();
String opponentID = opponent.getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void onButtonInteraction(ButtonInteractionEvent event) {

Guild guild = event.getGuild();
guild.retrieveMembersByIds(player1ID, player2ID).onSuccess((members) -> {
Member player1 = members.get(0);
Member player2 = members.get(1);
Member player1 = members.get(0).getId().equals(player1ID) ? members.get(0) : members.get(1);
Member player2 = members.get(1).getId().equals(player2ID) ? members.get(1) : members.get(0);
boolean isPlayer1 = currentPerson.getId().equals(player1ID);

if (player1 == null || player2 == null) {
Expand Down

0 comments on commit 174a973

Please sign in to comment.