Skip to content

Commit a5e160b

Browse files
committed
Fix commands throwing a wrong IllegalAccessError
1 parent 70c8098 commit a5e160b

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

common/src/main/java/de/bluecolored/bluemap/common/commands/BrigadierExecutionHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package de.bluecolored.bluemap.common.commands;
2626

27+
import com.mojang.brigadier.Message;
2728
import com.mojang.brigadier.exceptions.CommandSyntaxException;
2829
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
2930
import de.bluecolored.bluecommands.ParseFailure;
@@ -35,6 +36,7 @@
3536
import java.util.Comparator;
3637

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

3941
public BrigadierExecutionHandler(Plugin plugin) {
4042
super(plugin);
@@ -51,7 +53,10 @@ public int handle(ParseResult<CommandSource, Object> parseResult) throws Command
5153
private int parseFailure(ParseResult<CommandSource, Object> result) throws CommandSyntaxException {
5254
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
5355
.max(Comparator.comparing(ParseFailure::getPosition))
54-
.orElseThrow(IllegalAccessError::new);
56+
.orElseThrow(() -> new CommandSyntaxException(
57+
new SimpleCommandExceptionType(DEFAULT_FAILURE_MESSAGE),
58+
DEFAULT_FAILURE_MESSAGE
59+
));
5560
throw new CommandSyntaxException(
5661
new SimpleCommandExceptionType(failure::getReason),
5762
failure::getReason,

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[versions]
22
adventure = "4.17.0"
3-
bluecommands = "1.3.2"
3+
bluecommands = "1.3.3"
44
bstats = "2.2.1"
55
configurate = "4.1.2"
66
junit = "5.8.2"

implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitCommands.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab
114114
CommandExecutor.ExecutionResult executionResult = commandExecutor.execute(result);
115115

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

implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongeCommands.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ public CommandResult process(CommandCause cause, ArgumentReader.Mutable argument
7878
CommandExecutor.ExecutionResult executionResult = commandExecutor.execute(result);
7979

8080
if (executionResult.parseFailure()) {
81-
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
81+
result.getFailures().stream()
8282
.max(Comparator.comparing(ParseFailure::getPosition))
83-
.orElseThrow(IllegalAccessError::new);
84-
context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR));
83+
.ifPresent(failure -> context.sendMessage(text(failure.getReason()).color(NEGATIVE_COLOR)));
8584
return CommandResult.builder()
8685
.result(0)
8786
.build();

0 commit comments

Comments
 (0)