Search in sources :

Example 1 with ConfigNode

use of com.djrapitops.plan.settings.config.ConfigNode in project Plan by plan-player-analytics.

the class ThemeConfig method getDefaults.

private static ConfigNode getDefaults(PlanFiles files, PlanConfig config, PluginLogger logger) {
    String fileName = config.get(DisplaySettings.THEME);
    String fileLocation = getFileLocation(fileName);
    try (ConfigReader reader = new ConfigReader(files.getResourceFromJar(fileLocation).asInputStream())) {
        return reader.read();
    } catch (IOException e) {
        logger.error("Could not find theme " + fileLocation + ". Attempting to use default.");
        return new ConfigNode(null, null, null);
    }
}
Also used : ConfigReader(com.djrapitops.plan.settings.config.ConfigReader) IOException(java.io.IOException) ConfigNode(com.djrapitops.plan.settings.config.ConfigNode)

Example 2 with ConfigNode

use of com.djrapitops.plan.settings.config.ConfigNode in project Plan by plan-player-analytics.

the class WebAssetVersionCheckTask method run.

@Override
public void run() {
    Optional<ConfigNode> planCustomizationNode = getPlanCustomizationNode();
    if (planCustomizationNode.isPresent()) {
        try {
            webAssetVersions.prepare();
        } catch (IOException e) {
            logger.warn(String.format("Could not read web asset versions, %s", e.toString()));
            logger.warn("Web asset version check will be skipped!");
            return;
        }
        List<AssetInfo> outdated = new ArrayList<>();
        for (ConfigNode child : planCustomizationNode.get().getChildren()) {
            if (child.getBoolean()) {
                String resource = child.getKey(false).replace(',', '.');
                findOutdatedResource(resource).ifPresent(outdated::add);
            }
        }
        if (!outdated.isEmpty()) {
            logger.warn("You have customized files which are out of date due to recent updates!");
            logger.warn("Plan may not work properly until these files are updated to include the new modifications.");
            logger.warn("See https://github.com/plan-player-analytics/Plan/commits/html to compare changes");
        }
        for (AssetInfo asset : outdated) {
            logger.warn(String.format("- %s was modified %s, but the plugin contains a version from %s", asset.filename, formatters.secondLong().apply(asset.modifiedAt), formatters.secondLong().apply(asset.expectedModifiedAt)));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ConfigNode(com.djrapitops.plan.settings.config.ConfigNode) IOException(java.io.IOException)

Example 3 with ConfigNode

use of com.djrapitops.plan.settings.config.ConfigNode in project Plan by plan-player-analytics.

the class ResourceWriteTask method run.

@Override
public void run() {
    ResourceService resourceService = ResourceService.getInstance();
    Optional<ConfigNode> planCustomizationNode = getPlanCustomizationNode();
    if (planCustomizationNode.isPresent()) {
        for (ConfigNode child : planCustomizationNode.get().getChildren()) {
            if (child.getBoolean()) {
                String resource = child.getKey(false).replace(',', '.');
                try {
                    resourceService.getResource("Plan", resource, () -> files.getResourceFromJar("web/" + resource).asWebResource());
                } catch (UncheckedIOException resourceNoLongerFound) {
                    if (!(resourceNoLongerFound.getCause() instanceof FileNotFoundException)) {
                        errorLogger.error(resourceNoLongerFound, ErrorContext.builder().whatToDo("A resource could not be read from the jar: " + resource + ", try restarting the server. Report this if error still occurs afterwards: " + resourceNoLongerFound.getMessage()).build());
                    }
                }
            }
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) ConfigNode(com.djrapitops.plan.settings.config.ConfigNode)

Aggregations

ConfigNode (com.djrapitops.plan.settings.config.ConfigNode)3 IOException (java.io.IOException)2 ConfigReader (com.djrapitops.plan.settings.config.ConfigReader)1 FileNotFoundException (java.io.FileNotFoundException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1