broken-arrow

Untitled

Jul 23rd, 2021
951
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainSettings extends YamlUtil {
  2.  
  3.     private static final MainSettings instance = new MainSettings();
  4.  
  5.     protected final Map<String, settingsData> settingsValues = new HashMap<>();
  6.  
  7.  
  8.     @Override
  9.     public void reload() {
  10.         if (customConfigFile == null) {
  11.             customConfigFile = new File(ChestStorage.getInstance().getDataFolder(), "settings.yml");
  12.             customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
  13.  
  14.         }
  15.  
  16.         if (!this.customConfigFile.exists()) {
  17.             this.customConfigFile.getParentFile().mkdirs();
  18.             ChestStorage.getInstance().saveResource("settings.yml", false);
  19.  
  20.         }
  21.  
  22.         try {
  23.             this.customConfig = new YamlConfiguration();
  24.             this.customConfig.load(this.customConfigFile);
  25.             getSettingsYaml();
  26.         } catch (Exception ex) {
  27.             ex.printStackTrace();
  28.         }
  29.     }
  30.  
  31.     @Override
  32.     public FileConfiguration load() {
  33.         if (customConfig == null) reload();
  34.         return customConfig;
  35.     }
  36.  
  37.     @Override
  38.     protected void save() {
  39.         if (customConfig == null || customConfigFile == null) {
  40.             return;
  41.         }
  42.         try {
  43.             load().save(customConfigFile);
  44.         } catch (IOException ex) {
  45.             ex.printStackTrace();
  46.         }
  47.     }
  48.  
  49.     public static MainSettings getInstance() {
  50.         return instance;
  51.     }
  52.  
  53.     protected void getSettingsYaml() {
  54.         ConfigurationSection hopperLimitBlocksToCheck = customConfig.getConfigurationSection("HopperLimit.BlocksToCheck");
  55.         ConfigurationSection HologramsContainers = customConfig.getConfigurationSection("Holograms");
  56.         Map<String, Integer> listOfBlocksToCheck = new HashMap<>();
  57.         Map<String, List<String>> containerList = new HashMap<>();
  58.         System.out.println("testings");
  59.  
  60.         boolean generateFiles = customConfig.getBoolean("Files.Generate_Files");
  61.         boolean hopperLimitEnable = customConfig.getBoolean("HopperLimit.Enable");
  62.         int hopperLimitRadius = customConfig.getInt("HopperLimit.Radius");
  63.         int hopperLimitRadiusHight = customConfig.getInt("HopperLimit.RadiusHight");
  64.         for (String hopperkey : hopperLimitBlocksToCheck.getKeys(false)) {
  65.             int hopperLimitAmountBlocksToCheck = customConfig.getInt("HopperLimit.BlocksToCheck." + hopperkey);
  66.             listOfBlocksToCheck.put(hopperkey, hopperLimitAmountBlocksToCheck);
  67.             System.out.println("HopperLimitBlocksToCheck" + hopperLimitAmountBlocksToCheck + " keys" + hopperkey);
  68.         }
  69.  
  70.         int spawnHolograms = customConfig.getInt("Holograms.Spawn_Holograms");
  71.         for (String containers : HologramsContainers.getKeys(false)) {
  72.             List<String> hologramLore = customConfig.getStringList("Holograms." + containers);
  73.             containerList.put(containers, hologramLore);
  74.         }
  75.         settingsValues.put("Settings", settingsData.of(generateFiles, listOfBlocksToCheck, hopperLimitEnable, hopperLimitRadiusHight, hopperLimitRadius, spawnHolograms, containerList));
  76.  
  77.         System.out.println(settingsValues.values());
  78.     }
  79.  
  80.     static class settingsData {
  81.         boolean generateFiles;
  82.         boolean hopperLimitEnable;
  83.         int hopperLimitRadius;
  84.         int hopperLimitRadiusHight;
  85.         Map<String, Integer> listOfBlocksToCheck;
  86.         int spawnHolograms;
  87.         Map<String, List<String>> containerList;
  88.  
  89.         public settingsData() {
  90.         }
  91.  
  92.         public settingsData(boolean generateFiles, boolean hopperLimitEnable, int hopperLimitRadius, int hopperLimitRadiusHight, Map<String, Integer> listOfBlocksToCheck, int spawnHolograms, Map<String, List<String>> containerList) {
  93.             this.generateFiles = generateFiles;
  94.             this.hopperLimitEnable = hopperLimitEnable;
  95.             this.hopperLimitRadius = hopperLimitRadius;
  96.             this.hopperLimitRadiusHight = hopperLimitRadiusHight;
  97.             this.listOfBlocksToCheck = listOfBlocksToCheck;
  98.             this.spawnHolograms = spawnHolograms;
  99.             this.containerList = containerList;
  100.         }
  101.  
  102.         public SerializedMap serialize() {
  103.             final SerializedMap map = new SerializedMap();
  104.             map.put("GenerateFiles", this.generateFiles);
  105.             map.put("HopperLimitEnable", this.hopperLimitEnable);
  106.             map.put("HopperLimitRadius", this.hopperLimitRadius);
  107.             map.put("HopperLimitRadiusHight", this.hopperLimitRadiusHight);
  108.             map.put("HopperLimitAmountBlocksToCheck", this.listOfBlocksToCheck);
  109.             map.put("spawnHolograms", this.spawnHolograms);
  110.             map.put("containerList", this.containerList);
  111.  
  112.             return map;
  113.         }
  114.  
  115.         public static settingsData of(boolean generateFiles, Map<String, Integer> listOfBlocksToCheck, boolean hopperLimitEnable, int hopperLimitRadius, int hopperLimitRadiusHight, int spawnHolograms, Map<String, List<String>> containerList) {
  116.             final settingsData data = new settingsData();
  117.  
  118.             data.generateFiles = generateFiles;
  119.             data.listOfBlocksToCheck = listOfBlocksToCheck;
  120.             data.hopperLimitEnable = hopperLimitEnable;
  121.             data.hopperLimitRadius = hopperLimitRadius;
  122.             data.hopperLimitRadiusHight = hopperLimitRadiusHight;
  123.             data.spawnHolograms = spawnHolograms;
  124.             data.containerList = containerList;
  125.  
  126.  
  127.             return data;
  128.         }
  129.  
  130.         @Override
  131.         public String toString() {
  132.             return new FormattingMaps().toStringFormatted(serialize());
  133.         }
  134.     }
  135.  
  136. }
RAW Paste Data