ninja.leaping.configurate.hocon.HoconConfigurationLoader Java Examples

The following examples show how to use ninja.leaping.configurate.hocon.HoconConfigurationLoader. 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: HOCONPlayerStorage.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public boolean savePlayer(FactionPlayer player)
{
    Path playerFile = playersDirectoryPath.resolve(player.getUniqueId().toString() + ".conf");

    HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurateHelper.getDefaultOptions()).setPath(playerFile).build();
    try
    {
        ConfigurationNode configurationNode = configurationLoader.load();
        configurationNode.getNode("name").setValue(player.getName());
        configurationNode.getNode("faction").setValue(player.getFactionName().orElse(""));
        configurationNode.getNode("power").setValue(player.getPower());
        configurationNode.getNode("maxpower").setValue(player.getMaxPower());
        configurationNode.getNode("death-in-warzone").setValue(false);
        configurationLoader.save(configurationNode);
        return true;
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }

    return false;
}
 
Example #2
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = 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(ClaimTemplateConfig.class).bindToNew();

        reload();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #3
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(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(MessageDataConfig.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #4
Source File: ClaimStorageData.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    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(ClaimDataConfig.class).bind(claimData);
        this.configMapper.getInstance().setClaimStorageData(this);
        reload();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefDefenderPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #5
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = 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(ClaimTemplateConfig.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #6
Source File: OptionConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public OptionConfig(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(OptionStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #7
Source File: FlagConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public FlagConfig(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(FlagStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #8
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 #9
Source File: PlayerStorageData.java    From GriefDefender with MIT License 6 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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #10
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 6 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();

        load();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #11
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = 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(ClaimTemplateConfig.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize claim template data", e);
    }
}
 
Example #12
Source File: MessageStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(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(MessageDataConfig.class).bindToNew();

        reload();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #13
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    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(ClaimDataConfig.class).bind(claimData);
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #14
Source File: FlagConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public FlagConfig(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(FlagStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #15
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(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(MessageDataConfig.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #16
Source File: OptionConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public OptionConfig(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(OptionStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #17
Source File: HOCONFactionStorage.java    From EagleFactions with MIT License 6 votes vote down vote up
private void loadFactionsConfigurationLoaders()
{
    try
    {
        final Stream<Path> pathsStream = Files.list(this.factionsDir);
        pathsStream.forEach(path ->
        {
            final String factionFileName = path.getFileName().toString().toLowerCase();
            final HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurateHelper.getDefaultOptions()).setPath(this.factionsDir.resolve(path)).build();
            factionLoaders.put(factionFileName, configurationLoader);
        });
    }
    catch (final IOException e)
    {
        e.printStackTrace();
    }
}
 
Example #18
Source File: ClaimStorageData.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    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(ClaimDataConfig.class).bind(claimData);
        this.configMapper.getInstance().setClaimStorageData(this);
        reload();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefDefenderPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #19
Source File: LanguageHandler.java    From Nations with MIT License 6 votes vote down vote up
public static void init(File rootDir)
{
	languageFile = new File(rootDir, "language.conf");
	languageManager = HoconConfigurationLoader.builder().setPath(languageFile.toPath()).build();
	
	try
	{
		if (!languageFile.exists())
		{
			languageFile.getParentFile().mkdirs();
			languageFile.createNewFile();
			language = languageManager.load();
			languageManager.save(language);
		}
		language = languageManager.load();
	}
	catch (IOException e)
	{
		NationsPlugin.getLogger().error("Could not load or create language file !");
		e.printStackTrace();
	}
	
}
 
Example #20
Source File: ConfigCompleter.java    From UltimateCore with MIT License 6 votes vote down vote up
/**
     * This method completes a datafile.
     * Any fields that are in the asset provided but not in the datafile will be set in the datafile.
     *
     * @param file  The file to complete
     * @param asset The asset with the default values
     * @return Whether anything was added to the file
     */
    public static boolean complete(RawConfig file, Asset asset) {
        try {
            ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(asset.getUrl()).build();
            CommentedConfigurationNode assetnode = loader.load();
            CommentedConfigurationNode sourcenode = file.get();

//            if (complete(assetnode, sourcenode)) {
//                file.save(assetnode);
//                return true;
//            }
            return false;
        } catch (Exception ex) {
            ErrorLogger.log(ex, "Config completion failed for " + file + " / " + asset);
            return false;
        }
    }
 
Example #21
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (path.getParent().endsWith("town")) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #22
Source File: RawFileConfig.java    From UltimateCore with MIT License 6 votes vote down vote up
public void reload() {
    try {
        if (!file.exists()) {
            file.getParentFile().mkdirs();
            if (asset == null) {
                file.createNewFile();
            } else {
                asset.copyToFile(file.toPath());
            }
        }
        loader = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
        node = loader.load();
    } catch (IOException e) {
        ErrorLogger.log(e, "Failed to config for " + file);
    }
}
 
Example #23
Source File: SpongeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the configuration
 */
private void loadConfiguration() {
    configurationFile = getConfigFile();
    configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();

    try {
        if (!configurationFile.exists()) {
            configurationFile.createNewFile();
            config = configurationLoader.load();

            config.setComment("This contains settings for MCStats: http://mcstats.org");
            config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
            config.getNode("mcstats.opt-out").setValue(false);
            config.getNode("mcstats.debug").setValue(false);

            configurationLoader.save(config);
        } else {
            config = configurationLoader.load();
        }

        guid = config.getNode("mcstats.guid").getString();
        debug = config.getNode("mcstats.debug").getBoolean();
    } catch (final IOException e) {
        MainUtil.handleError(e);
    }
}
 
Example #24
Source File: ProtectionConfigImpl.java    From EagleFactions with MIT License 6 votes vote down vote up
public ProtectionConfigImpl(final Configuration configuration)
{
	this.configuration = configuration;

	try
	{
		Optional<Asset> worldsFile = Sponge.getAssetManager().getAsset(EagleFactionsPlugin.getPlugin(), "Worlds.conf");
		if (worldsFile.isPresent())
		{
			worldsFile.get().copyToDirectory(configuration.getConfigDirectoryPath(), false, true);
		}
	}
	catch (final IOException e)
	{
		e.printStackTrace();
	}

	this.configurationLoader = HoconConfigurationLoader.builder().setPath(configuration.getConfigDirectoryPath().resolve("Worlds.conf")).build();
	loadWorldsFile();
	saveWorldsFile();
}
 
Example #25
Source File: SpongeMetrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Loads the configuration
 */
private void loadConfiguration() {
    configurationFile = getConfigFile();
    configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build();

    try {
        if (!configurationFile.exists()) {
            configurationFile.createNewFile();
            config = configurationLoader.load();

            config.setComment("This contains settings for MCStats: http://mcstats.org");
            config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString());
            config.getNode("mcstats.opt-out").setValue(false);
            config.getNode("mcstats.debug").setValue(false);

            configurationLoader.save(config);
        } else {
            config = configurationLoader.load();
        }

        guid = config.getNode("mcstats.guid").getString();
        debug = config.getNode("mcstats.debug").getBoolean();
    } catch (final IOException e) {
        MainUtil.handleError(e);
    }
}
 
Example #26
Source File: HOCONPlayerStorage.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public Set<String> getServerPlayerNames()
{
    Set<String> playerSet = new HashSet<>();

    File playerDir = new File(playersDirectoryPath.toUri());
    File[] playerFiles = playerDir.listFiles();

    for(File playerFile : playerFiles)
    {
        HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurateHelper.getDefaultOptions()).setPath(playerFile.toPath()).build();
        try
        {
            ConfigurationNode configurationNode = configurationLoader.load();
            playerSet.add(configurationNode.getNode("name").getString(""));
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    return playerSet;
}
 
Example #27
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 #28
Source File: HOCONPlayerStorage.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public FactionPlayer getPlayer(final UUID playerUUID)
{
    final Path playerFilePath = this.playersDirectoryPath.resolve(playerUUID.toString() + ".conf");
    if (Files.notExists(playerFilePath))
        return null;

    HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurateHelper.getDefaultOptions()).setPath(playerFilePath).build();
    try
    {
        ConfigurationNode configurationNode = configurationLoader.load();
        String playerName = configurationNode.getNode("name").getString("");
        String factionName = configurationNode.getNode("faction").getString("");
        String factionMemberTypeString = configurationNode.getNode("faction-member-type").getString("");
        float power = configurationNode.getNode("power").getFloat(0.0f);
        float maxpower = configurationNode.getNode("maxpower").getFloat(0.0f);
        boolean diedInWarZone = configurationNode.getNode("death-in-warzone").getBoolean(false);
        FactionMemberType factionMemberType = null;

        if(!factionMemberTypeString.equals(""))
            factionMemberType = FactionMemberType.valueOf(factionMemberTypeString);

        return new FactionPlayerImpl(playerName, playerUUID, factionName, power, maxpower, factionMemberType, diedInWarZone);
    }
    catch(IOException e)
    {
        e.printStackTrace();
        Sponge.getServer().getConsole().sendMessage(PluginInfo.ERROR_PREFIX.concat(Text.of("Could not get player from the file. Tried to get player for UUID: " + playerUUID)));
    }
    return null;
}
 
Example #29
Source File: Metrics.java    From EconomyLite with MIT License 5 votes vote down vote up
/**
 * Loads the bStats configuration.
 *
 * @throws IOException If something did not work :(
 */
private void loadConfig() throws IOException {
    Path configPath = configDir.resolve("bStats");
    configPath.toFile().mkdirs();
    File configFile = new File(configPath.toFile(), "config.conf");
    HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setFile(configFile).build();
    CommentedConfigurationNode node;
    if (!configFile.exists()) {
        configFile.createNewFile();
        node = configurationLoader.load();

        // Add default values
        node.getNode("enabled").setValue(true);
        // Every server gets it's unique random id.
        node.getNode("serverUuid").setValue(UUID.randomUUID().toString());
        // Should failed request be logged?
        node.getNode("logFailedRequests").setValue(false);

        // Add information about bStats
        node.getNode("enabled").setComment(
                "bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
                        "To honor their work, you should not disable it.\n" +
                        "This has nearly no effect on the server performance!\n" +
                        "Check out https://bStats.org/ to learn more :)"
                );

        configurationLoader.save(node);
    } else {
        node = configurationLoader.load();
    }

    // Load configuration
    enabled = node.getNode("enabled").getBoolean(true);
    serverUUID = node.getNode("serverUuid").getString();
    logFailedRequests = node.getNode("logFailedRequests").getBoolean(false);
}
 
Example #30
Source File: WorldFlatFileRegionManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
private void load(String path) {

        if (!RedProtect.get().config.configRoot().file_type.equalsIgnoreCase("mysql")) {
            RedProtect.get().logger.debug(LogLevel.DEFAULT, "Load world " + this.world + ". File type: conf");

            try {
                File tempRegionFile = new File(path);
                if (!tempRegionFile.exists()) {
                    tempRegionFile.createNewFile();
                }

                ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(tempRegionFile.toPath()).build();
                CommentedConfigurationNode region = regionManager.load();

                for (Object key : region.getChildrenMap().keySet()) {
                    String rname = key.toString();
                    if (!region.getNode(rname).hasMapChildren()) {
                        continue;
                    }
                    Region newr = loadRegion(region, rname, Sponge.getServer().getWorld(world).get());
                    newr.setToSave(false);
                    regions.put(rname, newr);
                }
            } catch (IOException e) {
                CoreUtil.printJarVersion();
                e.printStackTrace();
            }
        }
    }