示例#1
0
 public static void load(final File file) {
   try {
     if (!file.exists()) {
       file.getParentFile().mkdirs();
       file.createNewFile();
     }
     final YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
     final Set<String> keys = yml.getKeys(true);
     final EnumSet<C> all = EnumSet.allOf(C.class);
     final HashSet<String> allNames = new HashSet<>();
     final HashSet<String> allCats = new HashSet<>();
     final HashSet<String> toRemove = new HashSet<>();
     for (final C c : all) {
       allNames.add(c.name());
       allCats.add(c.cat.toLowerCase());
     }
     final HashSet<C> captions = new HashSet<>();
     boolean changed = false;
     for (final String key : keys) {
       if (!yml.isString(key)) {
         if (!allCats.contains(key)) {
           toRemove.add(key);
         }
         continue;
       }
       final String[] split = key.split("\\.");
       final String node = split[split.length - 1].toUpperCase();
       final C caption = allNames.contains(node) ? valueOf(node) : null;
       if (caption != null) {
         if (caption.cat.startsWith("static")) {
           continue;
         }
         final String value = yml.getString(key);
         if (!split[0].equalsIgnoreCase(caption.cat)) {
           changed = true;
           yml.set(key, null);
           yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
         }
         captions.add(caption);
         caption.s = value;
       } else {
         toRemove.add(key);
       }
     }
     for (final String remove : toRemove) {
       changed = true;
       yml.set(remove, null);
     }
     final ConfigurationSection config = PS.get().style.getConfigurationSection("color");
     final Set<String> styles = config.getKeys(false);
     // HashMap<String, String> replacements = new HashMap<>();
     replacements.clear();
     for (final String style : styles) {
       replacements.put("$" + style, "\u00a7" + config.getString(style));
     }
     for (final char letter : "1234567890abcdefklmnor".toCharArray()) {
       replacements.put("&" + letter, "\u00a7" + letter);
     }
     replacements.put("\\\\n", "\n");
     replacements.put("\\n", "\n");
     replacements.put("&-", "\n");
     for (final C caption : all) {
       if (!captions.contains(caption)) {
         if (caption.cat.startsWith("static")) {
           continue;
         }
         changed = true;
         yml.set(caption.cat + "." + caption.name().toLowerCase(), caption.d);
       }
       caption.s = StringMan.replaceFromMap(caption.s, replacements);
     }
     if (changed) {
       yml.save(file);
     }
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }