Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysticsbiomes.config;
- import com.electronwill.nightconfig.core.*;
- import com.electronwill.nightconfig.core.io.WritingMode;
- import com.electronwill.nightconfig.toml.TomlFormat;
- import com.google.common.base.Predicates;
- import com.mysticsbiomes.MysticsBiomes;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.function.Predicate;
- public abstract class ConfigValue implements UnmodifiableConfig, CommentedConfig {
- private final Path path;
- private CommentedConfig config;
- protected ConfigValue(Path path) {
- this.path = path;
- this.config = TomlFormat.instance().createConfig();
- }
- public final void init() {
- this.parse(readToml(this.path));
- this.load();
- this.write();
- }
- public abstract void load();
- public void write() {
- TomlFormat.instance().createWriter().write(this.config, this.path, WritingMode.REPLACE);
- }
- public void read() {
- this.parse(readToml(this.path));
- }
- public void parse(String input) {
- this.config = TomlFormat.instance().createParser().parse(input);
- }
- private static String readToml(Path path) {
- if (path == null) return "";
- try {
- Path parent = path.getParent();
- if (parent != null) {
- Files.createDirectories(parent);
- }
- if (Files.exists(path)) {
- return Files.readString(path);
- }
- } catch (Exception e) {
- MysticsBiomes.logger.error("Failed to read config {}", path, e);
- }
- return "";
- }
- public <T> ConfigEntry<T> build(String key, T defaultValue) {
- return this.build(key, "", defaultValue);
- }
- public <T> ConfigEntry<T> build(String key, String comment, T defaultValue) {
- return this.build(key, comment, defaultValue, Predicates.alwaysTrue());
- }
- public <T> ConfigEntry<T> build(String key, String comment, T defaultValue, Predicate<T> validator) {
- var value = this.config.getOrElse(key, defaultValue);
- if (!validator.test(value)) {
- MysticsBiomes.logger.warn("Invalid value {} for key {}. Reverting to default", value, key);
- value = defaultValue;
- }
- if (!comment.isEmpty()) {
- this.config.setComment(key, comment);
- }
- this.config.set(key, value);
- return new ConfigEntry<>(value);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- @Override
- public Map<String, String> commentMap() {
- return this.config.commentMap();
- }
- @Override
- public boolean containsComment(List<String> path) {
- return this.config.containsComment(path);
- }
- @Override
- public String getComment(List<String> path) {
- return this.config.getComment(path);
- }
- @Override
- public String setComment(List<String> path, String comment) {
- return this.config.setComment(path, comment);
- }
- @Override
- public String removeComment(List<String> path) {
- return this.config.removeComment(path);
- }
- @Override
- public void clearComments() {
- this.config.clearComments();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- @Override
- public <T> T set(List<String> path, Object value) {
- return this.config.set(path, value);
- }
- @Override
- public boolean add(List<String> path, Object value) {
- return this.config.add(path, value);
- }
- @Override
- public <T> T remove(List<String> path) {
- return this.config.remove(path);
- }
- @Override
- public void clear() {
- this.config.clear();
- }
- @Override
- public <T> T getRaw(List<String> path) {
- return this.config.getRaw(path);
- }
- @Override
- public boolean contains(List<String> path) {
- return this.config.contains(path);
- }
- @Override
- public int size() {
- return this.config.size();
- }
- @Override
- public Map<String, Object> valueMap() {
- return this.config.valueMap();
- }
- @Override
- public Set<? extends CommentedConfig.Entry> entrySet() {
- return this.config.entrySet();
- }
- @Override
- public ConfigFormat<?> configFormat() {
- return this.config.configFormat();
- }
- @Override
- public CommentedConfig createSubConfig() {
- return this.config.createSubConfig();
- }
- public static final class ConfigEntry<T> {
- private T value;
- public ConfigEntry(T value) {
- this.value = value;
- }
- public T get() {
- return this.value;
- }
- void set(T value) {
- this.value = value;
- }
- }
- }
Advertisement
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=leyyqsmety
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment