Verified Commit 21a08e6a authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Better exception handling

And some formatting
parent 5014d763
......@@ -54,10 +54,14 @@ public abstract class BaseCommand {
public final boolean call(PlayerDataCommon player, String alias, Collection<String> arguments) {
try {
final List<String> argumentList =
(arguments instanceof List) ? ((List<String>) arguments) : new ArrayList<>(arguments);
execute(player, alias, argumentList);
try {
final List<String> argumentList =
(arguments instanceof List) ? ((List<String>) arguments) : new ArrayList<>(arguments);
execute(player, alias, argumentList);
} catch (RuntimeException e) {
throw new CommandExecutionException(e);
}
} catch (CommandExecutionException e) {
player.sendMessage(e.getMessageComponent());
......
......@@ -6,7 +6,7 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
public class CommandExecutionException extends RuntimeException {
public class CommandExecutionException extends Exception {
private final TextComponent message;
public CommandExecutionException() {
......
......@@ -13,10 +13,11 @@ public class SudoCommand extends BaseCommand {
@Override
public void execute(PlayerDataCommon player, String alias, List<String> arguments)
throws CommandExecutionException {
if (player.isConsole()) throw new CommandExecutionException("This command can only be executed by players!");
if (player.isConsole())
throw new CommandExecutionException("This command can only be executed by players!");
if (!player.hasPermission(COMMAND)) throw new PermissionException(COMMAND);
if(player.getSudoLevel() == 0) {
if (player.getSudoLevel() == 0) {
player.setSudoLevel(1);
player.sendMessage(Component.text("Enabled sudo mode", NamedTextColor.GREEN));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment