use of com.mcsimonflash.sponge.cmdscheduler.task.CommandTask in project CmdScheduler by SimonFlash.
the class Create method create.
public static CommandResult create(CommandSource src, CommandContext args, Function<CommandContext, Schedule> function) throws CommandException {
String name = args.<String>getOne("name").get();
if (Config.tasks.containsKey(name.toLowerCase())) {
throw new CommandException(Text.of("A task already exists with name " + name + "."));
}
try {
CommandTask task = new CommandTask(name, args.<String>getOne("command").get(), function.apply(args), args.<Tristate>getOne("async").orElse(Tristate.UNDEFINED));
Config.tasks.put(task.getName().toLowerCase(), task);
src.sendMessage(Text.of("Successfully created task " + task.getName() + ". For this task to persist, it must be added to the config manually."));
if (args.hasAny("start")) {
task.getTask().start(CmdScheduler.get().getContainer());
src.sendMessage(Text.of("Task " + task.getName() + " has been started."));
}
return CommandResult.success();
} catch (IllegalArgumentException e) {
throw new CommandException(Text.of(e.getMessage()));
}
}
Aggregations