Verified Commit dfab076d authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Don't crash on lack of permissions

parent 643029fc
Pipeline #391 passed with stages
in 4 minutes and 2 seconds
package team.aura_dev.aurasudo.platform.bungeecord.command;
import java.util.Arrays;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import team.aura_dev.aurasudo.api.player.PlayerManager;
......@@ -28,7 +27,6 @@ public class CommandWrapperBungeeCord extends Command {
@Override
public void execute(CommandSender sender, String[] args) {
// Sadly we don't know the alias being used, so we need to pass the base command
command.execute(
playerManager.fromNativePlayer(sender), command.getBaseCommand(), Arrays.asList(args));
command.call(playerManager.fromNativePlayer(sender), command.getBaseCommand(), args);
}
}
......@@ -40,6 +40,30 @@ public abstract class BaseCommand {
return aliases.toArray(new String[] {});
}
public abstract void execute(PlayerDataCommon player, String alias, List<String> arguments)
public final boolean call(PlayerDataCommon player, String alias, String commandLine) {
return call(player, alias, commandLine.split(" "));
}
public final boolean call(PlayerDataCommon player, String alias, String[] arguments) {
return call(player, alias, Arrays.asList(arguments));
}
public final boolean call(PlayerDataCommon player, String alias, Collection<String> arguments) {
try {
execute(
player,
alias,
(arguments instanceof List) ? ((List<String>) arguments) : new ArrayList<>(arguments));
} catch (CommandExecutionException e) {
// TODO replace with player call once it exists
System.out.println(e.getMessageComponent());
return false;
}
return true;
}
protected abstract void execute(PlayerDataCommon player, String alias, List<String> arguments)
throws CommandExecutionException;
}
......@@ -14,4 +14,8 @@ public class CommandExecutionException extends RuntimeException {
public CommandExecutionException(Throwable cause) {
super(cause);
}
public String getMessageComponent() {
return "Error :(";
}
}
......@@ -4,7 +4,7 @@ import javax.annotation.Nullable;
import lombok.Getter;
import team.aura_dev.aurasudo.platform.common.permission.Permission;
public class PermissionException extends RuntimeException {
public class PermissionException extends CommandExecutionException {
@Getter protected final Permission permission;
public PermissionException() {
......@@ -14,4 +14,9 @@ public class PermissionException extends RuntimeException {
public PermissionException(@Nullable Permission permission) {
this.permission = permission;
}
@Override
public String getMessageComponent() {
return "No permissions ;(";
}
}
......@@ -3,7 +3,6 @@ package team.aura_dev.aurasudo.platform.nukkit.command;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandData;
import java.util.Arrays;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
......@@ -32,8 +31,6 @@ public class CommandWrapperNukkit extends Command {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
command.execute(playerManager.fromNativePlayer(sender), commandLabel, Arrays.asList(args));
return true;
return command.call(playerManager.fromNativePlayer(sender), commandLabel, args);
}
}
package team.aura_dev.aurasudo.platform.spigot.command;
import java.util.Arrays;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import team.aura_dev.aurasudo.api.player.PlayerManager;
......@@ -28,8 +27,6 @@ public class CommandWrapperSpigot extends Command {
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
command.execute(playerManager.fromNativePlayer(sender), commandLabel, Arrays.asList(args));
return true;
return command.call(playerManager.fromNativePlayer(sender), commandLabel, args);
}
}
......@@ -32,11 +32,10 @@ public class CommandExecutorSponge implements CommandExecutor {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
// Sadly we don't know the alias being used, so we need to pass the base command
command.execute(
if (!command.call(
playerManager.fromNativePlayer(src),
command.getBaseCommand(),
new ArrayList(args.getAll(ARGS)));
return CommandResult.success();
new ArrayList(args.getAll(ARGS)))) throw new CommandException(Text.of(), false);
else return CommandResult.success();
}
}
package team.aura_dev.aurasudo.platform.velocity.command;
import com.velocitypowered.api.command.Command;
import com.velocitypowered.api.command.CommandSource;
import java.util.Arrays;
import com.velocitypowered.api.command.RawCommand;
import team.aura_dev.aurasudo.api.player.PlayerManager;
import team.aura_dev.aurasudo.platform.common.command.BaseCommand;
import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class CommandWrapperVelocity implements Command {
public class CommandWrapperVelocity implements RawCommand {
protected final PlayerManagerCommon playerManager;
protected final BaseCommand command;
......@@ -24,9 +22,11 @@ public class CommandWrapperVelocity implements Command {
}
@Override
public void execute(CommandSource source, String[] args) {
public void execute(Invocation invocation) {
// Sadly we don't know the alias being used, so we need to pass the base command
command.execute(
playerManager.fromNativePlayer(source), command.getBaseCommand(), Arrays.asList(args));
command.call(
playerManager.fromNativePlayer(invocation.source()),
invocation.alias(),
invocation.arguments());
}
}
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