port too many arguments back
mess and i'm not sure if i did the correct numbers for every command because uh my brain is kinda broken
This commit is contained in:
parent
364afb0879
commit
8b61ed93aa
18 changed files with 106 additions and 8 deletions
|
@ -35,6 +35,7 @@ public class CommandContext {
|
|||
public Component displayName () { return Component.empty(); }
|
||||
public void sendOutput (Component component) {}
|
||||
|
||||
// args parsing stuff
|
||||
private int argsPosition = 0;
|
||||
|
||||
public String getString (boolean greedy, boolean required) throws CommandException { return getString(greedy, required, "string"); }
|
||||
|
@ -128,4 +129,13 @@ public class CommandContext {
|
|||
throw new CommandException(Component.text("Invalid enum"));
|
||||
}
|
||||
}
|
||||
|
||||
public void checkOverloadArgs (int maximumArgs) throws CommandException {
|
||||
if (args.length > maximumArgs) throw new CommandException(
|
||||
Component.translatable(
|
||||
"Too many arguments, expected %s max",
|
||||
Component.text(maximumArgs)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ public class BotVisibilityCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final String action = context.getString(false, false, false);
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
|
@ -19,7 +20,9 @@ public class ClearChatQueueCommand extends Command {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandContext context) {
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(0);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
bot.chat.clearQueue();
|
||||
|
|
|
@ -48,6 +48,8 @@ public class CloopCommand extends Command {
|
|||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "remove" -> {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
try {
|
||||
final int index = context.getInteger(true);
|
||||
bot.cloop.remove(index);
|
||||
|
@ -61,10 +63,14 @@ public class CloopCommand extends Command {
|
|||
}
|
||||
}
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.cloop.clear();
|
||||
return Component.text("Cleared all cloops").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final List<Component> cloopsComponent = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
|
|
|
@ -65,6 +65,8 @@ public class ConsoleCommand extends Command {
|
|||
}
|
||||
}
|
||||
case "logtoconsole" -> {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final boolean bool = context.getBoolean(true);
|
||||
|
||||
bot.logger.logToConsole = bool;
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
|
@ -19,7 +20,9 @@ public class EndCommand extends Command {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandContext context) {
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(0);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
bot.session.disconnect("End command");
|
||||
|
|
|
@ -77,6 +77,8 @@ public class FilterCommand extends Command {
|
|||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "remove" -> {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
try {
|
||||
final int index = context.getInteger(true);
|
||||
|
||||
|
@ -91,10 +93,14 @@ public class FilterCommand extends Command {
|
|||
}
|
||||
}
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.filter.clear();
|
||||
return Component.text("Cleared the filter").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final List<Component> filtersComponents = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
|
|
|
@ -33,9 +33,11 @@ public class HelpCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
this.context = context;
|
||||
|
||||
final String commandName = context.getString(true, false);
|
||||
final String commandName = context.getString(false, false);
|
||||
|
||||
if (commandName.isEmpty()) {
|
||||
return sendCommandList();
|
||||
|
|
|
@ -50,6 +50,8 @@ public class IPFilterCommand extends Command {
|
|||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "remove" -> {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
try {
|
||||
final int index = context.getInteger(true);
|
||||
|
||||
|
@ -64,10 +66,14 @@ public class IPFilterCommand extends Command {
|
|||
}
|
||||
}
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.ipFilter.clear();
|
||||
return Component.text("Cleared the filter").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final List<Component> filtersComponents = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
|
|
|
@ -45,6 +45,8 @@ public class InfoCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final String action = context.getString(false, true, true);
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
|
@ -28,7 +29,9 @@ public class ListCommand extends Command {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandContext context) {
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(0);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final List<PlayerEntry> list = bot.players.list;
|
||||
|
|
|
@ -83,6 +83,8 @@ public class MailCommand extends Command {
|
|||
return Component.text("Mail sent!").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "sendselecteditem" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
int senderMailsSentTotal = 0;
|
||||
for (JsonElement mailElement : MailPlugin.mails) {
|
||||
final Mail mail = gson.fromJson(mailElement, Mail.class);
|
||||
|
@ -154,6 +156,8 @@ public class MailCommand extends Command {
|
|||
});
|
||||
}
|
||||
case "read" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
// TODO: use less for loops?
|
||||
|
||||
int senderMailSize = 0;
|
||||
|
|
|
@ -197,6 +197,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component playFromItem (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
// mail command lol
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
@ -258,6 +260,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component playSongPlayer (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
// dupe codes ??
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
@ -318,7 +322,9 @@ public class MusicCommand extends Command {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Component stop (CommandContext context) {
|
||||
public Component stop (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
bot.music.stopPlaying();
|
||||
bot.music.songQueue.clear();
|
||||
|
@ -327,6 +333,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component loop (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final Loop loop = context.getEnum(Loop.class);
|
||||
|
@ -427,6 +435,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component skip (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final MusicPlayerPlugin music = bot.music;
|
||||
if (music.currentSong == null) throw new CommandException(Component.text("No song is currently playing"));
|
||||
|
@ -444,6 +454,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component nowplaying (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final Song song = bot.music.currentSong;
|
||||
if (song == null) throw new CommandException(Component.text("No song is currently playing"));
|
||||
|
@ -454,7 +466,9 @@ public class MusicCommand extends Command {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
|
||||
public Component queue (CommandContext context) {
|
||||
public Component queue (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final List<Song> queue = bot.music.songQueue;
|
||||
|
||||
|
@ -493,6 +507,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component pitch (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final float pitch = context.getFloat(true);
|
||||
|
@ -506,6 +522,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component speed (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final Song currentSong = bot.music.currentSong;
|
||||
|
||||
|
@ -528,6 +546,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component amplify(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final int amplify = context.getInteger(true);
|
||||
|
@ -560,6 +580,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component pause (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final Song currentSong = bot.music.currentSong;
|
||||
|
||||
|
@ -575,6 +597,8 @@ public class MusicCommand extends Command {
|
|||
}
|
||||
|
||||
public Component info (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
final Song currentSong = bot.music.currentSong;
|
||||
|
||||
|
@ -594,7 +618,9 @@ public class MusicCommand extends Command {
|
|||
return Component.join(JoinConfiguration.newlines(), components);
|
||||
}
|
||||
|
||||
public Component testSong (CommandContext context) {
|
||||
public Component testSong (CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final Song song = new Song(
|
||||
|
|
|
@ -25,6 +25,8 @@ public class RandomTeleportCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(0);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final PlayerEntry sender = context.sender;
|
||||
|
|
|
@ -3,6 +3,7 @@ package land.chipmunk.chayapak.chomens_bot.commands;
|
|||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
|
@ -19,7 +20,9 @@ public class RefillCoreCommand extends Command {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandContext context) {
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(0);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
bot.core.reset();
|
||||
|
|
|
@ -35,6 +35,8 @@ public class ScreenshareCommand extends Command {
|
|||
try {
|
||||
switch (action) {
|
||||
case "start" -> {
|
||||
context.checkOverloadArgs(4);
|
||||
|
||||
final int x = context.getInteger(true);
|
||||
final int y = context.getInteger(true);
|
||||
final int z = context.getInteger(true);
|
||||
|
@ -46,6 +48,8 @@ public class ScreenshareCommand extends Command {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "stop" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.screenshare.stop();
|
||||
|
||||
return Component
|
||||
|
@ -53,6 +57,8 @@ public class ScreenshareCommand extends Command {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "setres" -> {
|
||||
context.checkOverloadArgs(3);
|
||||
|
||||
final int width = context.getInteger(true);
|
||||
final int height = context.getInteger(true);
|
||||
|
||||
|
@ -67,6 +73,8 @@ public class ScreenshareCommand extends Command {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "setfps" -> {
|
||||
context.checkOverloadArgs(2);
|
||||
|
||||
final int fps = context.getInteger(true);
|
||||
|
||||
bot.screenshare.fps = fps;
|
||||
|
|
|
@ -23,6 +23,8 @@ public class TPSBarCommand extends Command {
|
|||
|
||||
@Override
|
||||
public Component execute(CommandContext context) throws CommandException {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final Bot bot = context.bot;
|
||||
|
||||
final String action = context.getString(false, true, true);
|
||||
|
|
|
@ -33,11 +33,15 @@ public class WhitelistCommand extends Command {
|
|||
|
||||
switch (action) {
|
||||
case "enable" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.whitelist.enable();
|
||||
|
||||
return Component.text("Enabled whitelist").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "disable" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.whitelist.disable();
|
||||
|
||||
return Component.text("Disabled whitelist").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
|
@ -67,11 +71,15 @@ public class WhitelistCommand extends Command {
|
|||
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
bot.whitelist.clear();
|
||||
|
||||
return Component.text("Cleared the whitelist").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
|
||||
}
|
||||
case "list" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
final List<Component> playersComponent = new ArrayList<>();
|
||||
|
||||
int index = 0;
|
||||
|
|
Loading…
Reference in a new issue