settings.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. import net.minecraft.server.MinecraftServer;
  6. public class settings {
  7. private final static Object syncLock = new Object();
  8. protected static final Logger log = Logger.getLogger("Minecraft");
  9. private static volatile settings instance;
  10. static boolean toggle = true;
  11. private boolean adminChat = false;
  12. private boolean greentext = false;
  13. private boolean FFF = false;
  14. private boolean quakeColors = false;
  15. private boolean cmdFabulous = false;
  16. private boolean cmdPromote = false;
  17. private boolean cmdDemote = false;
  18. private boolean cmdWhoIs = false;
  19. private PropertiesFile properties;
  20. String file = "vminecraft.properties";
  21. public String rules[] = null;
  22. public void rules() {
  23. try{
  24. rules = properties.getString("rules", "Rules@#1: No griefing").split("@");
  25. }
  26. catch (Exception e) {
  27. log.log(Level.SEVERE, "Vminecraft: "+ e.getMessage() );
  28. rules = new String[]{"Rules@#1: No griefing"};
  29. }
  30. }
  31. public void loadSettings()
  32. //Will create a file if it doesn't exist
  33. {
  34. if (properties == null) {
  35. properties = new PropertiesFile("vminecraft.properties");
  36. } else {
  37. properties.load();
  38. }
  39. try{
  40. Scanner scanner = new Scanner(new File(file));
  41. while (scanner.hasNextLine()) {
  42. String line = scanner.nextLine();
  43. if( line.startsWith("#") || line.equals(""))
  44. {
  45. continue;
  46. }
  47. String[] split = line.split("=");
  48. if(split[0].equalsIgnoreCase("adminchat"))
  49. {
  50. if(split[1].equalsIgnoreCase("true"))
  51. {
  52. adminChat = true;
  53. }
  54. else adminChat = false;
  55. }
  56. if(split[0].equalsIgnoreCase("Greentext"))
  57. {
  58. if(split[1].equalsIgnoreCase("true"))
  59. {
  60. greentext = true;
  61. }
  62. else greentext = false;
  63. }
  64. if(split[0].equalsIgnoreCase("FFF"))
  65. {
  66. if(split[1].equalsIgnoreCase("true"))
  67. {
  68. FFF = true;
  69. }
  70. else FFF = false;
  71. }
  72. if(split[0].equalsIgnoreCase("QuakeColors"))
  73. {
  74. if(split[1].equalsIgnoreCase("true"))
  75. {
  76. quakeColors = true;
  77. }
  78. else quakeColors = false;
  79. }
  80. if(split[0].equalsIgnoreCase("cmdFabulous"))
  81. {
  82. if(split[1].equalsIgnoreCase("true"))
  83. {
  84. cmdFabulous = true;
  85. }
  86. else cmdFabulous = false;
  87. }
  88. if(split[0].equalsIgnoreCase("cmdPromote"))
  89. {
  90. if(split[1].equalsIgnoreCase("true"))
  91. {
  92. cmdPromote = true;
  93. }
  94. else cmdPromote = false;
  95. }
  96. if(split[0].equalsIgnoreCase("cmdDemote"))
  97. {
  98. if(split[1].equalsIgnoreCase("true"))
  99. {
  100. cmdDemote = true;
  101. }
  102. else cmdDemote = false;
  103. }
  104. if(split[0].equalsIgnoreCase("cmdWhoIs"))
  105. {
  106. if(split[1].equalsIgnoreCase("true"))
  107. {
  108. cmdWhoIs = true;
  109. }
  110. else cmdWhoIs = false;
  111. }
  112. }
  113. scanner.close();
  114. }
  115. catch (Exception e) {
  116. log.log(Level.SEVERE, "Vminecraft: "+ e.getMessage() );
  117. }
  118. }
  119. public boolean adminchat() {return adminChat;}
  120. public boolean greentext() {return greentext;}
  121. public boolean FFF() {return FFF;}
  122. public boolean quakeColors() {return quakeColors;}
  123. public boolean cmdFabulous() {return cmdFabulous;}
  124. public boolean cmdPromote() {return cmdPromote;}
  125. public boolean cmdDemote() {return cmdDemote;}
  126. public boolean cmdWhoIs() {return cmdWhoIs;}
  127. public static settings getInstance() {
  128. if (instance == null) {
  129. instance = new settings();
  130. }
  131. return instance;
  132. }
  133. //Will return the rules
  134. public String[] getRules() {
  135. return rules;
  136. }
  137. }