PageRenderTime 1881ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/oldsrc/hmod/HmodConfigurationImpl.java

http://github.com/sk89q/craftbook
Java | 137 lines | 80 code | 37 blank | 20 comment | 18 complexity | 2cc9ff5f6041583ea655af2c77afa050 MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. Craftbook
  3. Copyright (C) 2010 Lymia <lymiahugs@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. import com.sk89q.craftbook.access.Configuration;
  16. import java.io.IOException;
  17. import java.util.logging.Logger;
  18. public class HmodConfigurationImpl implements Configuration {
  19. /**
  20. * Logger.
  21. */
  22. private static final Logger logger = Logger.getLogger("Minecraft.CraftBook");
  23. private PropertiesFile f;
  24. private DataSource s = etc.getDataSource();
  25. public HmodConfigurationImpl(PropertiesFile f) throws IOException {
  26. this.f = f;
  27. f.load();
  28. }
  29. public boolean hasKey(String key) {
  30. return f.containsKey(key);
  31. }
  32. public boolean getBoolean(String key, boolean def) {
  33. Boolean b = getBoolean(key);
  34. if (b == null) {
  35. setString(key, def);
  36. return def;
  37. } else {
  38. return b;
  39. }
  40. }
  41. public int getInt(String key, int def) {
  42. return f.getInt(key, def);
  43. }
  44. public float getFloat(String key, float def) {
  45. return (float) f.getDouble(key, def);
  46. }
  47. public String getString(String key, String def) {
  48. return f.getString(key, def);
  49. }
  50. public Boolean getBoolean(String key) {
  51. String s = getString(key);
  52. if (s == null) return null;
  53. else if (s.equals("true")) return true;
  54. else if (s.equals("false")) return false;
  55. else return null;
  56. }
  57. public Integer getInt(String key) {
  58. String s = getString(key);
  59. if (s == null) return null;
  60. else try {
  61. return Integer.parseInt(key);
  62. } catch (NumberFormatException e) {
  63. return null;
  64. }
  65. }
  66. public Float getFloat(String key) {
  67. String s = getString(key);
  68. if (s == null) return null;
  69. else try {
  70. return Float.parseFloat(key);
  71. } catch (NumberFormatException e) {
  72. return null;
  73. }
  74. }
  75. public String getString(String key) {
  76. if (!f.containsKey(key)) return null;
  77. else return f.getString(key);
  78. }
  79. public void setString(String key, Object target) {
  80. f.setString(key, target.toString());
  81. }
  82. public void load() throws IOException {
  83. f.load();
  84. }
  85. public String getItemName(int id) {
  86. return s.getItem(id);
  87. }
  88. public int getItemId(String name) {
  89. return s.getItem(name);
  90. }
  91. public Logger getLogger() {
  92. return logger;
  93. }
  94. public boolean isValidMob(String mobName) {
  95. return Mob.isValid(mobName);
  96. }
  97. }