delete commandargumentexception and return usage instead

This commit is contained in:
spacerocket62 2022-02-06 19:53:35 -08:00
parent e328cf29e5
commit 282da7fdbb
9 changed files with 11 additions and 26 deletions

View File

@ -178,10 +178,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{ {
send(sender, component); send(sender, component);
} }
} catch (CommandArgumentException ex) }
{ catch (PlayerNotFoundException | CommandFailException
send(sender, getUsage());
} catch (PlayerNotFoundException | CommandFailException
| ConsoleOnlyException | ConsoleMustDefinePlayerException | ConsoleOnlyException | ConsoleMustDefinePlayerException
| PlayerNotBannedException ex) | PlayerNotBannedException ex)
{ {

View File

@ -1,5 +0,0 @@
package dev.plex.command.exception;
public class CommandArgumentException extends RuntimeException
{
} // lolololol

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List; import java.util.List;
@ -23,7 +22,7 @@ public class DeopCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
player.setOp(false); player.setOp(false);

View File

@ -5,7 +5,6 @@ import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.player.PunishedPlayer; import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
@ -13,11 +12,9 @@ import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang.time.DateUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -32,7 +29,7 @@ public class FreezeCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());

View File

@ -5,7 +5,6 @@ import com.google.common.collect.Lists;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.MojangUtils; import dev.plex.util.MojangUtils;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
@ -36,7 +35,7 @@ public class NameHistoryCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
String username = args[0]; String username = args[0];

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List; import java.util.List;
@ -23,7 +22,7 @@ public class OpCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
player.setOp(true); player.setOp(true);

View File

@ -5,7 +5,6 @@ import dev.plex.Plex;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
@ -54,7 +53,7 @@ public class PlexCMD extends PlexCommand
} }
else else
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
return null; return null;
} }

View File

@ -5,18 +5,18 @@ import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.exception.CommandFailException; import dev.plex.command.exception.CommandFailException;
import dev.plex.player.PunishedPlayer; import dev.plex.player.PunishedPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unfreeze") @CommandPermissions(level = Rank.ADMIN, permission = "plex.unfreeze")
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>") @CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
public class UnfreezeCMD extends PlexCommand public class UnfreezeCMD extends PlexCommand
@ -26,7 +26,7 @@ public class UnfreezeCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());

View File

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandArgumentException;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import java.util.List; import java.util.List;
@ -27,7 +26,7 @@ public class WorldCMD extends PlexCommand
{ {
if (args.length != 1) if (args.length != 1)
{ {
throw new CommandArgumentException(); return usage(getUsage());
} }
World world = getNonNullWorld(args[0]); World world = getNonNullWorld(args[0]);
playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0)); playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));