Search in sources :

Example 1 with InvalidFactionSettingException

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

the class CommandEditFaction 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.editfaction")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int factionid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaFaction solfaction = StateManager.getInstance().getConfigurationManager().getFaction(factionid);
            if (solfaction != null) {
                solfaction.sendFactionSettingsToSender(sender);
            } else {
                sender.sendMessage("FACTION ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: factionid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && (setting.toLowerCase().contains("description") || setting.toLowerCase().contains("factionentry") || setting.toLowerCase().contains("allygrants") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (factionid < 1) {
        sender.sendMessage("Invalid faction id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getFaction(factionid) == null) {
            sender.sendMessage("Cannot locate faction id: " + factionid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getFaction(factionid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This faction was op created and you are not an op. Only ops can faction op items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editFaction(factionid, setting, value);
        sender.sendMessage("Updating setting on faction");
    } catch (InvalidFactionSettingException ne) {
        sender.sendMessage("Invalid faction setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidFactionSettingException(com.solinia.solinia.Exceptions.InvalidFactionSettingException) IOException(java.io.IOException)

Example 2 with InvalidFactionSettingException

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

the class SoliniaFaction method editSetting.

@Override
public void editSetting(String setting, String value) throws InvalidFactionSettingException, NumberFormatException, CoreStateInitException, java.io.IOException {
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidFactionSettingException("Name is empty");
            if (value.length() > 25)
                throw new InvalidFactionSettingException("Name is longer than 25 characters");
            setName(value);
            break;
        case "base":
            if (Integer.parseInt(value) < -1500 || Integer.parseInt(value) > 1500)
                throw new InvalidFactionSettingException("Bounds are -1500 to 1500");
            setBase(Integer.parseInt(value));
            break;
        case "allygrantstitle":
            setAllyGrantsTitle(value);
            break;
        case "scowlsgrantstitle":
            setScowlsGrantsTitle(value);
            break;
        case "factionentry":
            String[] data = value.split(" ");
            if (data.length < 2)
                throw new InvalidFactionSettingException("Missing factionid and base value to set factionstanding (ie -1500 > 1500)");
            int factionId = Integer.parseInt(data[0]);
            ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(factionId);
            if (faction == null)
                throw new InvalidFactionSettingException("Faction doesnt exist");
            if (Integer.parseInt(data[1]) < -1500 || Integer.parseInt(data[1]) > 1500)
                throw new InvalidFactionSettingException("Bounds are -1500 to 1500");
            setFactionEntry(faction.getId(), Integer.parseInt(data[1]));
            break;
        default:
            throw new InvalidFactionSettingException("Invalid SpawnGroup setting. Valid Options are: name, base, factionentry");
    }
}
Also used : ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) InvalidFactionSettingException(com.solinia.solinia.Exceptions.InvalidFactionSettingException)

Aggregations

InvalidFactionSettingException (com.solinia.solinia.Exceptions.InvalidFactionSettingException)2 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 IOException (java.io.IOException)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1