2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launchserver.command;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2018-09-17 10:20:34 +03:00
|
|
|
import ru.gravit.utils.helper.VerifyHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
import ru.gravit.launchserver.LaunchServer;
|
|
|
|
|
|
|
|
public abstract class Command {
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected static String parseUsername(String username) throws CommandException {
|
|
|
|
try {
|
|
|
|
return VerifyHelper.verifyUsername(username);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
throw new CommandException(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected static UUID parseUUID(String s) throws CommandException {
|
|
|
|
try {
|
|
|
|
return UUID.fromString(s);
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
throw new CommandException(String.format("Invalid UUID: '%s'", s));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected final LaunchServer server;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected Command(LaunchServer server) {
|
|
|
|
this.server = server;
|
|
|
|
}
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract String getArgsDescription(); // "<required> [optional]"
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract String getUsageDescription();
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract void invoke(String... args) throws Exception;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected final void verifyArgs(String[] args, int min) throws CommandException {
|
|
|
|
if (args.length < min)
|
2018-09-22 17:33:00 +03:00
|
|
|
throw new CommandException("Command usage: " + getArgsDescription());
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|
|
|
|
}
|