PageRenderTime 862ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/moCreatures/server/core/sources/net/minecraft/src/PropertyManager.java

https://code.google.com/p/minecraft-smp-mocreatures/
Java | 102 lines | 87 code | 12 blank | 3 comment | 2 complexity | e520b052e82ca170dcb639c121ee48f7 MD5 | raw file
  1. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  2. // Jad home page: http://www.kpdus.com/jad.html
  3. // Decompiler options: packimports(3) braces deadcode
  4. package net.minecraft.src;
  5. import java.io.*;
  6. import java.util.Properties;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. public class PropertyManager
  10. {
  11. public PropertyManager(File file)
  12. {
  13. serverProperties = new Properties();
  14. serverPropertiesFile = file;
  15. if(file.exists())
  16. {
  17. try
  18. {
  19. serverProperties.load(new FileInputStream(file));
  20. }
  21. catch(Exception exception)
  22. {
  23. logger.log(Level.WARNING, (new StringBuilder()).append("Failed to load ").append(file).toString(), exception);
  24. generateNewProperties();
  25. }
  26. } else
  27. {
  28. logger.log(Level.WARNING, (new StringBuilder()).append(file).append(" does not exist").toString());
  29. generateNewProperties();
  30. }
  31. }
  32. public void generateNewProperties()
  33. {
  34. logger.log(Level.INFO, "Generating new properties file");
  35. saveProperties();
  36. }
  37. public void saveProperties()
  38. {
  39. try
  40. {
  41. serverProperties.store(new FileOutputStream(serverPropertiesFile), "Minecraft server properties");
  42. }
  43. catch(Exception exception)
  44. {
  45. logger.log(Level.WARNING, (new StringBuilder()).append("Failed to save ").append(serverPropertiesFile).toString(), exception);
  46. generateNewProperties();
  47. }
  48. }
  49. public String getStringProperty(String s, String s1)
  50. {
  51. if(!serverProperties.containsKey(s))
  52. {
  53. serverProperties.setProperty(s, s1);
  54. saveProperties();
  55. }
  56. return serverProperties.getProperty(s, s1);
  57. }
  58. public int getIntProperty(String s, int i)
  59. {
  60. try
  61. {
  62. return Integer.parseInt(getStringProperty(s, (new StringBuilder()).append("").append(i).toString()));
  63. }
  64. catch(Exception exception)
  65. {
  66. serverProperties.setProperty(s, (new StringBuilder()).append("").append(i).toString());
  67. }
  68. return i;
  69. }
  70. public boolean getBooleanProperty(String s, boolean flag)
  71. {
  72. try
  73. {
  74. return Boolean.parseBoolean(getStringProperty(s, (new StringBuilder()).append("").append(flag).toString()));
  75. }
  76. catch(Exception exception)
  77. {
  78. serverProperties.setProperty(s, (new StringBuilder()).append("").append(flag).toString());
  79. }
  80. return flag;
  81. }
  82. public void setProperty(String s, boolean flag)
  83. {
  84. serverProperties.setProperty(s, (new StringBuilder()).append("").append(flag).toString());
  85. saveProperties();
  86. }
  87. public static Logger logger = Logger.getLogger("Minecraft");
  88. private Properties serverProperties;
  89. private File serverPropertiesFile;
  90. }