vminecraftSettings.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import java.io.*;
  2. import java.util.ArrayList;
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. //=====================================================================
  6. //Class: vminecraftSettings
  7. //Use: Controls the settings for vminecraft
  8. //Author: nossr50, TrapAlice, cerevisiae
  9. //=====================================================================
  10. public class vminecraftSettings {
  11. //private final static Object syncLock = new Object();
  12. protected static final Logger log = Logger.getLogger("Minecraft");
  13. private static volatile vminecraftSettings instance;
  14. //Invulnerability List
  15. //The feature settings
  16. static boolean toggle = true,
  17. adminChat = false,
  18. greentext = false,
  19. FFF = false,
  20. quakeColors = false,
  21. cmdFabulous = false,
  22. cmdPromote = false,
  23. cmdDemote = false,
  24. cmdWhoIs = false,
  25. cmdRules = false,
  26. cmdMasstp = false,
  27. cmdTp = false,
  28. cmdTphere = false,
  29. globalmessages = false,
  30. cmdSay = false,
  31. cmdWho = false,
  32. stopFire = false,
  33. stopTnt = false,
  34. cmdEzModo = false;
  35. //An array of players currently in ezmodo
  36. static ArrayList<String> ezModo = new ArrayList<String>();
  37. //The max health for ezModo
  38. static int ezHealth = 30;
  39. private PropertiesFile properties;
  40. String file = "vminecraft.properties";
  41. public String rules[] = null;
  42. //=====================================================================
  43. //Function: loadSettings
  44. //Input: None
  45. //Output: None
  46. //Use: Loads the settings from the properties
  47. //=====================================================================
  48. public void loadSettings()
  49. {
  50. File theDir = new File("vminecraft.properties");
  51. if(!theDir.exists()){
  52. String location = "vminecraft.properties";
  53. properties = new PropertiesFile("vminecraft.properties");
  54. FileWriter writer = null;
  55. try {
  56. writer = new FileWriter(location);
  57. writer.write("#This plugin is modular\r\n");
  58. writer.write("#Turn any features you don't want to false and they won't be running\r\n");
  59. writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n");
  60. writer.write("greentext=true\r\n");
  61. writer.write("quakeColors=true\r\n");
  62. writer.write("cmdTphere=true\r\n");
  63. writer.write("cmdFabulous=true\r\n");
  64. writer.write("cmdWhoIs=true\r\n");
  65. writer.write("cmdWho=true\r\n");
  66. writer.write("cmdPromote=true\r\n");
  67. writer.write("cmdDemote=true\r\n");
  68. writer.write("cmdMasstp=true\r\n");
  69. writer.write("cmdSay=true\r\n");
  70. writer.write("cmdTp=true\r\n");
  71. writer.write("cmdRules=true\r\n");
  72. writer.write("globalmessages=true\r\n");
  73. writer.write("FFF=true\r\n");
  74. writer.write("adminchat=true\r\n");
  75. writer.write("cmdEzModo=true\r\n");
  76. writer.write("ezModo=\r\n");
  77. writer.write("ezHealth=30\r\n");
  78. writer.write("stopFire=false");
  79. writer.write("stopTnt=false");
  80. writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
  81. } catch (Exception e) {
  82. log.log(Level.SEVERE, "Exception while creating " + location, e);
  83. } finally {
  84. try {
  85. if (writer != null) {
  86. writer.close();
  87. }
  88. } catch (IOException e) {
  89. log.log(Level.SEVERE, "Exception while closing writer for " + location, e);
  90. }
  91. }
  92. } else {
  93. properties = new PropertiesFile("vminecraft.properties");
  94. try {
  95. properties.load();
  96. } catch (IOException e) {
  97. e.printStackTrace();
  98. }
  99. }
  100. try {
  101. adminChat = properties.getBoolean("adminchat",true);
  102. greentext = properties.getBoolean("greentext",true);
  103. FFF = properties.getBoolean("FFF",true);
  104. quakeColors = properties.getBoolean("quakeColors",true);
  105. cmdFabulous = properties.getBoolean("cmdFabulous",true);
  106. cmdPromote = properties.getBoolean("cmdPromote",true);
  107. cmdDemote = properties.getBoolean("cmdDemote",true);
  108. cmdWhoIs = properties.getBoolean("cmdWhoIs",true);
  109. cmdWho = properties.getBoolean("cmdWho",true);
  110. cmdRules = properties.getBoolean("cmdRules",true);
  111. cmdTp = properties.getBoolean("cmdTp",true);
  112. cmdMasstp = properties.getBoolean("cmdMasstp",true);
  113. cmdTphere = properties.getBoolean("cmdTphere",true);
  114. globalmessages = properties.getBoolean("globalmessages",true);
  115. cmdSay = properties.getBoolean("cmdSay",true);
  116. cmdEzModo = properties.getBoolean("cmdEzModo",true);
  117. stopFire = properties.getBoolean("stopFire",true);
  118. stopTnt = properties.getBoolean("stopTNT",true);
  119. rules = properties.getString("rules", "").split("@");
  120. String[] tempEz = properties.getString("ezModo").split(",");
  121. ezModo = new ArrayList<String>();
  122. for(int i = 0; i < tempEz.length; i++)
  123. ezModo.add(tempEz[i]);
  124. ezHealth = properties.getInt("ezHealth");
  125. log.log(Level.INFO, "vminecraft plugin successfully loaded");
  126. }
  127. catch (Exception e)
  128. {
  129. log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE");
  130. }
  131. }
  132. //=====================================================================
  133. //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous,
  134. // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay
  135. // cmdRules, globalmessages, cmdMasstp, cmdEzModo
  136. //Input: None
  137. //Output: Boolan: If the feature is enabled
  138. //Use: Returns if the feature is enabled
  139. //=====================================================================
  140. public boolean adminchat() {return adminChat;}
  141. public boolean greentext() {return greentext;}
  142. public boolean FFF() {return FFF;}
  143. public boolean quakeColors() {return quakeColors;}
  144. public boolean cmdFabulous() {return cmdFabulous;}
  145. public boolean cmdPromote() {return cmdPromote;}
  146. public boolean cmdDemote() {return cmdDemote;}
  147. public boolean cmdWhoIs() {return cmdWhoIs;}
  148. public boolean cmdTp() {return cmdTp;}
  149. public boolean cmdTphere() {return cmdTphere;}
  150. public boolean cmdSay() {return cmdSay;}
  151. public boolean cmdRules() {return cmdRules;}
  152. public boolean globalmessages() {return globalmessages;}
  153. public boolean cmdMasstp() {return cmdMasstp;}
  154. public boolean cmdEzModo() {return cmdEzModo;}
  155. public boolean cmdWho() {return cmdWho;}
  156. public boolean stopFire() {return stopFire;}
  157. public boolean stopTnt() {return stopTnt;}
  158. //EzModo functions
  159. public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}
  160. public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));}
  161. public void addEzModo(String playerName) {ezModo.add(playerName);}
  162. public int ezModoHealth() {return ezHealth;}
  163. public String ezModoList() {return ezModo.toString();}
  164. //=====================================================================
  165. //Function: getInstance
  166. //Input: None
  167. //Output: vminecraftSettings: The instance of the settings
  168. //Use: Returns the instance of the settings
  169. //=====================================================================
  170. public static vminecraftSettings getInstance() {
  171. if (instance == null) {
  172. instance = new vminecraftSettings();
  173. }
  174. return instance;
  175. }
  176. //=====================================================================
  177. //Function: getRules
  178. //Input: None
  179. //Output: String[]: The list of rules
  180. //Use: Gets the array containing the rules
  181. //=====================================================================
  182. public String[] getRules() {
  183. return rules;
  184. }
  185. }