Search in sources :

Example 1 with InvalidSpawnGroupSettingException

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

the class SoliniaSpawnGroup method editSetting.

@Override
public void editSetting(String setting, String value) throws InvalidSpawnGroupSettingException, NumberFormatException, CoreStateInitException, java.io.IOException {
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidSpawnGroupSettingException("Name is empty");
            if (value.length() > 25)
                throw new InvalidSpawnGroupSettingException("Name is longer than 25 characters");
            setName(value);
            break;
        case "respawntime":
            if (Integer.parseInt(value) < 360)
                throw new InvalidSpawnGroupSettingException("Minimum respawn time is 360 seconds");
            setRespawntime(Integer.parseInt(value));
            break;
        case "x":
            setX(Integer.parseInt(value));
            break;
        case "y":
            setY(Integer.parseInt(value));
            break;
        case "z":
            setZ(Integer.parseInt(value));
            break;
        case "disabled":
            setDisabled(Boolean.parseBoolean(value));
            break;
        case "npcid":
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(Integer.parseInt(value));
            if (npc == null)
                throw new InvalidSpawnGroupSettingException("Invalid NPCID");
            setNpcid(Integer.parseInt(value));
            break;
        default:
            throw new InvalidSpawnGroupSettingException("Invalid SpawnGroup setting. Valid Options are: name, x, y, z, respawntime,npcid");
    }
}
Also used : InvalidSpawnGroupSettingException(com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 2 with InvalidSpawnGroupSettingException

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

the class CommandEditSpawngroup 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.editspawngroup")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int spawngroupid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaSpawnGroup spawngroup = StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid);
            if (spawngroup != null) {
                spawngroup.sendSpawnGroupSettingsToSender(sender);
            } else {
                sender.sendMessage("SPAWNGROUP ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: spawngroupid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // for 'text' based spawngroup settings like trigger texts etc, get the whole thing as a string
    if (args.length > 3 && setting.toLowerCase().contains("text")) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (spawngroupid < 1) {
        sender.sendMessage("Invalid spawngroupid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid) == null) {
            sender.sendMessage("Cannot locate spawngroupid: " + spawngroupid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getSpawnGroup(spawngroupid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This spawngroup was op created and you are not an op. Only ops can edit spawngroup npcs");
            return false;
        }
        try {
            StateManager.getInstance().getConfigurationManager().editSpawnGroup(spawngroupid, setting, value);
            sender.sendMessage("Updating setting on spawngroup");
        } catch (java.io.IOException e) {
            sender.sendMessage("Failed to update SpawnGroup");
        }
    } catch (InvalidSpawnGroupSettingException ne) {
        sender.sendMessage("Invalid SpawnGroup 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) InvalidSpawnGroupSettingException(com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

InvalidSpawnGroupSettingException (com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaSpawnGroup (com.solinia.solinia.Interfaces.ISoliniaSpawnGroup)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1