Hi,
Im new when it comes to Java / Spongepowered. I wrote a method:
@Override
public Optional<CommandResult> process(CommandSource source, String arg_string) throws CommandException {
//Check if source has permission
if(!source.hasPermission("account.use")) {
source.sendMessage(Texts.builder("Keine Berechtigungen!").color(TextColors.RED).build());
return Optional.of(CommandResult.builder().successCount(0).build());
}
String[] args = arg_string.split(" ");
if(args.length<3){
source.sendMessage(Texts.builder("Verwendung: /account new <mail> <password>").color(TextColors.GRAY).build());
return Optional.of(CommandResult.builder().successCount(0).build());
}
if(args[0].equalsIgnoreCase("new")){
String user_mail = args[1];
String user_pass = args[2];
String name = source.getName();
String uuid = source.getIdentifier();
if(dataEditor.accountExists(uuid)){
source.sendMessage(Texts.builder("Dieser Account ist bereits registriert!").style(TextStyles.BOLD).color(TextColors.RED).build());
source.sendMessage(Texts.builder(" Fragen? Kontaktiere den Support auf http://the-cave.net").color(TextColors.GRAY).build());
//here i want to run a cmd command!
}else{
if(mailValidator.isEmail(user_mail)) {
if (dataEditor.addCaveAccount(user_mail, user_pass, name, uuid)) {
source.sendMessage(Texts.builder("Dein Account wurde registriert!").style(TextStyles.BOLD).color(TextColors.GREEN).build());
source.sendMessage(Texts.builder(" Du kannst dich ab sofort mit deiner Mail").color(TextColors.GRAY).build());
source.sendMessage(Texts.builder(" oder deinem Minecraft-Namen & deinem Passwort").color(TextColors.GRAY).build());
source.sendMessage(Texts.builder(" auf http://the-cave.net anmelden!").color(TextColors.GRAY).build());
return Optional.of(CommandResult.success());
}
}else{
source.sendMessage(Texts.builder("Account konnte nicht erstellt werden").style(TextStyles.BOLD).color(TextColors.RED).build());
source.sendMessage(Texts.builder(" Bitte gib eine valide E-Mail an!").color(TextColors.GRAY).build());
}
}
return Optional.of(CommandResult.builder().successCount(0).build());
}else{
//Invalid first argument
source.sendMessage(Texts.builder("Verwendung: /account new <mail> <password>").color(TextColors.RED).build());
return Optional.of(CommandResult.builder().successCount(0).build());
}
}
I have marked, where i want to run a cmd command -> “//here i want to run a cmd command!”. My problem is, that i have no clue, how i can use getGame(); there, because i havent an event to use it. I have read the API, but there is no detailed information about that.
My class: public class Commands implements CommandCallable
Thanks for helping,
Greets