Search in sources :

Example 1 with InvalidGodSettingException

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

the class CommandEditGod 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 (!sender.isOp() && !sender.hasPermission("solinia.editgod")) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int godid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaGod solgod = StateManager.getInstance().getConfigurationManager().getGod(godid);
            if (solgod != null) {
                solgod.sendGodSettingsToSender(sender);
            } else {
                sender.sendMessage("ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: godid 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 (godid < 1) {
        sender.sendMessage("Invalid god id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getGod(godid) == null) {
            sender.sendMessage("Cannot locate god id: " + godid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editGod(godid, setting, value);
        sender.sendMessage("Updating setting on god");
    } catch (InvalidGodSettingException ne) {
        sender.sendMessage("Invalid god setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidGodSettingException(com.solinia.solinia.Exceptions.InvalidGodSettingException) CommandSender(org.bukkit.command.CommandSender)

Example 2 with InvalidGodSettingException

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

the class SoliniaGod method editSetting.

@Override
public void editSetting(String setting, String value) throws InvalidGodSettingException, NumberFormatException, CoreStateInitException {
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidGodSettingException("Name is empty");
            setName(value);
            break;
        case "description":
            setDescription(value);
            break;
        case "alignment":
            if (!value.toUpperCase().equals("EVIL") && !value.toUpperCase().equals("NEUTRAL") && !value.toUpperCase().equals("GOOD"))
                throw new InvalidGodSettingException("Invalid Alignment (GOOD,NEUTRAL,EVIL)");
            setAlignment(value.toUpperCase());
            break;
        case "passiveabilityid":
            int abilityid = Integer.parseInt(value);
            if (abilityid < 1) {
                setPassiveAbilityId(0);
                break;
            }
            try {
                ISoliniaSpell ability = StateManager.getInstance().getConfigurationManager().getSpell(abilityid);
                if (ability == null)
                    throw new InvalidGodSettingException("Invalid id");
                if (!ability.isBuffSpell() || !SpellUtils.getSpellTargetType(ability.getTargettype()).equals(SpellTargetType.Self))
                    throw new InvalidGodSettingException("Only Self only buff type spells can be set as a passive spell");
            } catch (CoreStateInitException e) {
                throw new InvalidGodSettingException("State not initialised");
            }
            setPassiveAbilityId(abilityid);
            break;
        default:
            throw new InvalidGodSettingException("Invalid setting. Valid Options are: name,description");
    }
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidGodSettingException(com.solinia.solinia.Exceptions.InvalidGodSettingException)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 InvalidGodSettingException (com.solinia.solinia.Exceptions.InvalidGodSettingException)2 ISoliniaGod (com.solinia.solinia.Interfaces.ISoliniaGod)1 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1