Search in sources :

Example 1 with InvalidCraftSettingException

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

the class SoliniaCraft method editSetting.

public void editSetting(String setting, String value) throws InvalidCraftSettingException, NumberFormatException, CoreStateInitException {
    switch(setting.toLowerCase()) {
        case "recipename":
            if (value.equals(""))
                throw new InvalidCraftSettingException("Name is empty");
            if (StateManager.getInstance().getConfigurationManager().getCraft(value.toUpperCase()) != null)
                throw new InvalidCraftSettingException("Recipe already exists with this name");
            setRecipeName(value.toUpperCase());
            break;
        case "classid":
            ISoliniaClass classObj = StateManager.getInstance().getConfigurationManager().getClassObj(Integer.parseInt(value));
            if (classObj == null)
                throw new InvalidCraftSettingException("Class does not exist");
            setClassId(Integer.parseInt(value));
            break;
        case "skilltype":
            setSkilltype(SkillType.valueOf(value));
            break;
        case "minskill":
            if (Integer.parseInt(value) < 0)
                throw new InvalidCraftSettingException("Skill must be greater than or equal to 0");
            setMinSkill(Integer.parseInt(value));
            break;
        case "item1":
            int itemId1 = Integer.parseInt(value);
            ISoliniaItem solitem1 = StateManager.getInstance().getConfigurationManager().getItem(itemId1);
            if (solitem1 == null) {
                throw new InvalidCraftSettingException("Invalid item id (in item 1)");
            }
            setItem1(itemId1);
            break;
        case "item2":
            int itemId2 = Integer.parseInt(value);
            ISoliniaItem solitem2 = StateManager.getInstance().getConfigurationManager().getItem(itemId2);
            if (solitem2 == null) {
                throw new InvalidCraftSettingException("Invalid item id (in item 2)");
            }
            setItem2(itemId2);
            break;
        case "outputitem":
            int outputitem = Integer.parseInt(value);
            ISoliniaItem soloutitem = StateManager.getInstance().getConfigurationManager().getItem(outputitem);
            if (soloutitem == null) {
                throw new InvalidCraftSettingException("Invalid item id (out item)");
            }
            setOutputItem(outputitem);
            break;
        default:
            throw new InvalidCraftSettingException("Invalid zone setting. Valid Options are: recipename,item1,item2,outputitem");
    }
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) InvalidCraftSettingException(com.solinia.solinia.Exceptions.InvalidCraftSettingException)

Example 2 with InvalidCraftSettingException

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

the class CommandEditCraft 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.hasPermission("solinia.editcraft")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: craftid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int craftid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            SoliniaCraft craft = StateManager.getInstance().getConfigurationManager().getCraft(craftid);
            if (craft != null) {
                craft.sendCraftSettingsToSender(sender);
            } else {
                sender.sendMessage("Craft ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: craftid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (craftid < 1) {
        sender.sendMessage("Invalid craftid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getCraft(craftid) == null) {
            sender.sendMessage("Cannot locate craft id: " + craftid);
            return false;
        }
        /*if (StateManager.getInstance().getConfigurationManager().getCraft(craftid).isOperatorCreated() && !sender.isOp())
			{
				sender.sendMessage("This craft was op created and you are not an op. Only ops can edit op craft items");
				return false;
			}*/
        StateManager.getInstance().getConfigurationManager().editCraft(craftid, setting, value);
        sender.sendMessage("Updating setting on Craft");
    } catch (InvalidCraftSettingException ne) {
        sender.sendMessage("Invalid craft 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) SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) CommandSender(org.bukkit.command.CommandSender) InvalidCraftSettingException(com.solinia.solinia.Exceptions.InvalidCraftSettingException)

Aggregations

InvalidCraftSettingException (com.solinia.solinia.Exceptions.InvalidCraftSettingException)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)1 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)1 SoliniaCraft (com.solinia.solinia.Models.SoliniaCraft)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1