Search in sources :

Example 1 with InvalidSpellSettingException

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

the class SoliniaSpell method editSetting.

@Override
public void editSetting(String setting, String value, String[] additional) throws InvalidSpellSettingException, NumberFormatException, CoreStateInitException {
    String name = getName();
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidSpellSettingException("Name is empty");
            if (value.length() > 30)
                throw new InvalidSpellSettingException("Name is longer than 30 characters");
            setName(value);
            break;
        case "mana":
            if (value.equals(""))
                throw new InvalidSpellSettingException("mana is empty");
            int mana = Integer.parseInt(value);
            setMana(mana);
            break;
        case "duration":
            if (value.equals(""))
                throw new InvalidSpellSettingException("duration is empty");
            int buffduration = Integer.parseInt(value);
            setBuffduration(buffduration);
            break;
        case "spelleffectindex":
            setSpellAffectIndex(Integer.parseInt(value));
            break;
        case "effect":
            int effectNo = Integer.parseInt(value);
            if (effectNo < 1 || effectNo > 12)
                throw new InvalidSpellSettingException("EffectNo is not valid, must be between 1 and 12");
            if (additional.length < 2)
                throw new InvalidSpellSettingException("Missing effect setting and value to change, ie BASE 1");
            String effectSettingType = additional[0];
            int effectValue = Integer.parseInt(additional[1]);
            switch(effectNo) {
                case 1:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue1(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula1(effectValue);
                    }
                    break;
                case 2:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue2(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula2(effectValue);
                    }
                    break;
                case 3:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue3(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula3(effectValue);
                    }
                    break;
                case 4:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue4(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula4(effectValue);
                    }
                    break;
                case 5:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue5(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula5(effectValue);
                    }
                    break;
                case 6:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue6(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula6(effectValue);
                    }
                    break;
                case 7:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue7(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula7(effectValue);
                    }
                    break;
                case 8:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue8(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula8(effectValue);
                    }
                    break;
                case 9:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue9(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula9(effectValue);
                    }
                    break;
                case 10:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue10(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula10(effectValue);
                    }
                    break;
                case 11:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue11(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula11(effectValue);
                    }
                    break;
                case 12:
                    if (effectSettingType.equals("BASE")) {
                        this.setEffectBaseValue12(effectValue);
                    }
                    if (effectSettingType.equals("FORMULA")) {
                        this.setFormula12(effectValue);
                    }
                    break;
                default:
                    throw new InvalidSpellSettingException("EffectNo is not valid, must be between 1 and 12");
            }
            break;
        case "teleport_zone":
        case "teleportzone":
            try {
                String[] zonedata = value.split(",");
                // Dissasemble the value to ensure it is correct
                String world = zonedata[0];
                double x = Double.parseDouble(zonedata[1]);
                double y = Double.parseDouble(zonedata[2]);
                double z = Double.parseDouble(zonedata[3]);
                setTeleportZone(world + "," + x + "," + y + "," + z);
                break;
            } catch (Exception e) {
                throw new InvalidSpellSettingException("Teleport zone value must be in format: world,x,y,z");
            }
        case "skill":
            this.setSkill(Integer.parseInt(value));
            break;
        default:
            throw new InvalidSpellSettingException("Invalid Spell setting. Valid Options are: name");
    }
}
Also used : InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 2 with InvalidSpellSettingException

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

the class CommandEditSpell 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 spellid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
            if (spell != null) {
                spell.sendSpellSettingsToSender(sender);
            } else {
                sender.sendMessage("SPELL ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: spellid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (spellid < 1) {
        sender.sendMessage("Invalid spellid id");
        return false;
    }
    String[] additional = new String[0];
    if (args.length > 3) {
        additional = new String[args.length - 3];
        for (int i = 0; i < args.length; i++) {
            if (i < 3)
                continue;
            additional[i - 3] = args[i];
        }
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getSpell(spellid) == null) {
            sender.sendMessage("Cannot locate spell id: " + spellid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editSpell(spellid, setting, value, additional);
        sender.sendMessage("Updating setting on spell");
    } catch (InvalidSpellSettingException ne) {
        sender.sendMessage("Invalid Spell setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

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