de.teamlapen.lib.lib.util.LogUtil.CONFIG - java examples

Here are the examples of the java api de.teamlapen.lib.lib.util.LogUtil.CONFIG taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

18 View Complete Implementation : BloodValueLoaderDynamic.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
private static boolean writeBloodValues(Writer w, Map<ResourceLocation, Integer> values, String comment) throws IOException {
    BufferedWriter bw = null;
    try {
        bw = new BufferedWriter(w);
        bw.write('#');
        bw.write(comment);
        bw.newLine();
        for (Map.Entry<ResourceLocation, Integer> entry : values.entrySet()) {
            bw.write(entry.getKey().toString());
            bw.write('=');
            bw.write(String.valueOf(entry.getValue()));
            bw.newLine();
        }
        bw.flush();
        return true;
    } catch (IOException e) {
        LOGGER.error(LogUtil.CONFIG, "Failed to write blood values", e);
    } finally {
        if (bw != null) {
            bw.close();
        }
        w.close();
    }
    return false;
}

17 View Complete Implementation : BloodValueLoaderDynamic.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
/**
 * Reads automatically calculated values from world file
 */
private void loadDynamicBloodValues(File f) {
    try {
        Map<ResourceLocation, Integer> saved = loadBloodValuesFromReader(new InputStreamReader(new FileInputStream(f)), f.getName());
        this.addCalculatedValues.accept(saved);
    } catch (IOException e) {
        LOGGER.error(LogUtil.CONFIG, "[ModCompat]Could not read saved {} blood values from world from file {} {}", name, f, e);
    }
}

16 View Complete Implementation : BloodValueLoaderDynamic.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
/**
 * Saves blood values to file to be saved in world dir
 */
private void saveDynamicBloodValues(File f) {
    Map<ResourceLocation, Integer> values = this.getCalculatedValues.get();
    // Don't create a empty file
    if (!f.exists() && values.isEmpty())
        return;
    if (!f.exists()) {
        if (f.getParentFile() != null)
            f.getParentFile().mkdirs();
    }
    try {
        if (!writeBloodValues(new FileWriter(f), values, "Dynamically calculated blood values - DON'T EDIT")) {
            LOGGER.warn(LogUtil.CONFIG, "Could not write calculated {} values to file", name);
        }
    } catch (IOException e) {
        LOGGER.error(LogUtil.CONFIG, "Failed to write calculated blood values to file", e);
    }
}

15 View Complete Implementation : BloodValueLoader.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
/**
 * Reads blood values for a mod from the datapack.
 *
 * @param modId should be equals to the file name of location
 */
@Nullable
protected Map<ResourceLocation, Integer> loadBloodValuesFromDataPack(ResourceLocation location, String modId, IResourceManager resourceManager) {
    if (!ModList.get().isLoaded(modId))
        return null;
    try {
        return loadBloodValuesFromReader(new InputStreamReader(resourceManager.getResource(location).getInputStream()), modId);
    } catch (IOException e) {
        LOGGER.error(LogUtil.CONFIG, "[ModCompat]Could not read default blood values for mod {}, this should not happen {}", modId, e);
        return null;
    }
}

9 View Complete Implementation : BloodValueLoader.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
/**
 * @param r     Reader the values should be read from
 * @param modId Just for logging of errors
 */
protected <T> Map<ResourceLocation, Integer> loadBloodValuesFromReader(Reader r, String modId) throws IOException {
    Map<ResourceLocation, Integer> bloodValues = Maps.newConcurrentMap();
    BufferedReader br = null;
    try {
        br = new BufferedReader(r);
        String line;
        while ((line = br.readLine()) != null) {
            if (line.startsWith("#"))
                continue;
            if (StringUtils.isBlank(line))
                continue;
            String[] p = line.split("=");
            if (p.length != 2) {
                LOGGER.warn(LogUtil.CONFIG, "Line {}  in {} is not formatted properly", line, modId + ".txt");
                continue;
            }
            if (p[0].equals(modId)) {
                LOGGER.warn(LogUtil.CONFIG, "{} is not applicant for other the mod {} in {}", line, modId, modId + ".txt");
            }
            int val;
            try {
                val = Integer.parseInt(p[1]);
            } catch (NumberFormatException e) {
                LOGGER.warn(LogUtil.CONFIG, "Line {}  in {} is not formatted properly", line, modId + ".txt");
                continue;
            }
            ResourceLocation resourceLocation = new ResourceLocation(p[0]);
            if (!resourceLocation.getNamespace().equals(modId)) {
                LOGGER.warn(LogUtil.CONFIG, "Wrong namespace for entry {} in {}", p[0], modId + ".txt");
            } else {
                if (resourceLocation.equals(multiplierName)) {
                    multiplier = val;
                } else if (bloodValues.put(resourceLocation, val) != null) {
                    LOGGER.warn(LogUtil.CONFIG, "Duplicated entry for {} is being overridden in {}", modId + ".txt", p[0]);
                }
            }
        }
    } finally {
        if (br != null) {
            br.close();
        }
        r.close();
    }
    return bloodValues;
}

7 View Complete Implementation : BloodValueLoader.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
@Override
@SuppressWarnings("unchecked")
protected void apply(@Nonnull Object splashList, @Nonnull IResourceManager resourceManagerIn, @Nonnull IProfiler profilerIn) {
    Map<ResourceLocation, Integer> values = Maps.newConcurrentMap();
    for (ResourceLocation location : (Collection<ResourceLocation>) splashList) {
        String modId = location.getPath().substring(folderLocation.length() + 1, location.getPath().length() - 4);
        Map<ResourceLocation, Integer> values_tmp = loadBloodValuesFromDataPack(location, modId, resourceManagerIn);
        if (values_tmp != null) {
            values.putAll(values_tmp);
            LOGGER.info(LogUtil.CONFIG, "Loaded {} blood values for {} from {}", values_tmp.size(), this.getClreplaced().getName(), modId);
        }
    }
    consumer.accept(values, multiplier != 0 ? multiplier : 1);
}

5 View Complete Implementation : BalanceValues.java
Copyright GNU Lesser General Public License v3.0
Author : TeamLapen
public void loadBalance() {
    ConfigCategory cat = configuration.getCategory(Configuration.CATEGORY_GENERAL);
    boolean alt = shouldUseAlternate();
    for (Field f : this.getClreplaced().getDeclaredFields()) {
        String name = f.getName();
        Clreplaced type = f.getType();
        try {
            if (type == int.clreplaced) {
                DefaultInt a = f.getAnnotation(DefaultInt.clreplaced);
                int value = (alt && a.hasAlternate()) ? a.alternateValue() : a.value();
                f.set(this, MathHelper.clamp(configuration.get(cat.getQualifiedName(), chooseName(name, a.name()), value, a.comment(), a.minValue(), a.maxValue()).getInt(), a.minValue(), a.maxValue()));
            } else if (type == double.clreplaced) {
                // Possible exception should not be caught so you can't forget a default value
                DefaultDouble a = f.getAnnotation(DefaultDouble.clreplaced);
                double value = (alt && a.hasAlternate()) ? a.alternateValue() : a.value();
                f.set(this, MathHelper.clamp(configuration.get(cat.getQualifiedName(), chooseName(name, a.name()), value, a.comment(), a.minValue(), a.maxValue()).getDouble(), a.minValue(), a.maxValue()));
            } else if (type == boolean.clreplaced) {
                DefaultBoolean a = f.getAnnotation(DefaultBoolean.clreplaced);
                boolean value = (alt && a.hasAlternate()) ? a.alternateValue() : a.value();
                f.set(this, configuration.get(cat.getQualifiedName(), chooseName(name, a.name()), value, a.comment()).getBoolean());
            }
        } catch (NullPointerException e1) {
            LOGGER.error(LogUtil.CONFIG, "Author probably forgot to specify a default annotation for " + name + " in " + this.name, e1);
            throw new Error("Please check you default values in " + this.name);
        } catch (Exception e) {
            LOGGER.error(LogUtil.CONFIG, "Cant set " + this.name + " values", e);
            throw new Error("Please check your " + configuration.getConfigFile().getAbsolutePath() + " config file");
        }
    }
    if (configuration.hasChanged()) {
        configuration.save();
    }
}