Attempting to queue while in a match throws an exception. #4

Open
opened 2022-07-06 13:11:53 +00:00 by LogalDeveloper · 0 comments

If a match participant runs /sb, they receive an internal error message and a stacktrace is printed to console.

The root cause is the join_queue command handler neglects to check if the player is in a match.

/**
* Joins or removes the player from the queue.
*
* @param sender The user who executed the command.
*/
@Command(hook = "join_queue")
public void commandJoinQueue(CommandSender sender){
MatchManager matchManager = this.snowbrawl.getMatchManager();
Player player = (Player) sender;
if (matchManager.isInQueue(player)){
matchManager.removeFromQueue(player);
sender.sendMessage(successMessage("You have been removed from the queue."));
} else {
matchManager.addToQueue(player);
sender.sendMessage(successMessage("You have been added to the queue."));
}
}

Luckily, nothing actually breaks. A lower level check is performed by the MatchManager which prevents the player from actually joining the queue.

if (this.getMatchFromPlayer(player) != null){
throw new IllegalStateException("A player cannot be in a match and in the queue at the same time.");
}

The fix is to add another check to the command handler for whether the player is in a match, and if so, print a more useful error message.

If a match participant runs `/sb`, they receive an internal error message and a stacktrace is printed to console. The root cause is the `join_queue` command handler neglects to check if the player is in a match. https://git.logal.dev/LogalDeveloper/Snowbrawl/src/commit/8102c217bb441af8397ebbc5052af0cb09e74bb3/src/main/java/dev/logal/snowbrawl/CommandHandler.java#L60-L77 Luckily, nothing actually breaks. A lower level check is performed by the MatchManager which prevents the player from actually joining the queue. https://git.logal.dev/LogalDeveloper/Snowbrawl/src/commit/8102c217bb441af8397ebbc5052af0cb09e74bb3/src/main/java/dev/logal/snowbrawl/managers/MatchManager.java#L62-L64 The fix is to add another check to the command handler for whether the player is in a match, and if so, print a more useful error message.
LogalDeveloper added the
Bug
label 2022-07-06 13:11:53 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: LogalDeveloper/Snowbrawl#4
No description provided.