mcProperties.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.gmail.nossr50;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.util.Properties;
  7. public class mcProperties extends Properties{
  8. //private static volatile mcProperties instance;
  9. private String fileName;
  10. public mcProperties(String file) {
  11. this.fileName = file;
  12. }
  13. public void load() {
  14. File file = new File(this.fileName);
  15. if(file.exists()) {
  16. try {
  17. load(new FileInputStream(this.fileName));
  18. } catch (IOException ex) {
  19. }
  20. }
  21. }
  22. public void save(String start){
  23. try{
  24. store(new FileOutputStream(this.fileName), start);
  25. } catch (IOException ex) {
  26. }
  27. }
  28. public int getInteger(String key, int value){
  29. if(containsKey(key)){
  30. return Integer.parseInt(getProperty(key));
  31. }
  32. put(key, String.valueOf(value));
  33. return value;
  34. }
  35. public String getString(String key, String value){
  36. if(containsKey(key)){
  37. return getProperty(key);
  38. }
  39. put(key, value);
  40. return value;
  41. }
  42. public Boolean getBoolean(String key, boolean value) {
  43. if (containsKey(key)) {
  44. String boolString = getProperty(key);
  45. return (boolString.length() > 0)
  46. && (boolString.toLowerCase().charAt(0) == 't');
  47. }
  48. put(key, value ? "true" : "false");
  49. return value;
  50. }
  51. public double getDouble(String key, double value) {
  52. if (containsKey(key)) {
  53. return Double.parseDouble(getProperty(key));
  54. }
  55. put(key, String.valueOf(value));
  56. return value;
  57. }
  58. }