Search in sources :

Example 1 with InvalidRaceSettingException

use of com.solinia.solinia.Exceptions.InvalidRaceSettingException in project solinia3-core by mixxit.

the class CommandEditRace method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int raceid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaRace solrace = StateManager.getInstance().getConfigurationManager().getRace(raceid);
            if (solrace != null) {
                solrace.sendRaceSettingsToSender(sender);
            } else {
                sender.sendMessage("RACE ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: raceid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && setting.toLowerCase().contains("description")) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (raceid < 1) {
        sender.sendMessage("Invalid race id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getRace(raceid) == null) {
            sender.sendMessage("Cannot locate race id: " + raceid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editRace(raceid, setting, value);
        sender.sendMessage("Updating setting on race");
    } catch (InvalidRaceSettingException ne) {
        sender.sendMessage("Invalid race setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidRaceSettingException(com.solinia.solinia.Exceptions.InvalidRaceSettingException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 InvalidRaceSettingException (com.solinia.solinia.Exceptions.InvalidRaceSettingException)1 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1