From 174a9737d0b673d7c07b97e5beeaee134d87626e Mon Sep 17 00:00:00 2001 From: beanbeanjuice Date: Thu, 4 Jul 2024 02:39:04 -0400 Subject: [PATCH] Fixed the TicTacToe Ordering Bug --- .../cafebot/commands/games/TicTacToeCommand.java | 10 +++++++++- .../utility/sections/game/TicTacToeListener.java | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java index ac0a9c98..c77593a6 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java @@ -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; @@ -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 { @@ -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(); diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/game/TicTacToeListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/game/TicTacToeListener.java index 309f8e58..a066c893 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/sections/game/TicTacToeListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/sections/game/TicTacToeListener.java @@ -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) {