bspkrs

new Configuration methods

Mar 11th, 2013
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1.  
  2.    
  3.     /**
  4.      * Deletes a given category.
  5.      * @param category the category to delete
  6.      */
  7.     public void deleteCategory(String category)
  8.     {
  9.         if(hasCategory(category))
  10.         {
  11.             categories.remove(category);
  12.         }
  13.     }
  14.    
  15.     /**
  16.      * Renames a property in a given category.
  17.      * @param category    the category in which the property resides
  18.      * @param oldPropName the existing property name
  19.      * @param newPropName the
  20.      * @return            true if the category and property exist, false otherwise
  21.      */
  22.     public boolean renameProperty(String category, String oldPropName, String newPropName)
  23.     {
  24.         if (hasCategory(category))
  25.         {
  26.             if (!oldPropName.equalsIgnoreCase(newPropName))
  27.             {
  28.                 if (getCategory(category).containsKey(oldPropName))
  29.                 {
  30.                     get(category, newPropName, getCategory(category).get(oldPropName).getString());
  31.                     getCategory(category).remove(oldPropName);
  32.                     return true;
  33.                 }
  34.                 else
  35.                 {
  36.                     FMLLog.warning("Mod attempted to rename a non-existant property!");
  37.                     FMLLog.warning("Config \"%s\" Category: \"%s\" Source Key: \"%s\" Target Key: \"%s\"", fileName, category, oldPropName, newPropName);
  38.                 }
  39.             }
  40.         }
  41.         else
  42.         {
  43.             FMLLog.warning("Mod attempted to rename a property from a non-existant config category!");
  44.             FMLLog.warning("Config \"%s\" Category: \"%s\" Source Key: \"%s\" Target Key: \"%s\"", fileName, category, oldPropName, newPropName);
  45.         }
  46.         return false;
  47.     }
  48.     /**
  49.      * Moves a property from one category to another. The new category is created if it doesn't exist.
  50.      * @param oldCategory the category the property currently resides in
  51.      * @param propName    the name of the property to move
  52.      * @param newCategory the category the property should be moved to
  53.      * @return            true if the old category and property exist, false otherwise
  54.      */
  55.     public boolean moveProperty(String oldCategory, String propName, String newCategory)
  56.     {
  57.         if (!caseSensitiveCustomCategories)
  58.         {
  59.             oldCategory = oldCategory.toLowerCase(Locale.ENGLISH);
  60.             newCategory = newCategory.toLowerCase(Locale.ENGLISH);
  61.         }
  62.        
  63.         if (!oldCategory.equals(newCategory))
  64.         {
  65.             if(hasCategory(oldCategory))
  66.             {
  67.                 if (getCategory(oldCategory).containsKey(propName))
  68.                 {
  69.                     getCategory(newCategory).put(propName, getCategory(oldCategory).get(propName));
  70.                     return true;
  71.                 }
  72.                 else
  73.                 {
  74.                     FMLLog.warning("Mod attempted to move a non-existant property to another config category!");
  75.                     FMLLog.warning("Config \"%s\" Source Category: \"%s\" Key: \"%s\" Target Category: \"%s\"", fileName, oldCategory, propName, newCategory);
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 FMLLog.warning("Mod attempted to move a property from a non-existant config category!");
  81.                 FMLLog.warning("Config \"%s\" Source Category: \"%s\" Key: \"%s\" Target Category: \"%s\"", fileName, oldCategory, propName, newCategory);
  82.             }
  83.         }
  84.         return false;
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment