Search in sources :

Example 1 with Limits

use of dev.frankheijden.insights.api.config.Limits in project Insights by InsightsPlugin.

the class Insights method reloadLimits.

@Override
public void reloadLimits() {
    limits = new Limits();
    Path limitsPath = getDataFolder().toPath().resolve(LIMITS_FOLDER_NAME);
    if (!Files.exists(limitsPath)) {
        try {
            Files.createDirectory(limitsPath);
            IOUtils.copyResources(limitsPath, getClassLoader(), Arrays.asList("bed-limit.yml", "redstone-limit.yml", "tile-limit.yml"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(limitsPath, p -> !Files.isDirectory(p))) {
        for (Path child : stream) {
            String fileName = child.getFileName().toString();
            if (!fileName.toLowerCase(Locale.ENGLISH).endsWith(".yml"))
                continue;
            try {
                Limit limit = Limit.parse(child.toFile());
                getLogger().info("Loaded limit '" + fileName + "'");
                limits.addLimit(limit);
            } catch (YamlParseException ex) {
                getLogger().severe("Limit '" + fileName + "' could not be loaded:");
                getLogger().severe(ex.getMessage());
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) Limits(dev.frankheijden.insights.api.config.Limits) YamlParseException(dev.frankheijden.insights.api.config.parser.YamlParseException) IOException(java.io.IOException) Limit(dev.frankheijden.insights.api.config.limits.Limit)

Aggregations

Limits (dev.frankheijden.insights.api.config.Limits)1 Limit (dev.frankheijden.insights.api.config.limits.Limit)1 YamlParseException (dev.frankheijden.insights.api.config.parser.YamlParseException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1