Skip to content

Commit

Permalink
Fix commands throwing a wrong IllegalAccessError
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Feb 26, 2025
1 parent 70c8098 commit a5e160b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package de.bluecolored.bluemap.common.commands;

import com.mojang.brigadier.Message;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import de.bluecolored.bluecommands.ParseFailure;
Expand All @@ -35,6 +36,7 @@
import java.util.Comparator;

public class BrigadierExecutionHandler extends CommandExecutor implements CommandExecutionHandler<CommandSource, Object> {
private static final Message DEFAULT_FAILURE_MESSAGE = () -> "Unknown or incomplete command!";

public BrigadierExecutionHandler(Plugin plugin) {
super(plugin);
Expand All @@ -51,7 +53,10 @@ public int handle(ParseResult<CommandSource, Object> parseResult) throws Command
private int parseFailure(ParseResult<CommandSource, Object> result) throws CommandSyntaxException {
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
.max(Comparator.comparing(ParseFailure::getPosition))
.orElseThrow(IllegalAccessError::new);
.orElseThrow(() -> new CommandSyntaxException(
new SimpleCommandExceptionType(DEFAULT_FAILURE_MESSAGE),
DEFAULT_FAILURE_MESSAGE
));
throw new CommandSyntaxException(
new SimpleCommandExceptionType(failure::getReason),
failure::getReason,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
adventure = "4.17.0"
bluecommands = "1.3.2"
bluecommands = "1.3.3"
bstats = "2.2.1"
configurate = "4.1.2"
junit = "5.8.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
CommandExecutor.ExecutionResult executionResult = commandExecutor.execute(result);

if (executionResult.parseFailure()) {
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
result.getFailures().stream()
.max(Comparator.comparing(ParseFailure::getPosition))
.orElseThrow(IllegalAccessError::new);
context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR));
.ifPresent(failure -> context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR)));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ public CommandResult process(CommandCause cause, ArgumentReader.Mutable argument
CommandExecutor.ExecutionResult executionResult = commandExecutor.execute(result);

if (executionResult.parseFailure()) {
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
result.getFailures().stream()
.max(Comparator.comparing(ParseFailure::getPosition))
.orElseThrow(IllegalAccessError::new);
context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR));
.ifPresent(failure -> context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR)));
return CommandResult.builder()
.result(0)
.build();
Expand Down

0 comments on commit a5e160b

Please sign in to comment.