ninja.leaping.configurate.ConfigurationOptions Java Examples

The following examples show how to use ninja.leaping.configurate.ConfigurationOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Settings.java    From FlexibleLogin with MIT License 6 votes vote down vote up
private <T> void loadMapper(ObjectMapper<T>.BoundInstance mapper, Path file, ConfigurationOptions options) {
    ConfigurationNode rootNode;
    if (mapper != null) {
        HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setPath(file).build();
        try {
            rootNode = loader.load(options.setShouldCopyDefaults(true));
            ConfigurationNode hashNode = rootNode.getNode("hashAlgo");
            if ("bcrypt".equalsIgnoreCase(hashNode.getString())) {
                hashNode.setValue("BCrypt");
            }

            //load the config into the object
            mapper.populate(rootNode);

            //add missing default values
            loader.save(rootNode);
        } catch (ObjectMappingException objMappingExc) {
            logger.error("Error loading the configuration", objMappingExc);
        } catch (IOException ioExc) {
            logger.error("Error saving the default configuration", ioExc);
        }
    }
}
 
Example #2
Source File: ConfigLoader.java    From NuVotifier with GNU General Public License v3.0 6 votes vote down vote up
public static void loadConfig(NuVotifier pl) {
    if (!pl.getConfigDir().exists()) {
        if (!pl.getConfigDir().mkdirs()) {
            throw new RuntimeException("Unable to create the plugin data folder " + pl.getConfigDir());
        }
    }
    try {
        File config = new File(pl.getConfigDir(), "config.yml");
        if (!config.exists() && !config.createNewFile()) {
            throw new IOException("Unable to create the config file at " + config);
        }
        ConfigurationLoader loader = YAMLConfigurationLoader.builder().setFile(config).build();
        ConfigurationNode configNode = loader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true));
        spongeConfig = configNode.getValue(TypeToken.of(SpongeConfig.class), new SpongeConfig());
        loader.save(configNode);
    } catch (Exception e) {
        pl.getLogger().error("Could not load config.", e);
    }
}
 
Example #3
Source File: ConfigManager.java    From Despector with MIT License 6 votes vote down vote up
/**
 * Loads the given configuration file.
 */
public static void load(Path path) {
    System.out.println("Loading config from " + path.toString());
    try {
        Files.createDirectories(path.getParent());
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        loader = HoconConfigurationLoader.builder().setPath(path).build();
        configMapper = ObjectMapper.forClass(ConfigBase.class).bindToNew();
        node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
        config = configMapper.populate(node);
        configMapper.serialize(node);
        loader.save(node);
    } catch (Exception e) {
        System.err.println("Error loading configuration:");
        e.printStackTrace();
    }
}
 
Example #4
Source File: ConfigurationFileUtil.java    From AntiVPN with MIT License 5 votes vote down vote up
public static Configuration getConfig(Plugin plugin, String resourcePath, File fileOnDisk) throws IOException {
    File parentDir = fileOnDisk.getParentFile();
    if (parentDir.exists() && !parentDir.isDirectory()) {
        Files.delete(parentDir.toPath());
    }
    if (!parentDir.exists()) {
        if (!parentDir.mkdirs()) {
            throw new IOException("Could not create parent directory structure.");
        }
    }
    if (fileOnDisk.exists() && fileOnDisk.isDirectory()) {
        Files.delete(fileOnDisk.toPath());
    }

    if (!fileOnDisk.exists()) {
        try (InputStreamReader reader = new InputStreamReader(plugin.getResource(resourcePath));
             BufferedReader in = new BufferedReader(reader);
             FileWriter writer = new FileWriter(fileOnDisk);
             BufferedWriter out = new BufferedWriter(writer)) {
            String line;
            while ((line = in.readLine()) != null) {
                out.write(line + System.lineSeparator());
            }
        }
    }

    ConfigurationLoader<ConfigurationNode> loader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setFile(fileOnDisk).build();
    ConfigurationNode root = loader.load(ConfigurationOptions.defaults().setHeader("Comments are gone because update :(. Click here for new config + comments: https://www.spigotmc.org/resources/anti-vpn.58291/"));
    Configuration config = new Configuration(root);
    ConfigurationVersionUtil.conformVersion(loader, config, fileOnDisk);

    return config;
}
 
Example #5
Source File: Settings.java    From FlexibleLogin with MIT License 5 votes vote down vote up
private ConfigurationOptions getConfigurationOptions() {
    ConfigurationOptions defaults = ConfigurationOptions.defaults();

    TypeSerializerCollection serializers = defaults.getSerializers().newChild();
    serializers.registerType(TypeToken.of(Duration.class), new DurationSerializer());

    //explicit set enum serializer because otherwise they will be interpreted as class with the requirement of
    //a public constructor
    TypeSerializer<Enum> enumSerializer = serializers.get(TypeToken.of(Enum.class));
    serializers.registerType(TypeToken.of(StorageType.class), enumSerializer);
    serializers.registerType(TypeToken.of(HashingAlgorithm.class), enumSerializer);

    return defaults.setSerializers(serializers);
}
 
Example #6
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void load() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #7
Source File: MessageStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setHeader(GriefPreventionPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #8
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void load() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #9
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setSerializers(
                        TypeSerializers.getDefaultSerializers().newChild().registerType(TypeToken.of(IpSet.class), new IpSet.IpSetSerializer()))
                .setHeader(GriefPreventionPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to load configuration", e);
    }
}
 
Example #10
Source File: ProtectionConfigImpl.java    From EagleFactions with MIT License 5 votes vote down vote up
private void loadWorldsFile()
{
	try
	{
		this.worldsConfigNode = this.configurationLoader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true));
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
}
 
Example #11
Source File: ConfigurationImpl.java    From EagleFactions with MIT License 5 votes vote down vote up
private void loadConfiguration()
{
    try
    {
        configNode = configLoader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true));
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
Example #12
Source File: ConfigurationFileUtil.java    From AntiVPN with MIT License 5 votes vote down vote up
public static Configuration getConfig(Object plugin, String resourcePath, File fileOnDisk) throws IOException {
    File parentDir = fileOnDisk.getParentFile();
    if (parentDir.exists() && !parentDir.isDirectory()) {
        Files.delete(parentDir.toPath());
    }
    if (!parentDir.exists()) {
        if (!parentDir.mkdirs()) {
            throw new IOException("Could not create parent directory structure.");
        }
    }
    if (fileOnDisk.exists() && fileOnDisk.isDirectory()) {
        Files.delete(fileOnDisk.toPath());
    }

    if (!fileOnDisk.exists()) {
        try (InputStreamReader reader = new InputStreamReader(plugin.getClass().getClassLoader().getResourceAsStream(resourcePath));
             BufferedReader in = new BufferedReader(reader);
             FileWriter writer = new FileWriter(fileOnDisk);
             BufferedWriter out = new BufferedWriter(writer)) {
            String line;
            while ((line = in.readLine()) != null) {
                out.write(line + System.lineSeparator());
            }
        }
    }

    ConfigurationLoader<ConfigurationNode> loader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setFile(fileOnDisk).build();
    ConfigurationNode root = loader.load(ConfigurationOptions.defaults().setHeader("Comments are gone because update :(. Click here for new config + comments: https://forums.velocitypowered.com/t/anti-vpn-get-the-best-save-money-on-overpriced-plugins-and-block-vpn-users/207"));
    Configuration config = new Configuration(root);
    ConfigurationVersionUtil.conformVersion(loader, config, fileOnDisk);

    return config;
}
 
Example #13
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setHeader(GriefDefenderPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #14
Source File: ConfigurationFileUtil.java    From AntiVPN with MIT License 5 votes vote down vote up
public static Configuration getConfig(Plugin plugin, String resourcePath, File fileOnDisk) throws IOException {
    File parentDir = fileOnDisk.getParentFile();
    if (parentDir.exists() && !parentDir.isDirectory()) {
        Files.delete(parentDir.toPath());
    }
    if (!parentDir.exists()) {
        if (!parentDir.mkdirs()) {
            throw new IOException("Could not create parent directory structure.");
        }
    }
    if (fileOnDisk.exists() && fileOnDisk.isDirectory()) {
        Files.delete(fileOnDisk.toPath());
    }

    if (!fileOnDisk.exists()) {
        try (InputStreamReader reader = new InputStreamReader(plugin.getResourceAsStream(resourcePath));
             BufferedReader in = new BufferedReader(reader);
             FileWriter writer = new FileWriter(fileOnDisk);
             BufferedWriter out = new BufferedWriter(writer)) {
            String line;
            while ((line = in.readLine()) != null) {
                out.write(line + System.lineSeparator());
            }
        }
    }

    ConfigurationLoader<ConfigurationNode> loader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setFile(fileOnDisk).build();
    ConfigurationNode root = loader.load(ConfigurationOptions.defaults().setHeader("Comments are gone because update :(. Click here for new config + comments: https://www.spigotmc.org/resources/anti-vpn-bungee.58716/"));
    Configuration config = new Configuration(root);
    ConfigurationVersionUtil.conformVersion(loader, config, fileOnDisk);

    return config;
}
 
Example #15
Source File: ClaimStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
    }
}
 
Example #16
Source File: OptionConfig.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #17
Source File: MessageStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
        MESSAGE_DATA = this.configBase;
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #18
Source File: FlagConfig.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #19
Source File: PlayerStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #20
Source File: PlayerStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public PlayerStorageData(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(PlayerDataConfig.class).bindToNew();
        this.root = this.loader.load(ConfigurationOptions.defaults());
        CommentedConfigurationNode rootNode = this.root.getNode(GriefDefenderPlugin.MOD_ID);
        // Check if server is using existing Sponge GP data
        if (rootNode.isVirtual()) {
            // check GriefPrevention
            CommentedConfigurationNode gpRootNode = this.root.getNode("GriefPrevention");
            if (!gpRootNode.isVirtual()) {
                rootNode.setValue(gpRootNode.getValue());
                gpRootNode.setValue(null);
            }
        }
        this.configBase = this.configMapper.populate(rootNode);
        save();
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #21
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults()
                .setHeader(GriefDefenderPlugin.CONFIG_HEADER));
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #22
Source File: ClaimStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
public void reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
    }
}
 
Example #23
Source File: OptionConfig.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #24
Source File: MessageStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
        MESSAGE_DATA = this.configBase;
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #25
Source File: FlagConfig.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #26
Source File: PlayerStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean reload() {
    try {
        this.root = this.loader.load(ConfigurationOptions.defaults());
        this.configBase = this.configMapper.populate(this.root.getNode(GriefDefenderPlugin.MOD_ID));
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to load configuration", e);
        return false;
    }
    return true;
}
 
Example #27
Source File: ConfigurateHelper.java    From EagleFactions with MIT License 4 votes vote down vote up
public static ConfigurationOptions getDefaultOptions()
{
    final ConfigurationOptions configurationOptions = ConfigurationOptions.defaults();
    return configurationOptions.setAcceptedTypes(ImmutableSet.of(Map.class, Set.class, List.class, Double.class, Float.class, Long.class, Integer.class, Boolean.class, String.class,
            Short.class, Byte.class, Number.class));
}
 
Example #28
Source File: VirtualChestItemStackSerializer.java    From VirtualChest with GNU Lesser General Public License v3.0 4 votes vote down vote up
private ConfigurationNode convertToConfigurationNode(DataView view)
{
    ConfigurationOptions configurationOptions = ConfigurationOptions.defaults().setSerializers(this.serializers);
    Map<?, ?> values = view.getMap(DataQuery.of()).orElseThrow(InvalidDataException::new);
    return SimpleConfigurationNode.root(configurationOptions).setValue(values);
}