Small fix to command sources

This commit is contained in:
Chipmunk 2023-01-22 16:45:04 -05:00
parent 0341df11f2
commit f7f1df7d4d

View file

@ -4,11 +4,14 @@ import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkbot.ChipmunkBot; import land.chipmunk.chipmunkbot.ChipmunkBot;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import lombok.Getter; import lombok.Getter;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
public class CommandSource { public class CommandSource {
private static final SimpleCommandExceptionType PLAYER_NOT_FOUND = new SimpleCommandExceptionType(ComponentMessage.wrap(Component.translatable("argument.entity.notfound.player")));
@Getter private final ChipmunkBot client; @Getter private final ChipmunkBot client;
// ? Should I support message objects? // ? Should I support message objects?
@ -19,9 +22,9 @@ public class CommandSource {
public MutablePlayerListEntry player () { return null; } public MutablePlayerListEntry player () { return null; }
public MutablePlayerListEntry playerOrThrow () { public MutablePlayerListEntry playerOrThrow () throws CommandSyntaxException {
MutablePlayerListEntry player = player(); MutablePlayerListEntry player = player();
// if (player == null) throw new CommandSyntaxException(Component.text("Command must be executed by a player")); if (player == null) throw PLAYER_NOT_FOUND.create();
return player; return player;
} }
} }