Guest User

Untitled

a guest
Nov 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. static{
  2.     CLAN_DEFAULTS.put(".type", "hostile");
  3.     CLAN_DEFAULTS.put(".Description", defDescription);
  4.     CLAN_DEFAULTS.put(".users", null);
  5. }
  6.  
  7. // later in the code
  8.  
  9. private void loadClanFiles(){
  10.     if(ClansFile.exists()){
  11.         plugin.log.info("[PhantomClans] loading clan files");
  12.         clans = new Configuration(ClansFile);
  13.         clans.load();
  14.         // for each clan in the original list
  15.         for(String m_clans : plugin.getClans() ){
  16.             // for each property in the static list above
  17.             plugin.log.info("Writing for " + m_clans);
  18.             for(String prop : CLAN_DEFAULTS.keySet()){
  19.                 plugin.log.info("Writing for " + prop);
  20.                 if (clans.getProperty("clans." + m_clans + prop) == null) {
  21.                     clans.setProperty("clans." + m_clans + prop, CLAN_DEFAULTS.get("clans." + m_clans + prop));
  22.                 }
  23.             }
  24.         }
  25.     } else {
  26.         plugin.log.info("[PhantomClans] creating default clan structures");
  27.         try {
  28.             plugin.getDataFolder().mkdir();
  29.             ClansFile.createNewFile();
  30.             clans = new Configuration(ClansFile);
  31.             // default values TODO: make it so the default list isn't the only one used in the "for each"
  32.             for(String m_clans : plugin.getClans()){
  33.                 // for each property in the static list above
  34.                 for(String prop : CLAN_DEFAULTS.keySet()){
  35.                     // this might be very ugly, but if it works, I like it
  36.                     clans.setProperty("clans." + m_clans + prop, CLAN_DEFAULTS.get("clans." + m_clans + prop));
  37.                 }
  38.             }
  39.             clans.save();
  40.         } catch (IOException e) {
  41.             plugin.log.warning(e.toString());
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment