/** * Loads new test with given name and ConfigurationSection. * * @param plugin instance of BetonTest * @param name name of the test * @param config section containing the test * @throws TestException when configuration is incorrect */ public Test(BetonTest plugin, String name, ConfigurationSection config) throws TestException { this.plugin = plugin; this.name = name; messageStart = config.getString("messages.start"); messageResume = config.getString("messages.resume"); messagePass = config.getString("messages.pass"); messageFail = config.getString("messages.fail"); messagePause = config.getString("messages.pause"); commandWin = config.getString("commands.pass"); commandFail = config.getString("commands.fail"); commandPause = config.getString("commands.pause"); blockedCommands = config.getStringList("blocked_cmds"); teleportBack = config.getBoolean("teleport_back"); maxMistakes = config.getInt("max_mistakes", -1); if (maxMistakes < 0) throw new TestException("max_mistakes must be more than 0"); onMistake = MistakeAction.match(config.getString("on_mistake")); if (onMistake == null) throw new TestException("incorrect on_mistake value"); if (config.getConfigurationSection("categories") == null) throw new TestException("categories not defined"); for (String key : config.getConfigurationSection("categories").getKeys(false)) { try { categories.add( new Category(plugin, this, key, config.getConfigurationSection("categories." + key))); } catch (CategoryException e) { throw new TestException("error in '" + key + "' category: " + e.getMessage()); } } if (categories.isEmpty()) throw new TestException("categories not defined"); for (Category category : categories) { category.shuffle(); } }