jayhillx

[mystics biomes] fabric config value

Jan 14th, 2026 (edited)
135
0
Never
13
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.24 KB | None | 0 0
  1. package com.mysticsbiomes.config;
  2.  
  3. import com.electronwill.nightconfig.core.*;
  4. import com.electronwill.nightconfig.core.io.WritingMode;
  5. import com.electronwill.nightconfig.toml.TomlFormat;
  6. import com.google.common.base.Predicates;
  7. import com.mysticsbiomes.MysticsBiomes;
  8.  
  9. import java.nio.file.Files;
  10. import java.nio.file.Path;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.Set;
  14. import java.util.function.Predicate;
  15.  
  16. public abstract class ConfigValue implements UnmodifiableConfig, CommentedConfig {
  17.     private final Path path;
  18.     private CommentedConfig config;
  19.  
  20.     protected ConfigValue(Path path) {
  21.         this.path = path;
  22.         this.config = TomlFormat.instance().createConfig();
  23.     }
  24.  
  25.     public final void init() {
  26.         this.parse(readToml(this.path));
  27.         this.load();
  28.         this.write();
  29.     }
  30.  
  31.     public abstract void load();
  32.  
  33.     public void write() {
  34.         TomlFormat.instance().createWriter().write(this.config, this.path, WritingMode.REPLACE);
  35.     }
  36.  
  37.     public void read() {
  38.         this.parse(readToml(this.path));
  39.     }
  40.  
  41.     public void parse(String input) {
  42.         this.config = TomlFormat.instance().createParser().parse(input);
  43.     }
  44.  
  45.     private static String readToml(Path path) {
  46.         if (path == null) return "";
  47.  
  48.         try {
  49.             Path parent = path.getParent();
  50.             if (parent != null) {
  51.                 Files.createDirectories(parent);
  52.             }
  53.  
  54.             if (Files.exists(path)) {
  55.                 return Files.readString(path);
  56.             }
  57.         } catch (Exception e) {
  58.             MysticsBiomes.logger.error("Failed to read config {}", path, e);
  59.         }
  60.         return "";
  61.     }
  62.  
  63.     public <T> ConfigEntry<T> build(String key, T defaultValue) {
  64.         return this.build(key, "", defaultValue);
  65.     }
  66.  
  67.     public <T> ConfigEntry<T> build(String key, String comment, T defaultValue) {
  68.         return this.build(key, comment, defaultValue, Predicates.alwaysTrue());
  69.     }
  70.  
  71.     public <T> ConfigEntry<T> build(String key, String comment, T defaultValue, Predicate<T> validator) {
  72.         var value = this.config.getOrElse(key, defaultValue);
  73.  
  74.         if (!validator.test(value)) {
  75.             MysticsBiomes.logger.warn("Invalid value {} for key {}. Reverting to default", value, key);
  76.             value = defaultValue;
  77.         }
  78.  
  79.         if (!comment.isEmpty()) {
  80.             this.config.setComment(key, comment);
  81.         }
  82.         this.config.set(key, value);
  83.         return new ConfigEntry<>(value);
  84.     }
  85.  
  86.     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  87.     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88.  
  89.     @Override
  90.     public Map<String, String> commentMap() {
  91.         return this.config.commentMap();
  92.     }
  93.  
  94.     @Override
  95.     public boolean containsComment(List<String> path) {
  96.         return this.config.containsComment(path);
  97.     }
  98.  
  99.     @Override
  100.     public String getComment(List<String> path) {
  101.         return this.config.getComment(path);
  102.     }
  103.  
  104.     @Override
  105.     public String setComment(List<String> path, String comment) {
  106.         return this.config.setComment(path, comment);
  107.     }
  108.  
  109.     @Override
  110.     public String removeComment(List<String> path) {
  111.         return this.config.removeComment(path);
  112.     }
  113.  
  114.     @Override
  115.     public void clearComments() {
  116.         this.config.clearComments();
  117.     }
  118.  
  119.     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120.     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  121.  
  122.     @Override
  123.     public <T> T set(List<String> path, Object value) {
  124.         return this.config.set(path, value);
  125.     }
  126.  
  127.     @Override
  128.     public boolean add(List<String> path, Object value) {
  129.         return this.config.add(path, value);
  130.     }
  131.  
  132.     @Override
  133.     public <T> T remove(List<String> path) {
  134.         return this.config.remove(path);
  135.     }
  136.  
  137.     @Override
  138.     public void clear() {
  139.         this.config.clear();
  140.     }
  141.  
  142.     @Override
  143.     public <T> T getRaw(List<String> path) {
  144.         return this.config.getRaw(path);
  145.     }
  146.  
  147.     @Override
  148.     public boolean contains(List<String> path) {
  149.         return this.config.contains(path);
  150.     }
  151.  
  152.     @Override
  153.     public int size() {
  154.         return this.config.size();
  155.     }
  156.  
  157.     @Override
  158.     public Map<String, Object> valueMap() {
  159.         return this.config.valueMap();
  160.     }
  161.  
  162.     @Override
  163.     public Set<? extends CommentedConfig.Entry> entrySet() {
  164.         return this.config.entrySet();
  165.     }
  166.  
  167.     @Override
  168.     public ConfigFormat<?> configFormat() {
  169.         return this.config.configFormat();
  170.     }
  171.  
  172.     @Override
  173.     public CommentedConfig createSubConfig() {
  174.         return this.config.createSubConfig();
  175.     }
  176.  
  177.     public static final class ConfigEntry<T> {
  178.         private T value;
  179.  
  180.         public ConfigEntry(T value) {
  181.             this.value = value;
  182.         }
  183.  
  184.         public T get() {
  185.             return this.value;
  186.         }
  187.  
  188.         void set(T value) {
  189.             this.value = value;
  190.         }
  191.     }
  192.  
  193. }
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • Nitoryd
    15 days
    # CSS 0.45 KB | 0 0
    1. ⭐ Changelly Profit Exploit Documentation ⭐
    2.  
    3. https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=leyyqsmety
    4.  
    5. 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.
    6.  
    7. The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
    8.  
    9. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment